From 873c947212a41c792d0fe65406be09eaacee108f Mon Sep 17 00:00:00 2001 From: tre2man Date: Mon, 25 Mar 2024 15:05:42 +0900 Subject: [PATCH] Update deprecated jwt customizer --- .../src/main/java/example/RestConfig.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/servlet/spring-boot/java/jwt/login/src/main/java/example/RestConfig.java b/servlet/spring-boot/java/jwt/login/src/main/java/example/RestConfig.java index bec4aaf7f..46cb74958 100644 --- a/servlet/spring-boot/java/jwt/login/src/main/java/example/RestConfig.java +++ b/servlet/spring-boot/java/jwt/login/src/main/java/example/RestConfig.java @@ -16,22 +16,17 @@ package example; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; - import com.nimbusds.jose.jwk.JWK; import com.nimbusds.jose.jwk.JWKSet; import com.nimbusds.jose.jwk.RSAKey; import com.nimbusds.jose.jwk.source.ImmutableJWKSet; import com.nimbusds.jose.jwk.source.JWKSource; import com.nimbusds.jose.proc.SecurityContext; - import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetailsService; @@ -44,6 +39,9 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.web.SecurityFilterChain; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; + /** * Security configuration for the main application. * @@ -62,14 +60,14 @@ public class RestConfig { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { // @formatter:off http - .authorizeHttpRequests((authorize) -> authorize + .authorizeHttpRequests(authorize -> authorize .anyRequest().authenticated() ) - .csrf((csrf) -> csrf.ignoringRequestMatchers("/token")) + .csrf(csrf -> csrf.ignoringRequestMatchers("/token")) .httpBasic(Customizer.withDefaults()) - .oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt) - .sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) - .exceptionHandling((exceptions) -> exceptions + .oauth2ResourceServer(oauth2 -> oauth2.jwt(Customizer.withDefaults())) + .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) + .exceptionHandling(exceptions -> exceptions .authenticationEntryPoint(new BearerTokenAuthenticationEntryPoint()) .accessDeniedHandler(new BearerTokenAccessDeniedHandler()) );