We use Spring boot with Spring security in our Application. Using Spring db authentication for web authentication and planning to use ldap for JMS authentication.
@Configuration
@EnableWebMvcSecurity
@ComponentScan
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
@SuppressWarnings("PMD")
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.authorizeRequests()
.antMatchers("/login", "/logoffUser", "/sessionExpired", "/error", "/unauth").permitAll()
.anyRequest().authenticated().and().rememberMe().and().httpBasic()
.authenticationEntryPoint(entryPointObj).and()
.addFilterAfter(filterObj, PreAuthenticatedProcessingFilter.class).csrf()
.disable().logout().deleteCookies("JSESSIONID").logoutSuccessUrl("/logoff").invalidateHttpSession(true);
}
}
The web authentication works without any issues.
For LDAP Authentication, we use the below code.
@Configuration
public class LdapAuthenticationConfig extends
GlobalAuthenticationConfigurerAdapter {
/** The environment. */
private Environment environment;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication()
.userSearchFilter(
"(&(sAMAccountName={0})(objectclass=organizationalPerson))")
.userSearchBase("OU=${ldap.user-search-base.name}")
.groupSearchFilter("(member={0})")
.groupSearchBase("OU=Global-Groups")
.groupRoleAttribute("un")
.contextSource()
.url(environment.getProperty("ldap.url"))
.managerDn(environment.getProperty("ldap.conn.user"))
.managerPassword(environment.getProperty("ldap.conn.pwd"));
// authenticationManager = auth.getObject();
}
@Autowired
public void setEnvironment(Environment environment) {
this.environment = environment;
}
}
I am not sure how to expose the AuthnticationManager for the ldap so that it can be injected in some other class as below.
Public class JmsConfig {
@Autowired
@Qualifier("ldapAuthManager")
private AuthenticationManager authenticationManager;
}