Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer;
import org.springframework.security.config.ldap.LdapBindAuthenticationManagerFactory;
import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.ldap.DefaultSpringSecurityContextSource;
import org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider;
import org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator;
import org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator;
import org.springframework.security.ldap.userdetails.PersonContextMapper;
Expand Down Expand Up @@ -199,6 +201,25 @@ public LdapAuthoritiesPopulator authorities(BaseLdapPathContextSource contextSou
return myAuthPopulator;
}

@Bean
@ConditionalOnProperty(name = "auth.impl", havingValue = "ad")
public AuthenticationManager authenticationProvider() throws Exception {
ActiveDirectoryLdapAuthenticationProvider adProvider =
new ActiveDirectoryLdapAuthenticationProvider(ad_domain, ad_url);
adProvider.setConvertSubErrorCodesToExceptions(true);
adProvider.setUseAuthenticationRequestCredentials(true);
adProvider.setUserDetailsContextMapper(new PersonContextMapper());
SimpleAuthorityMapper simpleAuthorityMapper = new SimpleAuthorityMapper();
simpleAuthorityMapper.setConvertToUpperCase(true);
adProvider.setAuthoritiesMapper(simpleAuthorityMapper);
return new AuthenticationManagerBuilder(new ObjectPostProcessor<>() {
@Override
public <O> O postProcess(O object) {
return object;
}
}).authenticationProvider(adProvider).build();
}

@Bean
@ConditionalOnProperty(name = "auth.impl", havingValue = "demo")
public AuthenticationManager demoAuthenticationManager(AuthenticationManagerBuilder auth) throws Exception {
Expand Down