|
@@ -31,7 +31,6 @@ 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.configuration.WebSecurityConfigurerAdapter;
|
|
|
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;
|
|
@@ -43,6 +42,7 @@ import org.springframework.security.oauth2.jwt.NimbusJwtEncoder;
|
|
|
import org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationEntryPoint;
|
|
|
import org.springframework.security.oauth2.server.resource.web.access.BearerTokenAccessDeniedHandler;
|
|
|
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
|
|
+import org.springframework.security.web.SecurityFilterChain;
|
|
|
|
|
|
/**
|
|
|
* Security configuration for the main application.
|
|
@@ -50,7 +50,7 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager;
|
|
|
* @author Josh Cummings
|
|
|
*/
|
|
|
@Configuration
|
|
|
-public class RestConfig extends WebSecurityConfigurerAdapter {
|
|
|
+public class RestConfig {
|
|
|
|
|
|
@Value("${jwt.public.key}")
|
|
|
RSAPublicKey key;
|
|
@@ -58,22 +58,23 @@ public class RestConfig extends WebSecurityConfigurerAdapter {
|
|
|
@Value("${jwt.private.key}")
|
|
|
RSAPrivateKey priv;
|
|
|
|
|
|
- @Override
|
|
|
- protected void configure(HttpSecurity http) throws Exception {
|
|
|
+ @Bean
|
|
|
+ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
|
|
|
// @formatter:off
|
|
|
http
|
|
|
- .authorizeHttpRequests((authorize) -> authorize
|
|
|
- .anyRequest().authenticated()
|
|
|
- )
|
|
|
- .csrf((csrf) -> csrf.ignoringAntMatchers("/token"))
|
|
|
- .httpBasic(Customizer.withDefaults())
|
|
|
- .oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
|
|
|
- .sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
|
|
- .exceptionHandling((exceptions) -> exceptions
|
|
|
- .authenticationEntryPoint(new BearerTokenAuthenticationEntryPoint())
|
|
|
- .accessDeniedHandler(new BearerTokenAccessDeniedHandler())
|
|
|
- );
|
|
|
+ .authorizeHttpRequests((authorize) -> authorize
|
|
|
+ .anyRequest().authenticated()
|
|
|
+ )
|
|
|
+ .csrf((csrf) -> csrf.ignoringAntMatchers("/token"))
|
|
|
+ .httpBasic(Customizer.withDefaults())
|
|
|
+ .oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
|
|
|
+ .sessionManagement((session) -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
|
|
+ .exceptionHandling((exceptions) -> exceptions
|
|
|
+ .authenticationEntryPoint(new BearerTokenAuthenticationEntryPoint())
|
|
|
+ .accessDeniedHandler(new BearerTokenAccessDeniedHandler())
|
|
|
+ );
|
|
|
// @formatter:on
|
|
|
+ return http.build();
|
|
|
}
|
|
|
|
|
|
@Bean
|