Package net.shibboleth.shared.security
Class EncryptedCookieManager
java.lang.Object
net.shibboleth.shared.component.AbstractInitializableComponent
net.shibboleth.shared.security.EncryptedCookieManager
- All Implemented Interfaces:
Component,DestructableComponent,InitializableComponent
Wrapper for managing a cookie encrypted with the
DataSealer component.
The component can be wired up without the necessary components, but then all operations do nothing.
This is allowed for the case where deployers disable the DataSealer component, though very rare.
- Since:
- 9.2.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanFlags whether the component is active or should no-op.private CookieManagerOptional cookie manager to use.private StringPasswordless cookie name.private DataSealerOptional data sealer to use.private final org.slf4j.LoggerClass logger.static final StringA negative signal to allow caching opt-out. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidUnset the cookie.protected voidPerforms the initialization of the component.booleanisOptOut()Tests whether the cookie's value indicates a cached negative response.Read back existing cookie and return the value embedded in it, if any.booleanFor a non-negative cookie, this recreates the cookie using the current default key to ensure it can continue to be read.voidsetCookieManager(CookieManager manager) SetsCookieManagerto use.voidsetCookieName(String name) Set cookie name to use.voidsetDataSealer(DataSealer sealer) SetsDataSealerto use.booleanwriteCookie(String value) Creates a fresh cookie for a given value (or a placeholder if null to indicate the negative).Methods inherited from class net.shibboleth.shared.component.AbstractInitializableComponent
checkComponentActive, checkSetterPreconditions, destroy, doDestroy, ifDestroyedThrowDestroyedComponentException, ifInitializedThrowUnmodifiabledComponentException, ifNotInitializedThrowUninitializedComponentException, initialize, isDestroyed, isInitialized
-
Field Details
-
NEGATIVE_VALUE
A negative signal to allow caching opt-out.- See Also:
-
log
@Nonnull private final org.slf4j.Logger logClass logger. -
cookieName
Passwordless cookie name. -
cookieManager
Optional cookie manager to use. -
dataSealer
Optional data sealer to use. -
active
private boolean activeFlags whether the component is active or should no-op.
-
-
Constructor Details
-
EncryptedCookieManager
public EncryptedCookieManager()
-
-
Method Details
-
setCookieName
Set cookie name to use.- Parameters:
name- cookie name
-
doInitialize
Performs the initialization of the component. This method is executed within the lock on the object being initialized. The default implementation of this method is a no-op.- Overrides:
doInitializein classAbstractInitializableComponent- Throws:
ComponentInitializationException- thrown if there is a problem initializing the component
-
isOptOut
public boolean isOptOut()Tests whether the cookie's value indicates a cached negative response.- Returns:
- true iff the input value corresponds to the "opt-out" constant
-
readCookie
Read back existing cookie and return the value embedded in it, if any.A null is returned in the event of various decoding errors or if the cookie contains the "negative" magic value.
- Returns:
- value from sealed cookie, or null
-
writeCookie
Creates a fresh cookie for a given value (or a placeholder if null to indicate the negative).- Parameters:
value- value or null- Returns:
- true iff the operation succeeded
-
refreshCookie
public boolean refreshCookie()For a non-negative cookie, this recreates the cookie using the current default key to ensure it can continue to be read.- Returns:
- true iff the operation succeeded
-
clearCookie
public void clearCookie()Unset the cookie.
-