/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions Copyrighted [year] [name of copyright owner]".
*
* Copyright 2015 ForgeRock AS.
*/
/**
* @see STSInstanceStateProvider
* Base class for providing the TokenGenerationService with STSInstanceState subclasses corresponding to published rest or
* soap sts instance state.
* Caches state pulled from the persistent store for performance. Registers a ServiceListener in the ctor so that
* cache entries can be invalidated when the corresponding service is updated.
*/
public abstract class STSInstanceStateProviderBase<S extends STSInstanceConfig, T extends STSInstanceState> implements STSInstanceStateProvider<T> {
cachedRestInstanceConfigState = new ConcurrentHashMap<>();
this.serviceName = serviceName;
/*
Add the ServiceListener when the caching layer is initialized - i.e. in this ctor.
*/
try {
logger.debug("In STSInstanceStateProviderBase ctor, successfully added ServiceListener for service "
+ serviceName);
} catch (STSInitializationException e) {
" ServiceListener in the STSInstanceStateProviderBase: " + e;
}
}
public T getSTSInstanceState(String instanceId, String realm) throws TokenCreationException, STSPublishException {
/*
The instanceId can include upper-case characters. Yet the id of the rest-sts instance, as indicated to registered
ServiceListeners, is all lower-case. So the entry in the map should be always be lower-case.
*/
if (cachedState == null) {
if ((concurrentlyCreatedState = cachedRestInstanceConfigState.putIfAbsent(lowerCaseInstanceId, createdState)) != null) {
return concurrentlyCreatedState;
} else {
return createdState;
}
} else {
return cachedState;
}
}
" instance state for instance " + instanceId);
}
}
private T createSTSInstanceState(String instanceId, String realm) throws TokenCreationException, STSPublishException {
return instanceStateFactory.createSTSInstanceState(stsInstanceConfigStore.getSTSInstanceConfig(instanceId, realm));
}
}
}