小编Tim*_*Tim的帖子

通过注释而不是XML配置Spring LdapTemplate的最佳实践?

对于Spring Boot应用程序,我LdapTemplate使用注释成功配置了Spring ,包括LdapContextSource@Valueapplication.properties中的s 的依赖关系.(哇!我找不到一个例子,所以也许这会帮助别人.)

片段(下面)设置上下文源,将其注入LdapTemplate到我的DirectoryService中,然后自动装入到我的DirectoryService中.

是否有更好/更清晰的方法来设置ContextSourceSpring Boot应用程序?

application.properties(在类路径上):

ldap.url=ldap://server.domain.com:389
ldap.base:OU=Employees,OU=Users,DC=domain,DC=com
ldap.username:CN=myuserid,OU=employees,OU=Users,DC=domain,DC=com
ldap.password:secretthingy
Run Code Online (Sandbox Code Playgroud)

MyLdapContextSource.java:

@Component
public class MyLdapContextSource extends LdapContextSource implements ContextSource {

    @Value("${ldap.url}")
    @Override
    public void setUrl(String url) { super.setUrl(url);  }

    @Value("${ldap.base}")
    @Override
    public void setBase(String base) {super.setBase(base); }

    @Value("${ldap.username}")
    @Override
    public void setUserDn(String userDn) {super.setUserDn(userDn); }

    @Value("${ldap.password}")
    @Override
    public void setPassword(String password) { super.setPassword(password); }
}
Run Code Online (Sandbox Code Playgroud)

MyLdapTemplate.java:

@Component
public class MyLdapTemplate extends LdapTemplate {

    @Autowired
    public MyLdapTemplate(ContextSource …
Run Code Online (Sandbox Code Playgroud)

java annotations spring-ldap spring-boot

29
推荐指数
2
解决办法
3万
查看次数

如何在Spring Boot中设置预认证基于头的身份验证?

我的应用程序从Oracle Access Manager SSO获取带有用户名的AUTH_USER请求标头.Spring Security"附加主题"2.2.1有一个"PreAuth"的例子,它似乎是我需要的,但不是一个完整的工作示例.

下面的代码段来自docs/examples,而不是基于注释的配置.

Siteminder示例配置 - 使用带有RequestHeaderAuthenticationFilter的 XML 和PreAuthenticatedAuthenticationProvider以及UserDetailsS​​ervice来查找用户.

这如何映射到基于Java的配置?

<security:http>
  <!-- Additional http configuration omitted -->
  <security:custom-filter position="PRE_AUTH_FILTER" ref="siteminderFilter" />
</security:http>

<bean id="siteminderFilter" class="org.springframework.security.web.authentication.preauth.RequestHeaderAuthenticationFilter">
  <property name="principalRequestHeader" value="AUTH_USER"/>
  <property name="authenticationManager" ref="authenticationManager" />
</bean>

<bean id="preauthAuthProvider" class="org.springframework.security.web.authentication.preauth.    PreAuthenticatedAuthenticationProvider">
  <property name="preAuthenticatedUserDetailsService">
    <bean id="userDetailsServiceWrapper"
          class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
      <property name="userDetailsService" ref="userDetailsService"/>
    </bean>
  </property>
</bean>

<security:authentication-manager alias="authenticationManager">
   <security:authentication-provider ref="preauthAuthProvider" />
</security:authentication-manager>
Run Code Online (Sandbox Code Playgroud)

Spring Security preauth示例具有完全不同的设置(XML配置更加令人生畏).没有提到pre-auth过滤器或如何设置标题名称.

@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests() …
Run Code Online (Sandbox Code Playgroud)

java spring-security single-sign-on pre-authentication spring-boot

12
推荐指数
1
解决办法
1万
查看次数