|
|
@ -23,9 +23,7 @@ import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
import org.springframework.security.config.Customizer;
|
|
|
|
|
|
|
|
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.configurers.oauth2.server.resource.OAuth2ResourceServerConfigurer;
|
|
|
|
|
|
|
|
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
|
|
|
|
import org.springframework.security.oauth2.server.authorization.client.RegisteredClientRepository;
|
|
|
|
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration;
|
|
|
|
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configuration.OAuth2AuthorizationServerConfiguration;
|
|
|
|
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2AuthorizationServerConfigurer;
|
|
|
|
import org.springframework.security.oauth2.server.authorization.config.annotation.web.configurers.OAuth2AuthorizationServerConfigurer;
|
|
|
@ -33,6 +31,8 @@ import org.springframework.security.oauth2.server.authorization.settings.Authori
|
|
|
|
import org.springframework.security.web.SecurityFilterChain;
|
|
|
|
import org.springframework.security.web.SecurityFilterChain;
|
|
|
|
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
|
|
|
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.security.config.Customizer.withDefaults;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@link Configuration @Configuration} for OAuth2 authorization server support.
|
|
|
|
* {@link Configuration @Configuration} for OAuth2 authorization server support.
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -47,18 +47,17 @@ class OAuth2AuthorizationServerWebSecurityConfiguration {
|
|
|
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
|
|
|
@Order(Ordered.HIGHEST_PRECEDENCE)
|
|
|
|
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
|
|
|
|
SecurityFilterChain authorizationServerSecurityFilterChain(HttpSecurity http) throws Exception {
|
|
|
|
OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http);
|
|
|
|
OAuth2AuthorizationServerConfiguration.applyDefaultSecurity(http);
|
|
|
|
http.getConfigurer(OAuth2AuthorizationServerConfigurer.class).oidc(Customizer.withDefaults());
|
|
|
|
http.getConfigurer(OAuth2AuthorizationServerConfigurer.class).oidc(withDefaults());
|
|
|
|
http.oauth2ResourceServer(OAuth2ResourceServerConfigurer::jwt)
|
|
|
|
http.oauth2ResourceServer((resourceServer) -> resourceServer.jwt(withDefaults()));
|
|
|
|
.exceptionHandling((exceptions) -> exceptions
|
|
|
|
http.exceptionHandling(
|
|
|
|
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")));
|
|
|
|
(exceptions) -> exceptions.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")));
|
|
|
|
return http.build();
|
|
|
|
return http.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@Order(SecurityProperties.BASIC_AUTH_ORDER)
|
|
|
|
@Order(SecurityProperties.BASIC_AUTH_ORDER)
|
|
|
|
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
|
|
|
|
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
|
|
|
|
http.authorizeHttpRequests((authorize) -> authorize.anyRequest().authenticated())
|
|
|
|
http.authorizeHttpRequests((authorize) -> authorize.anyRequest().authenticated()).formLogin(withDefaults());
|
|
|
|
.formLogin(Customizer.withDefaults());
|
|
|
|
|
|
|
|
return http.build();
|
|
|
|
return http.build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|