Class SessionBasedExternalAuthenticationRepository
java.lang.Object
se.swedenconnect.spring.saml.idp.authentication.provider.external.SessionBasedExternalAuthenticationRepository
- All Implemented Interfaces:
ExternalAuthenticatorTokenRepository,FilterAuthenticationTokenRepository
public class SessionBasedExternalAuthenticationRepository
extends Object
implements FilterAuthenticationTokenRepository, ExternalAuthenticatorTokenRepository
An implementation of the
FilterAuthenticationTokenRepository and ExternalAuthenticatorTokenRepository
interfaces that is session based.- Author:
- Martin Lindström
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name of the session key where we store theRedirectForAuthenticationToken.static final StringThe name of the session key where we store theResumedAuthenticationToken(i.e., the result). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear(jakarta.servlet.http.HttpServletRequest request) Clears the current external authentication.voidcompleteExternalAuthentication(org.springframework.security.core.Authentication token, jakarta.servlet.http.HttpServletRequest request) Is invoken to commit theAuthenticationtoken that is the result from the external user authentication.voidcompleteExternalAuthentication(Saml2ErrorStatusException error, jakarta.servlet.http.HttpServletRequest request) Is invoken to commit theSaml2ErrorStatusExceptionthat is a description for a failed user authentication.getCompletedExternalAuthentication(jakarta.servlet.http.HttpServletRequest request) Is invoked when theSaml2UserAuthenticationProcessingFilterreceives a request on its "resume paths" (seeSaml2UserAuthenticationProcessingFilter.setResumeAuthnRequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher)).getExternalAuthenticationToken(jakarta.servlet.http.HttpServletRequest request) Gets theRedirectForAuthenticationTokenthat is the input for an external authentication process.voidstartExternalAuthentication(RedirectForAuthenticationToken token, jakarta.servlet.http.HttpServletRequest request) Starts an external authentication processs by storing the suppliedRedirectForAuthenticationToken.
-
Field Details
-
INPUT_SESSION_KEY
The name of the session key where we store theRedirectForAuthenticationToken. -
RESULT_SESSION_KEY
The name of the session key where we store theResumedAuthenticationToken(i.e., the result).
-
-
Constructor Details
-
SessionBasedExternalAuthenticationRepository
public SessionBasedExternalAuthenticationRepository()
-
-
Method Details
-
startExternalAuthentication
public void startExternalAuthentication(RedirectForAuthenticationToken token, jakarta.servlet.http.HttpServletRequest request) Starts an external authentication processs by storing the suppliedRedirectForAuthenticationToken.This happens when the
Saml2UserAuthenticationProcessingFilterreceives aRedirectForAuthenticationTokenfrom a call toAuthenticationManager.authenticate(Authentication).Any previously stored tokens are cleared.
- Specified by:
startExternalAuthenticationin interfaceFilterAuthenticationTokenRepository- Parameters:
token- theRedirectForAuthenticationTokenrequest- the HTTP servlet request
-
getCompletedExternalAuthentication
public ResumedAuthenticationToken getCompletedExternalAuthentication(jakarta.servlet.http.HttpServletRequest request) throws IllegalStateException Is invoked when theSaml2UserAuthenticationProcessingFilterreceives a request on its "resume paths" (seeSaml2UserAuthenticationProcessingFilter.setResumeAuthnRequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher)).The method gets the
Authenticationobject stored by the authenticator (ExternalAuthenticatorTokenRepository.completeExternalAuthentication(Authentication, HttpServletRequest)orExternalAuthenticatorTokenRepository.completeExternalAuthentication(Saml2ErrorStatusException, HttpServletRequest)) and creates aResumedAuthenticationToken.- Specified by:
getCompletedExternalAuthenticationin interfaceFilterAuthenticationTokenRepository- Parameters:
request- the HTTP request- Returns:
- a
ResumedAuthenticationTokenornullif no token exists - Throws:
IllegalStateException- if aResumedAuthenticationTokentoken exists, but no correspondingRedirectForAuthenticationToken
-
getExternalAuthenticationToken
public RedirectForAuthenticationToken getExternalAuthenticationToken(jakarta.servlet.http.HttpServletRequest request) Gets theRedirectForAuthenticationTokenthat is the input for an external authentication process.- Specified by:
getExternalAuthenticationTokenin interfaceExternalAuthenticatorTokenRepository- Parameters:
request- the HTTP servlet request- Returns:
- the
RedirectForAuthenticationTokenornullif not present
-
completeExternalAuthentication
public void completeExternalAuthentication(org.springframework.security.core.Authentication token, jakarta.servlet.http.HttpServletRequest request) throws IllegalStateException Is invoken to commit theAuthenticationtoken that is the result from the external user authentication.- Specified by:
completeExternalAuthenticationin interfaceExternalAuthenticatorTokenRepository- Parameters:
token- theAuthenticationtokenrequest- the current HTTP request- Throws:
IllegalStateException- if the correspondingRedirectForAuthenticationTokenis not available in the repository
-
completeExternalAuthentication
public void completeExternalAuthentication(Saml2ErrorStatusException error, jakarta.servlet.http.HttpServletRequest request) throws IllegalStateException Is invoken to commit theSaml2ErrorStatusExceptionthat is a description for a failed user authentication.- Specified by:
completeExternalAuthenticationin interfaceExternalAuthenticatorTokenRepository- Parameters:
error- the errorrequest- the current HTTP request- Throws:
IllegalStateException- if the correspondingRedirectForAuthenticationTokenis not available in the repository
-
clear
public void clear(jakarta.servlet.http.HttpServletRequest request) Clears the current external authentication.- Specified by:
clearin interfaceFilterAuthenticationTokenRepository- Parameters:
request- the HTTP servlet request
-