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
    Modifier and Type
    Field
    Description
    (package private) static final String
    Authority of the scope that allows deleting documents.
    (package private) static final String
    Path pattern of a single document.
    (package private) static final String
    Authority of the scope that allows reading documents.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    (package private) org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationConverter
    Maps the scope claim to SCOPE_* authorities (the default converter) and the roles claim to ROLE_* authorities.
    (package private) 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)
    Builds the filter chain of the opaque-token variant.
    (package private) 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.
    private static void
    Fails fast when no accepted audience is configured, instead of accepting every token.
    (package private) 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)
    Builds the filter chain validating bearer JWTs (the decoder is built from issuer-uri, and the configured audiences are validated by it).
    (package private) StepUpAccessDeniedHandler
    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) StepUpAuthorizationManager
    Builds the manager that requires a recent strong authentication to delete a document.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 from issuer-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

      @Bean StepUpAuthorizationManager stepUpAuthorizationManager(StepUpProperties properties)
      Builds the manager that requires a recent strong authentication to delete a document.
      Parameters:
      properties - the step-up policy.
      Returns:
      the manager.
    • stepUpAccessDeniedHandler

      @Bean StepUpAccessDeniedHandler stepUpAccessDeniedHandler(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.
      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 (see application-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 the scope claim to SCOPE_* authorities (the default converter) and the roles claim to ROLE_* 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

      private static void requireAudiences(List<String> audiences)
      Fails fast when no accepted audience is configured, instead of accepting every token.
      Parameters:
      audiences - configured audiences.
      Throws:
      IllegalStateException - if there is none.