boolean enableAppliesTo
) throws Exception {
if (issuedToken == null) {
return;
}
TokenStore tokenStore = getTokenStore(message);
String key = appliesTo;
if (!enableAppliesTo || key == null || "".equals(key)) {
key = ASSOCIATED_TOKEN;
}
if (onBehalfOfToken != null) {
String id = getIdFromToken(onBehalfOfToken);
SecurityToken cachedToken = tokenStore.getToken(id);
if (cachedToken == null) {
cachedToken = new SecurityToken(id);
cachedToken.setToken(onBehalfOfToken);
}
Properties properties = cachedToken.getProperties();
if (properties == null) {
properties = new Properties();
cachedToken.setProperties(properties);
}
properties.put(key, issuedToken.getId());
tokenStore.add(cachedToken);
}
if (actAsToken != null) {
String id = getIdFromToken(actAsToken);
SecurityToken cachedToken = tokenStore.getToken(id);
if (cachedToken == null) {
cachedToken = new SecurityToken(id);
cachedToken.setToken(actAsToken);
}
Properties properties = cachedToken.getProperties();
if (properties == null) {
properties = new Properties();
cachedToken.setProperties(properties);
}
properties.put(key, issuedToken.getId());
tokenStore.add(cachedToken);
}
}