Class SecurityConfig

java.lang.Object
com.irurueta.authserver.bff.api.web.security.SecurityConfig

@Configuration(proxyBeanMethods=false) public class SecurityConfig extends Object
Signs users in with OAuth2 / OpenID Connect login and out with the RP-initiated logout of the authorization server. API calls from the SPA get a 401 instead of a redirect, and every state-changing request must carry the CSRF token the SPA reads from the XSRF-TOKEN cookie. The tokens of the user stay in the HTTP session (persisted by Spring Session JDBC), never in the browser.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final String
    Content security policy of the BFF: same-origin resources only (so script-src 'self'), no framing.
    (package private) static final String
    Path of the logout, answered by Spring Security's logout filter (only to POST).
    (package private) static final String
    Page the browser is sent to when the sign-in fails (for example, the user denied the consent).
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager
    authorizedClientManager(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRepository, org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository authorizedClientRepository)
    Builds the manager that obtains the access token of the signed-in user and renews it with its refresh token when it expires.
    (package private) org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository
    Keeps the authorized clients (the tokens of the signed-in user) in the HTTP session, which Spring Session JDBC persists, so no table of its own is needed and the tokens never reach the browser.
    (package private) org.springframework.security.web.SecurityFilterChain
    bffFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http, org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRepository, ReturnToAuthenticationSuccessHandler loginSuccessHandler, org.springframework.security.oauth2.client.oidc.web.logout.OidcClientInitiatedLogoutSuccessHandler logoutSuccessHandler)
    Builds the BFF filter chain.

    Methods inherited from class java.lang.Object

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

    • CONTENT_SECURITY_POLICY

      static final String CONTENT_SECURITY_POLICY
      Content security policy of the BFF: same-origin resources only (so script-src 'self'), no framing.
      See Also:
    • SIGN_IN_FAILURE_URL

      static final String SIGN_IN_FAILURE_URL
      Page the browser is sent to when the sign-in fails (for example, the user denied the consent).
      See Also:
    • LOGOUT_PATH

      static final String LOGOUT_PATH
      Path of the logout, answered by Spring Security's logout filter (only to POST).
      See Also:
  • Constructor Details

    • SecurityConfig

      public SecurityConfig()
  • Method Details

    • bffFilterChain

      @Bean org.springframework.security.web.SecurityFilterChain bffFilterChain(org.springframework.security.config.annotation.web.builders.HttpSecurity http, org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRepository, ReturnToAuthenticationSuccessHandler loginSuccessHandler, org.springframework.security.oauth2.client.oidc.web.logout.OidcClientInitiatedLogoutSuccessHandler logoutSuccessHandler) throws Exception
      Builds the BFF filter chain.
      Parameters:
      http - the HTTP security builder.
      clientRepository - the registered OAuth2 clients.
      loginSuccessHandler - sends the browser back to the returnTo of the login once signed in.
      logoutSuccessHandler - redirects the browser to the RP-initiated logout of the authorization server.
      Returns:
      the security filter chain.
      Throws:
      Exception - if the chain cannot be built.
    • authorizedClientRepository

      @Bean org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository authorizedClientRepository()
      Keeps the authorized clients (the tokens of the signed-in user) in the HTTP session, which Spring Session JDBC persists, so no table of its own is needed and the tokens never reach the browser.
      Returns:
      the repository of authorized clients.
    • authorizedClientManager

      @Bean org.springframework.security.oauth2.client.OAuth2AuthorizedClientManager authorizedClientManager(org.springframework.security.oauth2.client.registration.ClientRegistrationRepository clientRepository, org.springframework.security.oauth2.client.web.OAuth2AuthorizedClientRepository authorizedClientRepository)
      Builds the manager that obtains the access token of the signed-in user and renews it with its refresh token when it expires.
      Parameters:
      clientRepository - the registered OAuth2 clients.
      authorizedClientRepository - where the authorized clients are kept.
      Returns:
      the authorized client manager, with the authorization_code and refresh_token providers.