Class SecurityConfig
java.lang.Object
com.irurueta.authserver.bff.api.web.security.SecurityConfig
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
FieldsModifier and TypeFieldDescription(package private) static final StringContent security policy of the BFF: same-origin resources only (soscript-src 'self'), no framing.(package private) static final StringPath of the logout, answered by Spring Security's logout filter (only toPOST).(package private) static final StringPage the browser is sent to when the sign-in fails (for example, the user denied the consent). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) org.springframework.security.oauth2.client.OAuth2AuthorizedClientManagerauthorizedClientManager(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.OAuth2AuthorizedClientRepositoryKeeps 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.SecurityFilterChainbffFilterChain(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.
-
Field Details
-
CONTENT_SECURITY_POLICY
Content security policy of the BFF: same-origin resources only (soscript-src 'self'), no framing.- See Also:
-
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
Path of the logout, answered by Spring Security's logout filter (only toPOST).- 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 thereturnToof 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_codeandrefresh_tokenproviders.
-