-
-
Save reflexdemon/5f53418f826b511199348238351dbe74 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package app.config; | |
import org.springframework.beans.factory.annotation.Value; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.security.authentication.AuthenticationManager; | |
import org.springframework.security.authentication.AuthenticationProvider; | |
import org.springframework.security.authentication.ProviderManager; | |
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | |
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | |
import org.springframework.security.config.annotation.web.builders.WebSecurity; | |
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | |
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | |
import org.springframework.security.ldap.authentication.ad.ActiveDirectoryLdapAuthenticationProvider; | |
import java.util.Arrays; | |
@Configuration | |
@EnableWebSecurity | |
public class WebSecurityConfigAD extends WebSecurityConfigurerAdapter { | |
@Value("${ad.domain}") | |
private String AD_DOMAIN; | |
@Value("${ad.url}") | |
private String AD_URL; | |
@Override | |
protected void configure(HttpSecurity http) throws Exception { | |
http.authorizeRequests().anyRequest().authenticated().and().httpBasic(); | |
} | |
@Override | |
protected void configure(AuthenticationManagerBuilder authManagerBuilder) throws Exception { | |
authManagerBuilder.authenticationProvider(activeDirectoryLdapAuthenticationProvider()).userDetailsService(userDetailsService()); | |
} | |
@Bean | |
public AuthenticationManager authenticationManager() { | |
return new ProviderManager(Arrays.asList(activeDirectoryLdapAuthenticationProvider())); | |
} | |
@Bean | |
public AuthenticationProvider activeDirectoryLdapAuthenticationProvider() { | |
ActiveDirectoryLdapAuthenticationProvider provider = new ActiveDirectoryLdapAuthenticationProvider(AD_DOMAIN, AD_URL); | |
provider.setConvertSubErrorCodesToExceptions(true); | |
provider.setUseAuthenticationRequestCredentials(true); | |
return provider; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment