}
public Assertion build(Element element, AssertionBuilderFactory factory)
throws IllegalArgumentException {
SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
SecureConversationToken conversationToken = new SecureConversationToken(consts);
conversationToken.setOptional(PolicyConstants.isOptional(element));
conversationToken.setIgnorable(PolicyConstants.isIgnorable(element));
String attribute = DOMUtils.getAttribute(element, consts.getIncludeToken());
if (attribute != null) {
conversationToken.setInclusion(consts.getInclusionFromAttributeValue(attribute.trim()));
}
Element elem = DOMUtils.getFirstElement(element);
boolean foundPolicy = false;
while (elem != null) {
QName qn = DOMUtils.getElementQName(elem);
if (Constants.isPolicyElement(qn)) {
foundPolicy = true;
conversationToken.setPolicy(elem);
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);
}
if (DOMUtils.getFirstChildWithName(elem,
consts.getNamespace(),
SPConstants.SC13_SECURITY_CONTEXT_TOKEN) != null) {
conversationToken.setSc13SecurityContextToken(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);
}