//String sctPolicyId = sctBinding.getPolicyToken().getTokenId();
String sctPolicyId = sctBinding.getUUID();
//Look for SCT in TokenCache
HashMap tokCache = context.getTokenCache();
SecurityContextTokenImpl sct = null;
sct = (SecurityContextTokenImpl)tokCache.get(sctPolicyId);
boolean tokenInserted = false;
SOAPElement sctElement = null;
IssuedTokenContext ictx = context.getSecureConversationContext();
if (sct == null) {
SecurityContextToken sct1 =(SecurityContextToken)ictx.getSecurityToken();
if (sct1 == null) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1347_NULL_SECURE_CONVERSATION_TOKEN());
throw new XWSSecurityException("SecureConversation Token not Found");
}
sct = new SecurityContextTokenImpl(
secureMessage.getSOAPPart(), sct1.getIdentifier().toString(), sct1.getInstance(), sct1.getWsuId(), sct1.getExtElements());
// put back in token cache
tokCache.put(sctPolicyId, sct);
} else {
tokenInserted = true;
// record the element
sctElement = secureMessage.getElementByWsuId(sct.getWsuId());
}
String sctWsuId = sct.getWsuId();
if (sctWsuId == null) {
sct.setId(secureMessage.generateId());
}
sctWsuId = sct.getWsuId();
String iTokenType = sctBinding.getIncludeToken();
if(sctBinding.INCLUDE_ALWAYS_TO_RECIPIENT.equals(iTokenType) ||
sctBinding.INCLUDE_ALWAYS.equals(iTokenType) ||
sctBinding.INCLUDE_ALWAYS_TO_RECIPIENT_VER2.equals(iTokenType) ||
sctBinding.INCLUDE_ALWAYS_VER2.equals(iTokenType)) {
if (!tokenInserted) {
secureMessage.findOrCreateSecurityHeader().insertHeaderBlock(sct);
// record the element
sctElement = secureMessage.getElementByWsuId(sct.getWsuId());
}
DirectReference reference = new DirectReference();
reference.setURI("#" + sctWsuId);
secTokenRef.setReference(reference);
} else {
// we have to insert SCT Session Id instead of wsuId
DirectReference reference = new DirectReference();
reference.setSCTURI(sct.getIdentifier().toString(), sct.getInstance());
secTokenRef.setReference(reference);
}
return sctElement;
}