Class AbstractDynamicPropertyKey<T>
java.lang.Object
com.broadleafcommerce.auth.user.autoconfigure.support.keys.AbstractDynamicPropertyKey<T>
- Direct Known Subclasses:
DynamicPropertyPrivateKey
,DynamicPropertyPublicKey
Properties can be updated at runtime (ex: from Broadleaf Config Server), and therefore it is
important that all components who need a particular signing/verification key are using an
instance that matches the latest property value for that key.
Extensions of this are intended to be special 'smart key' beans that will always present the latest key based on the latest property value for that key. The only exception is when this key is used multiple times in a request lifecycle - in that case, the 'latest' value is computed in the first use of this key, and then that value is used for the remainder of that request's lifecycle.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract boolean
atomicSetKeyInRequestContextIfUnset
(T key, DynamicPropertyKeysRequestContext requestContext) Implementations must be atomic and only set the given key instance value in the request context if unset.protected abstract T
constructKeyInstance
(String rawKeyValue) protected T
protected Optional<DynamicPropertyKeysRequestContext>
Return the request scoped keys context bean.protected abstract T
getExistingKeyFromRequestContext
(DynamicPropertyKeysRequestContext requestContext) protected abstract String
protected abstract org.slf4j.Logger
getLog()
protected T
getOrComputeKeyFromRequestContext
(DynamicPropertyKeysRequestContext requestContext) Gets the existing value from the request context, or computes it newly and initializes it in the request context.protected T
We use the raw latest property value from the environment as a map-key into the single-member cache.void
setDynamicPropertyKeysRequestContext
(DynamicPropertyKeysRequestContext keysRequestContext)
-
Constructor Details
-
AbstractDynamicPropertyKey
public AbstractDynamicPropertyKey()
-
-
Method Details
-
setDynamicPropertyKeysRequestContext
@Autowired(required=false) public void setDynamicPropertyKeysRequestContext(DynamicPropertyKeysRequestContext keysRequestContext) -
getDynamicPropertyKeysRequestContext
Return the request scoped keys context bean. If not in a request scope,Optional.empty()
is returned.- Returns:
- an
Optional
containing thekeysRequestContext
if in a request scope.
-
getLog
protected abstract org.slf4j.Logger getLog()- Returns:
- the logger that should be used for log messages
-
getDelegate
- Returns:
- the actual delegate key instance that should be used for all the key-related method calls (such as those from the underlying key interface)
-
getOrComputeKeyFromRequestContext
Gets the existing value from the request context, or computes it newly and initializes it in the request context.- Parameters:
requestContext
- the request context state to get/initialize the value from/in- Returns:
- the existing or newly computed key instance in the request context
-
getExistingKeyFromRequestContext
@Nullable protected abstract T getExistingKeyFromRequestContext(DynamicPropertyKeysRequestContext requestContext) - Parameters:
requestContext
- the request context from which to get the existing key instance- Returns:
- the existing key instance in the request context, or
null
if none is set
-
atomicSetKeyInRequestContextIfUnset
protected abstract boolean atomicSetKeyInRequestContextIfUnset(T key, DynamicPropertyKeysRequestContext requestContext) Implementations must be atomic and only set the given key instance value in the request context if unset.Recommended to use
AtomicReference.compareAndSet(Object, Object)
semantics.- Parameters:
key
- the key value to set in the request contextrequestContext
- the request context in which to set the value- Returns:
- true if the update succeeded (only set if unset), false otherwise
-
getOrComputeLatestKeyFromProperties
We use the raw latest property value from the environment as a map-key into the single-member cache.If the existing property value map-key in the cache does not match the latest property value, there will be a cache miss and replacement will occur.
- Returns:
- a key instance matching the latest property value
-
getLatestPropertyValueForKey
- Returns:
- the raw latest property value from the environment for the key
-
constructKeyInstance
- Parameters:
rawKeyValue
- the raw key value to construct the key instance from- Returns:
- the constructed key instance
-