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 of `IdPSession` for use with `StorageBackedSessionManager`.

## 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 final org.slf4j.Logger`
`log`
Class logger.
`private final StorageBackedSessionManager`
`sessionManager`
Back-reference to parent instance.
`private long`
`version`
Storage 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

Modifier and Type
Method
Description
`AuthenticationResult`
`addAuthenticationResult(AuthenticationResult result)`
Add a new `AuthenticationResult` to this IdP session, replacing any existing result of the same flow ID.
`SPSession`
`addSPSession(SPSession spSession)`
Add a new SP session to this IdP session, replacing any existing session for the same service.
`void`
`bindToAddress(String address)`
Associate an address with this session.
`boolean`
`checkAddress(String address)`
Test the session's validity based on the supplied client address, possibly binding it to the session if appropriate.
`boolean`
`checkTimeout()`
Test the session's validity based on inactivity, while updating the last activity time.
`AuthenticationResult`
`getAuthenticationResult(String flowId)`
Get an associated `AuthenticationResult` given its flow ID.
`protected Map<String,Optional<AuthenticationResult>>`
`getAuthenticationResultMap()`
Accessor for the underlying `AuthenticationResult` map maintained with the IdP session.
`Set<AuthenticationResult>`
`getAuthenticationResults()`
Get the unmodifiable set of `AuthenticationResult`s associated with this session.
`SPSession`
`getSPSession(String serviceId)`
Get the SPSession for a given service.
`protected Map<String,Optional<SPSession>>`
`getSPSessionMap()`
Accessor for the underlying `SPSession` map maintained with the IdP session.
`Set<SPSession>`
`getSPSessions()`
Gets the unmodifiable collection of service sessions associated with this session.
`private String`
`getSPSessionStorageKey(String serviceId)`
Convert a service identifier into a suitable key for the underlying storage service.
`protected long`
`getVersion()`
Get the record version.
`private AuthenticationResult`
`loadAuthenticationResultFromStorage(String flowId)`
Loads an `AuthenticationResult` record from storage and deserializes it using the object attached to the corresponding `AuthenticationFlowDescriptor`.
`private SPSession`
`loadSPSessionFromStorage(String serviceId)`
Loads a `SPSession` record from storage and deserializes it using the object registered in the attached `SPSessionSerializerRegistry`.
`boolean`
`removeAuthenticationResult(AuthenticationResult result)`
Disassociate an `AuthenticationResult` from this IdP session.
`boolean`
`removeSPSession(SPSession spSession)`
Disassociate the given SP session from this IdP session.
`private boolean`
`saveAuthenticationResultToStorage(AuthenticationResult result)`
Saves an `AuthenticationResult` record to storage, serializing it using the object attached to the corresponding `AuthenticationFlowDescriptor`.
`private boolean`
`saveSPSessionToStorage(SPSession session)`
Saves a `SPSession` record to storage.
`void`
`setLastActivityInstant(Instant instant)`
Set the last activity instant for the session.
`protected void`
`setVersion(long ver)`
Set the record version.
`void`
`updateAuthenticationResultActivity(AuthenticationResult result)`
Update the recorded activity timestamp for an `AuthenticationResult` associated with this session.
`private boolean`
`writeToStorage()`
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`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### 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 Details

### StorageBackedIdPSession

public StorageBackedIdPSession(@Nonnull StorageBackedSessionManager manager, @Nonnull @NotEmpty String sessionId, @Nonnull @NotEmpty String canonicalName, @Nonnull Instant creationTime)
Constructor.

Parameters:
  `manager` - parent SessionManager instance
  `sessionId` - unique ID of session
  `canonicalName` - canonical name of session subject
  `creationTime` - creation time of session

## Method Details

### setLastActivityInstant

public void setLastActivityInstant(@Nonnull Instant instant) throws SessionException
Set the last activity instant for the session.

Overrides:
  `setLastActivityInstant` in class `AbstractIdPSession`
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:
  `checkAddress` in interface `IdPSession`
Overrides:
  `checkAddress` in class `AbstractIdPSession`
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:
  `bindToAddress` in class `AbstractIdPSession`
Parameters:
  `address` - the address to associate
Throws:
  `SessionException` - if an error occurs binding the address to the session

### getAuthenticationResults

@Nonnull @NotLive @Unmodifiable public Set<AuthenticationResult> getAuthenticationResults()
Get the unmodifiable set of `AuthenticationResult`s associated with this session.

Specified by:
  `getAuthenticationResults` in interface `IdPSession`
Overrides:
  `getAuthenticationResults` in class `AbstractIdPSession`
Returns:
  unmodifiable set of results

### getAuthenticationResult

@Nullable public AuthenticationResult getAuthenticationResult(@Nonnull @NotEmpty String flowId)
Get an associated `AuthenticationResult` given its flow ID.

Specified by:
  `getAuthenticationResult` in interface `IdPSession`
Overrides:
  `getAuthenticationResult` in class `AbstractIdPSession`
Parameters:
  `flowId` - the ID of the `AuthenticationResult`
Returns:
  the authentication result, or null

### addAuthenticationResult

@Nullable public AuthenticationResult addAuthenticationResult(@Nonnull AuthenticationResult result) throws SessionException
Add a new `AuthenticationResult` to this IdP session, replacing any existing result of the same flow ID.

Specified by:
  `addAuthenticationResult` in interface `IdPSession`
Overrides:
  `addAuthenticationResult` in class `AbstractIdPSession`
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 SessionException
Update the recorded activity timestamp for an `AuthenticationResult` associated 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 SessionException
Disassociate an `AuthenticationResult` from this IdP session.

Specified by:
  `removeAuthenticationResult` in interface `IdPSession`
Overrides:
  `removeAuthenticationResult` in class `AbstractIdPSession`
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 @NotLive @Unmodifiable public Set<SPSession> getSPSessions()
Gets the unmodifiable collection of service sessions associated with this session.

Specified by:
  `getSPSessions` in interface `IdPSession`
Overrides:
  `getSPSessions` in class `AbstractIdPSession`
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:
  `getSPSession` in interface `IdPSession`
Overrides:
  `getSPSession` in class `AbstractIdPSession`
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:
  `addSPSession` in interface `IdPSession`
Overrides:
  `addSPSession` in class `AbstractIdPSession`
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 SessionException
Disassociate the given SP session from this IdP session.

Specified by:
  `removeSPSession` in interface `IdPSession`
Overrides:
  `removeSPSession` in class `AbstractIdPSession`
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 SessionException
Test the session's validity based on inactivity, while updating the last activity time.

Specified by:
  `checkTimeout` in interface `IdPSession`
Overrides:
  `checkTimeout` in class `AbstractIdPSession`
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 @Live protected Map<String,Optional<AuthenticationResult>> getAuthenticationResultMap()
Accessor for the underlying `AuthenticationResult` map maintained with the IdP session.

Overrides:
  `getAuthenticationResultMap` in class `AbstractIdPSession`
Returns:
  direct access to the result map

### getSPSessionMap

@Nonnull @Live protected Map<String,Optional<SPSession>> getSPSessionMap()
Accessor for the underlying `SPSession` map maintained with the IdP session.

Overrides:
  `getSPSessionMap` in class `AbstractIdPSession`
Returns:
  direct access to the service session map

### loadAuthenticationResultFromStorage

@Nullable private AuthenticationResult loadAuthenticationResultFromStorage(@Nonnull @NotEmpty String flowId) throws IOException
Loads an `AuthenticationResult` record from storage and deserializes it using the object attached to the corresponding `AuthenticationFlowDescriptor`.

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 IOException
Saves an `AuthenticationResult` record to storage, serializing it using the object attached to the corresponding `AuthenticationFlowDescriptor`.

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 a `SPSession` record from storage and deserializes it using the object registered in the attached `SPSessionSerializerRegistry`.

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 IOException
Saves a `SPSession` record 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 IOException
Update 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