Package net.shibboleth.idp.session.impl
Class StorageBackedIdPSession
- java.lang.Object
-
- net.shibboleth.idp.session.AbstractIdPSession
-
- net.shibboleth.idp.session.impl.StorageBackedIdPSession
-
- All Implemented Interfaces:
IdPSession,Component,IdentifiedComponent
public class StorageBackedIdPSession extends AbstractIdPSession
Implementation ofIdPSessionfor use withStorageBackedSessionManager.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.shibboleth.idp.session.AbstractIdPSession
AbstractIdPSession.AddressFamily
-
-
Field Summary
Fields Modifier and Type Field Description private org.slf4j.LoggerlogClass logger.private StorageBackedSessionManagersessionManagerBack-reference to parent instance.private longversionStorage version used to synchronize changes.-
Fields inherited from interface net.shibboleth.idp.session.IdPSession
MDC_ATTRIBUTE
-
-
Constructor Summary
Constructors Constructor Description StorageBackedIdPSession(StorageBackedSessionManager manager, String sessionId, String canonicalName, Instant creationTime)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AuthenticationResultaddAuthenticationResult(AuthenticationResult result)Add a newAuthenticationResultto this IdP session, replacing any existing result of the same flow ID.SPSessionaddSPSession(SPSession spSession)Add a new SP session to this IdP session, replacing any existing session for the same service.voidbindToAddress(String address)Associate an address with this session.booleancheckAddress(String address)Test the session's validity based on the supplied client address, possibly binding it to the session if appropriate.booleancheckTimeout()Test the session's validity based on inactivity, while updating the last activity time.AuthenticationResultgetAuthenticationResult(String flowId)Get an associatedAuthenticationResultgiven its flow ID.protected Map<String,Optional<AuthenticationResult>>getAuthenticationResultMap()Accessor for the underlyingAuthenticationResultmap maintained with the IdP session.Set<AuthenticationResult>getAuthenticationResults()Get the unmodifiable set ofAuthenticationResults associated with this session.SPSessiongetSPSession(String serviceId)Get the SPSession for a given service.protected Map<String,Optional<SPSession>>getSPSessionMap()Accessor for the underlyingSPSessionmap maintained with the IdP session.Set<SPSession>getSPSessions()Gets the unmodifiable collection of service sessions associated with this session.private StringgetSPSessionStorageKey(String serviceId)Convert a service identifier into a suitable key for the underlying storage service.protected longgetVersion()Get the record version.private AuthenticationResultloadAuthenticationResultFromStorage(String flowId)Loads anAuthenticationResultrecord from storage and deserializes it using the object attached to the correspondingAuthenticationFlowDescriptor.private SPSessionloadSPSessionFromStorage(String serviceId)Loads aSPSessionrecord from storage and deserializes it using the object registered in the attachedSPSessionSerializerRegistry.booleanremoveAuthenticationResult(AuthenticationResult result)Disassociate anAuthenticationResultfrom this IdP session.booleanremoveSPSession(SPSession spSession)Disassociate the given SP session from this IdP session.private booleansaveAuthenticationResultToStorage(AuthenticationResult result)Saves anAuthenticationResultrecord to storage, serializing it using the object attached to the correspondingAuthenticationFlowDescriptor.private booleansaveSPSessionToStorage(SPSession session)Saves aSPSessionrecord to storage.voidsetLastActivityInstant(Instant instant)Set the last activity instant for the session.protected voidsetVersion(long ver)Set the record version.voidupdateAuthenticationResultActivity(AuthenticationResult result)Update the recorded activity timestamp for anAuthenticationResultassociated with this session.private booleanwriteToStorage()Update the primary session record based on the current contents of this object.-
Methods inherited from class net.shibboleth.idp.session.AbstractIdPSession
doAddAuthenticationResult, doAddSPSession, doBindToAddress, doRemoveAuthenticationResult, doRemoveSPSession, doSetLastActivityInstant, equals, getAddress, getAddressFamily, getCreationInstant, getId, getLastActivityInstant, getPrincipalName, hashCode, toString
-
-
-
-
Field Detail
-
log
@Nonnull private final org.slf4j.Logger log
Class logger.
-
sessionManager
@Nonnull private final StorageBackedSessionManager sessionManager
Back-reference to parent instance.
-
version
private long version
Storage version used to synchronize changes.
-
-
Constructor Detail
-
StorageBackedIdPSession
public StorageBackedIdPSession(@Nonnull StorageBackedSessionManager manager, @Nonnull @NotEmpty String sessionId, @Nonnull @NotEmpty String canonicalName, @Nonnull Instant creationTime)Constructor.- Parameters:
manager- parent SessionManager instancesessionId- unique ID of sessioncanonicalName- canonical name of session subjectcreationTime- creation time of session
-
-
Method Detail
-
setLastActivityInstant
public void setLastActivityInstant(@Nonnull Instant instant) throws SessionExceptionSet the last activity instant for the session.- Overrides:
setLastActivityInstantin classAbstractIdPSession- Parameters:
instant- last activity instant for the session- Throws:
SessionException- if an error occurs updating the session
-
checkAddress
public boolean checkAddress(@Nonnull @NotEmpty String address) throws SessionException
Test the session's validity based on the supplied client address, possibly binding it to the session if appropriate.- Specified by:
checkAddressin interfaceIdPSession- Overrides:
checkAddressin classAbstractIdPSession- Parameters:
address- client address for validation- Returns:
- true iff the session is valid for the specified client address
- Throws:
SessionException- if an error occurs binding the address to the session
-
bindToAddress
public void bindToAddress(@Nonnull @NotEmpty String address) throws SessionException
Associate an address with this session.- Overrides:
bindToAddressin classAbstractIdPSession- Parameters:
address- the address to associate- Throws:
SessionException- if an error occurs binding the address to the session
-
getAuthenticationResults
@Nonnull @NonnullElements @NotLive @Unmodifiable public Set<AuthenticationResult> getAuthenticationResults()
Get the unmodifiable set ofAuthenticationResults associated with this session.- Specified by:
getAuthenticationResultsin interfaceIdPSession- Overrides:
getAuthenticationResultsin classAbstractIdPSession- Returns:
- unmodifiable set of results
-
getAuthenticationResult
@Nullable public AuthenticationResult getAuthenticationResult(@Nonnull @NotEmpty String flowId)
Get an associatedAuthenticationResultgiven its flow ID.- Specified by:
getAuthenticationResultin interfaceIdPSession- Overrides:
getAuthenticationResultin classAbstractIdPSession- Parameters:
flowId- the ID of theAuthenticationResult- Returns:
- the authentication result, or null
-
addAuthenticationResult
@Nullable public AuthenticationResult addAuthenticationResult(@Nonnull AuthenticationResult result) throws SessionException
Add a newAuthenticationResultto this IdP session, replacing any existing result of the same flow ID.- Specified by:
addAuthenticationResultin interfaceIdPSession- Overrides:
addAuthenticationResultin classAbstractIdPSession- Parameters:
result- the result to add- Returns:
- a previously existing result replaced by the new one, if any
- Throws:
SessionException- if an error occurs updating the session
-
updateAuthenticationResultActivity
public void updateAuthenticationResultActivity(@Nonnull AuthenticationResult result) throws SessionExceptionUpdate the recorded activity timestamp for anAuthenticationResultassociated with this session.- Parameters:
result- the result to update- Throws:
SessionException- if an error occurs updating the session
-
removeAuthenticationResult
public boolean removeAuthenticationResult(@Nonnull AuthenticationResult result) throws SessionExceptionDisassociate anAuthenticationResultfrom this IdP session.- Specified by:
removeAuthenticationResultin interfaceIdPSession- Overrides:
removeAuthenticationResultin classAbstractIdPSession- Parameters:
result- the result to disassociate- Returns:
- true iff the given result had been associated with this IdP session and now is not
- Throws:
SessionException- if an error occurs accessing the session
-
getSPSessions
@Nonnull @NonnullElements @NotLive @Unmodifiable public Set<SPSession> getSPSessions()
Gets the unmodifiable collection of service sessions associated with this session.- Specified by:
getSPSessionsin interfaceIdPSession- Overrides:
getSPSessionsin classAbstractIdPSession- Returns:
- unmodifiable collection of service sessions associated with this session
-
getSPSession
@Nullable public SPSession getSPSession(@Nonnull @NotEmpty String serviceId)
Get the SPSession for a given service.- Specified by:
getSPSessionin interfaceIdPSession- Overrides:
getSPSessionin classAbstractIdPSession- Parameters:
serviceId- ID of the service- Returns:
- the session service or null if no session exists for that service, may be null
-
addSPSession
@Nullable public SPSession addSPSession(@Nonnull SPSession spSession) throws SessionException
Add a new SP session to this IdP session, replacing any existing session for the same service.- Specified by:
addSPSessionin interfaceIdPSession- Overrides:
addSPSessionin classAbstractIdPSession- Parameters:
spSession- the SP session- Returns:
- a previously existing SPSession replaced by the new one, if any
- Throws:
SessionException- if an error occurs accessing the session
-
removeSPSession
public boolean removeSPSession(@Nonnull SPSession spSession) throws SessionExceptionDisassociate the given SP session from this IdP session.- Specified by:
removeSPSessionin interfaceIdPSession- Overrides:
removeSPSessionin classAbstractIdPSession- Parameters:
spSession- the SP session- Returns:
- true iff the given SP session had been associated with this IdP session and now is not
- Throws:
SessionException- if an error occurs accessing the SP session
-
checkTimeout
public boolean checkTimeout() throws SessionExceptionTest the session's validity based on inactivity, while updating the last activity time.- Specified by:
checkTimeoutin interfaceIdPSession- Overrides:
checkTimeoutin classAbstractIdPSession- Returns:
- true iff the session is still valid
- Throws:
SessionException- if an error occurs updating the activity time
-
getVersion
protected long getVersion()
Get the record version.- Returns:
- current version of the storage record
-
setVersion
protected void setVersion(long ver)
Set the record version.- Parameters:
ver- version to set
-
getAuthenticationResultMap
@Nonnull @NonnullElements @Live protected Map<String,Optional<AuthenticationResult>> getAuthenticationResultMap()
Accessor for the underlyingAuthenticationResultmap maintained with the IdP session.- Overrides:
getAuthenticationResultMapin classAbstractIdPSession- Returns:
- direct access to the result map
-
getSPSessionMap
@Nonnull @NonnullElements @Live protected Map<String,Optional<SPSession>> getSPSessionMap()
Accessor for the underlyingSPSessionmap maintained with the IdP session.- Overrides:
getSPSessionMapin classAbstractIdPSession- Returns:
- direct access to the service session map
-
loadAuthenticationResultFromStorage
@Nullable private AuthenticationResult loadAuthenticationResultFromStorage(@Nonnull @NotEmpty String flowId) throws IOException
Loads anAuthenticationResultrecord from storage and deserializes it using the object attached to the correspondingAuthenticationFlowDescriptor.- Parameters:
flowId- ID of result/flow to load- Returns:
- the stored result, or null if the record is missing or unusable
- Throws:
IOException- if a possibly transitory storage-related error occurs
-
saveAuthenticationResultToStorage
private boolean saveAuthenticationResultToStorage(@Nonnull AuthenticationResult result) throws IOExceptionSaves anAuthenticationResultrecord to storage, serializing it using the object attached to the correspondingAuthenticationFlowDescriptor.- Parameters:
result- the object to store- Returns:
- true iff the record was successfully saved
- Throws:
IOException- if a possibly transitory storage-related error occurs
-
loadSPSessionFromStorage
@Nullable private SPSession loadSPSessionFromStorage(@Nonnull @NotEmpty String serviceId) throws IOException
Loads aSPSessionrecord from storage and deserializes it using the object registered in the attachedSPSessionSerializerRegistry.- Parameters:
serviceId- ID of service for session to load- Returns:
- the stored session, or null if the record is missing or unusable
- Throws:
IOException- if a possibly transitory storage-related error occurs
-
saveSPSessionToStorage
private boolean saveSPSessionToStorage(@Nonnull SPSession session) throws IOExceptionSaves aSPSessionrecord to storage.- Parameters:
session- the object to store- Returns:
- true iff the record was successfully saved
- Throws:
IOException- if a possibly transitory storage-related error occurs
-
getSPSessionStorageKey
@Nonnull @NotEmpty private String getSPSessionStorageKey(@Nonnull @NotEmpty String serviceId)
Convert a service identifier into a suitable key for the underlying storage service.- Parameters:
serviceId- the service identifier- Returns:
- an appropriately sized storage key
-
writeToStorage
private boolean writeToStorage() throws IOExceptionUpdate the primary session record based on the current contents of this object.- Returns:
- true iff the update succeeds, false iff a version mismatch resulted in overwrite of this object
- Throws:
IOException- if an error occurs trying to perform an update
-
-