JAVA-14890 Update spring-security-oauth2-sso module under spring-security-modules to remove usage of deprecated WebSecurityConfigurerAdapter (#12913)
* JAVA-14890 Update spring-security-oauth2-sso module under spring-security-modules to remove usage of deprecated WebSecurityConfigurerAdapter * JAVA-14890 Commit remaining code
This commit is contained in:
parent
84dd60e287
commit
bca5ffe971
|
@ -6,39 +6,47 @@ import org.springframework.core.io.FileSystemResource;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
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.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
|
import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
|
||||||
import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
|
import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
|
||||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
|
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
|
||||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
|
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
|
||||||
import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
|
import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
|
||||||
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||||
|
|
||||||
import com.baeldung.intro.security.DummyUserDetailsService;
|
import com.baeldung.intro.security.DummyUserDetailsService;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
public class WebSecurityConfig extends AbstractHttpConfigurer<WebSecurityConfig, HttpSecurity> {
|
||||||
|
|
||||||
|
public static WebSecurityConfig securityConfig() {
|
||||||
|
return new WebSecurityConfig();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public void configure(HttpSecurity http) throws Exception {
|
||||||
|
AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class);
|
||||||
|
http.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManager), BasicAuthenticationFilter.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
http.authorizeRequests()
|
http.authorizeRequests()
|
||||||
.anyRequest()
|
.anyRequest()
|
||||||
.authenticated()
|
.authenticated()
|
||||||
.and()
|
.and()
|
||||||
.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class);
|
.apply(securityConfig());
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Bean
|
@Bean
|
||||||
public AuthenticationManager authenticationManagerBean() throws Exception {
|
public AuthenticationManager authManager(HttpSecurity http) throws Exception {
|
||||||
return super.authenticationManagerBean();
|
return http.getSharedObject(AuthenticationManagerBuilder.class)
|
||||||
}
|
.authenticationProvider(kerberosAuthenticationProvider())
|
||||||
|
.authenticationProvider(kerberosServiceAuthenticationProvider())
|
||||||
@Override
|
.build();
|
||||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
|
||||||
auth.authenticationProvider(kerberosAuthenticationProvider())
|
|
||||||
.authenticationProvider(kerberosServiceAuthenticationProvider());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
|
@ -9,18 +9,19 @@ import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
|
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.HttpSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
||||||
import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
|
import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider;
|
||||||
import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
|
import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider;
|
||||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
|
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient;
|
||||||
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
|
import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator;
|
||||||
import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
|
import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter;
|
||||||
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint;
|
||||||
|
import org.springframework.security.web.SecurityFilterChain;
|
||||||
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebSecurity
|
@EnableWebSecurity
|
||||||
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
class WebSecurityConfig extends AbstractHttpConfigurer<WebSecurityConfig, HttpSecurity> {
|
||||||
|
|
||||||
@Value("${app.service-principal}")
|
@Value("${app.service-principal}")
|
||||||
private String servicePrincipal;
|
private String servicePrincipal;
|
||||||
|
@ -28,31 +29,44 @@ class WebSecurityConfig extends WebSecurityConfigurerAdapter {
|
||||||
@Value("${app.keytab-location}")
|
@Value("${app.keytab-location}")
|
||||||
private String keytabLocation;
|
private String keytabLocation;
|
||||||
|
|
||||||
|
public static WebSecurityConfig securityConfig() {
|
||||||
|
return new WebSecurityConfig();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(HttpSecurity http) throws Exception {
|
public void configure(HttpSecurity http) throws Exception {
|
||||||
http.exceptionHandling()
|
AuthenticationManager authenticationManager = http.getSharedObject(AuthenticationManager.class);
|
||||||
.authenticationEntryPoint(spnegoEntryPoint())
|
http.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManager), BasicAuthenticationFilter.class);
|
||||||
.and()
|
|
||||||
.authorizeRequests().antMatchers("/", "/home").permitAll()
|
|
||||||
.anyRequest().authenticated()
|
|
||||||
.and()
|
|
||||||
.formLogin().loginPage("/login").permitAll()
|
|
||||||
.and()
|
|
||||||
.logout().permitAll()
|
|
||||||
.and()
|
|
||||||
.addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()),
|
|
||||||
BasicAuthenticationFilter.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public AuthenticationManager anAuthenticationManager() throws Exception {
|
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||||
return authenticationManager();
|
http.exceptionHandling()
|
||||||
|
.authenticationEntryPoint(spnegoEntryPoint())
|
||||||
|
.and()
|
||||||
|
.authorizeRequests()
|
||||||
|
.antMatchers("/", "/home")
|
||||||
|
.permitAll()
|
||||||
|
.anyRequest()
|
||||||
|
.authenticated()
|
||||||
|
.and()
|
||||||
|
.formLogin()
|
||||||
|
.loginPage("/login")
|
||||||
|
.permitAll()
|
||||||
|
.and()
|
||||||
|
.logout()
|
||||||
|
.permitAll()
|
||||||
|
.and()
|
||||||
|
.apply(securityConfig());
|
||||||
|
return http.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Bean
|
||||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
|
public AuthenticationManager authManager(HttpSecurity http) throws Exception {
|
||||||
auth.authenticationProvider(kerberosAuthenticationProvider())
|
return http.getSharedObject(AuthenticationManagerBuilder.class)
|
||||||
.authenticationProvider(kerberosServiceAuthenticationProvider());
|
.authenticationProvider(kerberosAuthenticationProvider())
|
||||||
|
.authenticationProvider(kerberosServiceAuthenticationProvider())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
|
Loading…
Reference in New Issue