JAVA-14897 Update spring-security-auth0 module under spring-security modules to remove usage of deprecated WebSecurityConfigurerAdapter (#13070)

* JAVA-14897 Update spring-security-auth0 module under spring-security-modules to remove usage of deprecated WebSecurityConfigurerAdapter

* JAVA-14897 Code update as per review comment
This commit is contained in:
anuragkumawat 2022-11-25 19:50:00 +05:30 committed by GitHub
parent 3feba66f4c
commit 8ee7dcd350
1 changed files with 19 additions and 15 deletions

View File

@ -7,10 +7,9 @@ import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
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.WebSecurityConfigurerAdapter;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import com.auth0.AuthenticationController;
@ -20,7 +19,7 @@ import com.auth0.jwk.JwkProviderBuilder;
@Configuration
@EnableWebSecurity
public class AuthConfig extends WebSecurityConfigurerAdapter {
public class AuthConfig {
@Value(value = "${com.auth0.domain}")
private String domain;
@ -53,18 +52,23 @@ public class AuthConfig extends WebSecurityConfigurerAdapter {
.build();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http
.authorizeRequests()
.antMatchers("/callback", "/login", "/").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.and()
.logout().logoutSuccessHandler(logoutSuccessHandler()).permitAll();
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf()
.disable()
.authorizeRequests()
.antMatchers("/callback", "/login", "/")
.permitAll()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.and()
.logout()
.logoutSuccessHandler(logoutSuccessHandler())
.permitAll();
return http.build();
}
public String getDomain() {