SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
SecureConversationToken conversationToken = new SecureConversationToken(consts);
conversationToken.setOptional(PolicyConstants.isOptional(element));
String attribute = DOMUtils.getAttribute(element, consts.getIncludeToken());
if (attribute == null) {
throw new IllegalArgumentException("SecurityContextToken doesn't contain "
+ "any sp:IncludeToken attribute");
}
String inclusionValue = attribute.trim();
conversationToken.setInclusion(consts.getInclusionFromAttributeValue(inclusionValue));
Element elem = DOMUtils.getFirstElement(element);
while (elem != null) {
QName qn = DOMUtils.getElementQName(elem);
if (PolicyConstants.isPolicyElem(qn)) {
if (DOMUtils.getFirstChildWithName(elem,
consts.getNamespace(),
SPConstants.REQUIRE_DERIVED_KEYS) != null) {
conversationToken.setDerivedKeys(true);
} else if (DOMUtils.getFirstChildWithName(elem,
SP12Constants
.REQUIRE_IMPLIED_DERIVED_KEYS)
!= null) {
conversationToken.setImpliedDerivedKeys(true);
} else if (DOMUtils.getFirstChildWithName(elem,
SP12Constants
.REQUIRE_EXPLICIT_DERIVED_KEYS)
!= null) {
conversationToken.setExplicitDerivedKeys(true);
}
if (DOMUtils.getFirstChildWithName(elem,
consts.getNamespace(),
SPConstants.REQUIRE_EXTERNAL_URI_REFERENCE) != null) {
conversationToken.setRequireExternalUriRef(true);
}
if (DOMUtils.getFirstChildWithName(elem,
consts.getNamespace(),
SPConstants.SC10_SECURITY_CONTEXT_TOKEN) != null) {
conversationToken.setSc10SecurityContextToken(true);
}
Element bootstrapPolicyElement = DOMUtils.getFirstChildWithName(elem,
consts.getNamespace(),
SPConstants.BOOTSTRAP_POLICY);
if (bootstrapPolicyElement != null) {
Policy policy = builder.getPolicy(DOMUtils.getFirstElement(bootstrapPolicyElement));
conversationToken.setBootstrapPolicy(policy);
}
} else if (consts.getNamespace().equals(qn.getNamespaceURI())
&& SPConstants.ISSUER.equals(qn.getLocalPart())) {
conversationToken.setIssuerEpr(DOMUtils.getFirstElement(elem));
}
elem = DOMUtils.getNextElement(elem);
}
return conversationToken;