Class SecurityConfig
java.lang.Object
com.irurueta.authserver.resourceserver.api.web.security.SecurityConfig
@Configuration(proxyBeanMethods=false)
@EnableMethodSecurity
@EnableConfigurationProperties(StepUpProperties.class)
public class SecurityConfig
extends Object
Secures the API: every request except the health endpoint and the OpenAPI document requires a valid bearer token
issued by the authorization server for this resource server's audience. Failures answer with the RFC 6750
WWW-Authenticate challenge (invalid_token / insufficient_scope). By default the tokens are
JWTs; the opaque profile introspects them instead.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidauthorize(org.springframework.security.config.annotation.web.builders.HttpSecurity http, StepUpAuthorizationManager stepUp) Declares which requests are public and which need a scope.(package private) org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverterMaps thescopeclaim toSCOPE_*authorities (the default converter) and therolesclaim toROLE_*authorities.(package private) org.springframework.security.web.SecurityFilterChainopaqueTokenFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http, org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector introspector, StepUpAuthorizationManager stepUp, StepUpAccessDeniedHandler accessDeniedHandler) Builds the filter chain of the opaque-token variant.(package private) org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospectoropaqueTokenIntrospector(org.springframework.boot.security.oauth2.server.resource.autoconfigure.OAuth2ResourceServerProperties properties) Builds the introspector of the opaque-token variant.private static voidrequireAudiences(List<String> audiences) Fails fast when no accepted audience is configured, instead of accepting every token.(package private) org.springframework.security.web.SecurityFilterChainresourceServerFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http, org.springframework.boot.security.oauth2.server.resource.autoconfigure.OAuth2ResourceServerProperties properties, StepUpAuthorizationManager stepUp, StepUpAccessDeniedHandler accessDeniedHandler) Builds the filter chain validating bearer JWTs (the decoder is built fromissuer-uri, and the configured audiences are validated by it).(package private) StepUpAccessDeniedHandlerstepUpAccessDeniedHandler(StepUpProperties properties) Builds the handler that answers the step-up requirement with the RFC 9470 challenge and every other denial with the RFC 6750 one.(package private) StepUpAuthorizationManagerstepUpAuthorizationManager(StepUpProperties properties) Builds the manager that requires a recent strong authentication to delete a document.
-
Field Details
-
READ_AUTHORITY
Authority of the scope that allows reading documents.- See Also:
-
DELETE_AUTHORITY
Authority of the scope that allows deleting documents.- See Also:
-
DOCUMENT_PATH
Path pattern of a single document.- See Also:
-
-
Constructor Details
-
SecurityConfig
public SecurityConfig()
-
-
Method Details
-
resourceServerFilterChain
@Bean @Profile("!opaque") org.springframework.security.web.SecurityFilterChain resourceServerFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http, org.springframework.boot.security.oauth2.server.resource.autoconfigure.OAuth2ResourceServerProperties properties, StepUpAuthorizationManager stepUp, StepUpAccessDeniedHandler accessDeniedHandler) throws Exception Builds the filter chain validating bearer JWTs (the decoder is built fromissuer-uri, and the configured audiences are validated by it).- Parameters:
http- the HTTP security builder.properties- the resource server properties.stepUp- requires a recent strong authentication to delete.accessDeniedHandler- answers the denials, including the step-up challenge.- Returns:
- the security filter chain.
- Throws:
Exception- if the chain cannot be built.IllegalStateException- if no accepted audience is configured.
-
opaqueTokenFilterChain
@Bean @Profile("opaque") org.springframework.security.web.SecurityFilterChain opaqueTokenFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http, org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector introspector, StepUpAuthorizationManager stepUp, StepUpAccessDeniedHandler accessDeniedHandler) throws Exception Builds the filter chain of the opaque-token variant.- Parameters:
http- the HTTP security builder.introspector- introspector that validates the opaque tokens.stepUp- requires a recent strong authentication to delete.accessDeniedHandler- answers the denials, including the step-up challenge.- Returns:
- the security filter chain.
- Throws:
Exception- if the chain cannot be built.
-
stepUpAuthorizationManager
Builds the manager that requires a recent strong authentication to delete a document.- Parameters:
properties- the step-up policy.- Returns:
- the manager.
-
stepUpAccessDeniedHandler
Builds the handler that answers the step-up requirement with the RFC 9470 challenge and every other denial with the RFC 6750 one.- Parameters:
properties- the step-up policy.- Returns:
- the handler.
-
opaqueTokenIntrospector
@Bean @Profile("opaque") org.springframework.security.oauth2.server.resource.introspection.OpaqueTokenIntrospector opaqueTokenIntrospector(org.springframework.boot.security.oauth2.server.resource.autoconfigure.OAuth2ResourceServerProperties properties) Builds the introspector of the opaque-token variant. The introspection URI and the client credentials come from the environment (seeapplication-opaque.yml); no value is ever defaulted.- Parameters:
properties- the resource server properties.- Returns:
- the introspector.
- Throws:
IllegalStateException- if no accepted audience is configured.
-
jwtAuthenticationConverter
org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter jwtAuthenticationConverter()Maps thescopeclaim toSCOPE_*authorities (the default converter) and therolesclaim toROLE_*authorities.- Returns:
- the converter.
-
authorize
private static void authorize(org.springframework.security.config.annotation.web.builders.HttpSecurity http, StepUpAuthorizationManager stepUp) Declares which requests are public and which need a scope. Deleting also needs a recent strong authentication (RFC 9470) and is protected by method security as well.- Parameters:
http- the HTTP security builder.stepUp- requires a recent strong authentication to delete.
-
requireAudiences
Fails fast when no accepted audience is configured, instead of accepting every token.- Parameters:
audiences- configured audiences.- Throws:
IllegalStateException- if there is none.
-