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`

public class EncryptedCookieManager extends AbstractInitializableComponent
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

Fields
Modifier and Type
Field
Description
`private boolean`
`active`
Flags whether the component is active or should no-op.
`private CookieManager`
`cookieManager`
Optional cookie manager to use.
`private String`
`cookieName`
Passwordless cookie name.
`private DataSealer`
`dataSealer`
Optional data sealer to use.
`private final org.slf4j.Logger`
`log`
Class logger.
`static final String`
`NEGATIVE_VALUE`
A negative signal to allow caching opt-out.

## Constructor Summary

Constructors
Constructor
Description
`EncryptedCookieManager()`

## Method Summary

Modifier and Type
Method
Description
`void`
`clearCookie()`
Unset the cookie.
`protected void`
`doInitialize()`
Performs the initialization of the component.
`boolean`
`isOptOut()`
Tests whether the cookie's value indicates a cached negative response.
`String`
`readCookie()`
Read back existing cookie and return the value embedded in it, if any.
`boolean`
`refreshCookie()`
For a non-negative cookie, this recreates the cookie using the current default key to ensure it can continue to be read.
`void`
`setCookieManager(CookieManager manager)`
Sets `CookieManager` to use.
`void`
`setCookieName(String name)`
Set cookie name to use.
`void`
`setDataSealer(DataSealer sealer)`
Sets `DataSealer` to use.
`boolean`
`writeCookie(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`

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

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### NEGATIVE_VALUE

@Nonnull @NotEmpty public static final String NEGATIVE_VALUE
A negative signal to allow caching opt-out.

See Also:
  - Constant Field Values

### log

@Nonnull private final org.slf4j.Logger log
Class logger.

### cookieName

@Nullable @NotEmpty private String cookieName
Passwordless cookie name.

### cookieManager

@Nullable private CookieManager cookieManager
Optional cookie manager to use.

### dataSealer

@Nullable private DataSealer dataSealer
Optional data sealer to use.

### active

private boolean active
Flags whether the component is active or should no-op.

## Constructor Details

### EncryptedCookieManager

public EncryptedCookieManager()

## Method Details

### setCookieName

public void setCookieName(@Nullable String name)
Set cookie name to use.

Parameters:
  `name` - cookie name

### setCookieManager

public void setCookieManager(@Nullable CookieManager manager)
Sets `CookieManager` to use.

Parameters:
  `manager` - cookie manager

### setDataSealer

public void setDataSealer(@Nullable DataSealer sealer)
Sets `DataSealer` to use.

Parameters:
  `sealer` - data sealer

### doInitialize

protected void doInitialize() throws ComponentInitializationException
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:
  `doInitialize` in class `AbstractInitializableComponent`
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

@Nullable @NotEmpty public String 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

public boolean writeCookie(@Nullable String value)
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.