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
Modifier and TypeFieldDescriptionstatic final String
The name of the session key where we store theRedirectForAuthenticationToken
.static final String
The name of the session key where we store theResumedAuthenticationToken
(i.e., the result). -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear
(jakarta.servlet.http.HttpServletRequest request) Clears the current external authentication.void
completeExternalAuthentication
(org.springframework.security.core.Authentication token, jakarta.servlet.http.HttpServletRequest request) Is invoken to commit theAuthentication
token that is the result from the external user authentication.void
completeExternalAuthentication
(Saml2ErrorStatusException error, jakarta.servlet.http.HttpServletRequest request) Is invoken to commit theSaml2ErrorStatusException
that is a description for a failed user authentication.getCompletedExternalAuthentication
(jakarta.servlet.http.HttpServletRequest request) Is invoked when theSaml2UserAuthenticationProcessingFilter
receives a request on its "resume paths" (seeSaml2UserAuthenticationProcessingFilter.setResumeAuthnRequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher)
).getExternalAuthenticationToken
(jakarta.servlet.http.HttpServletRequest request) Gets theRedirectForAuthenticationToken
that is the input for an external authentication process.void
startExternalAuthentication
(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
Saml2UserAuthenticationProcessingFilter
receives aRedirectForAuthenticationToken
from a call toAuthenticationManager.authenticate(Authentication)
.Any previously stored tokens are cleared.
- Specified by:
startExternalAuthentication
in interfaceFilterAuthenticationTokenRepository
- Parameters:
token
- theRedirectForAuthenticationToken
request
- the HTTP servlet request
-
getCompletedExternalAuthentication
public ResumedAuthenticationToken getCompletedExternalAuthentication(jakarta.servlet.http.HttpServletRequest request) throws IllegalStateException Is invoked when theSaml2UserAuthenticationProcessingFilter
receives a request on its "resume paths" (seeSaml2UserAuthenticationProcessingFilter.setResumeAuthnRequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher)
).The method gets the
Authentication
object stored by the authenticator (ExternalAuthenticatorTokenRepository.completeExternalAuthentication(Authentication, HttpServletRequest)
orExternalAuthenticatorTokenRepository.completeExternalAuthentication(Saml2ErrorStatusException, HttpServletRequest)
) and creates aResumedAuthenticationToken
.- Specified by:
getCompletedExternalAuthentication
in interfaceFilterAuthenticationTokenRepository
- Parameters:
request
- the HTTP request- Returns:
- a
ResumedAuthenticationToken
ornull
if no token exists - Throws:
IllegalStateException
- if aResumedAuthenticationToken
token exists, but no correspondingRedirectForAuthenticationToken
-
getExternalAuthenticationToken
public RedirectForAuthenticationToken getExternalAuthenticationToken(jakarta.servlet.http.HttpServletRequest request) Gets theRedirectForAuthenticationToken
that is the input for an external authentication process.- Specified by:
getExternalAuthenticationToken
in interfaceExternalAuthenticatorTokenRepository
- Parameters:
request
- the HTTP servlet request- Returns:
- the
RedirectForAuthenticationToken
ornull
if not present
-
completeExternalAuthentication
public void completeExternalAuthentication(org.springframework.security.core.Authentication token, jakarta.servlet.http.HttpServletRequest request) throws IllegalStateException Is invoken to commit theAuthentication
token that is the result from the external user authentication.- Specified by:
completeExternalAuthentication
in interfaceExternalAuthenticatorTokenRepository
- Parameters:
token
- theAuthentication
tokenrequest
- the current HTTP request- Throws:
IllegalStateException
- if the correspondingRedirectForAuthenticationToken
is not available in the repository
-
completeExternalAuthentication
public void completeExternalAuthentication(Saml2ErrorStatusException error, jakarta.servlet.http.HttpServletRequest request) throws IllegalStateException Is invoken to commit theSaml2ErrorStatusException
that is a description for a failed user authentication.- Specified by:
completeExternalAuthentication
in interfaceExternalAuthenticatorTokenRepository
- Parameters:
error
- the errorrequest
- the current HTTP request- Throws:
IllegalStateException
- if the correspondingRedirectForAuthenticationToken
is not available in the repository
-
clear
public void clear(jakarta.servlet.http.HttpServletRequest request) Clears the current external authentication.- Specified by:
clear
in interfaceFilterAuthenticationTokenRepository
- Parameters:
request
- the HTTP servlet request
-