public Assertion build(Element element, AssertionBuilderFactory factory)
throws IllegalArgumentException {
SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
SpnegoContextToken spnegoContextToken = new SpnegoContextToken(consts);
spnegoContextToken.setOptional(PolicyConstants.isOptional(element));
spnegoContextToken.setIgnorable(PolicyConstants.isIgnorable(element));
String attribute = DOMUtils.getAttribute(element, consts.getIncludeToken());
if (attribute == null) {
throw new IllegalArgumentException("SpnegoContextToken doesn't contain "
+ "any sp:IncludeToken attribute");
}
String inclusionValue = attribute.trim();
spnegoContextToken.setInclusion(consts.getInclusionFromAttributeValue(inclusionValue));
Element elem = DOMUtils.getFirstElement(element);
while (elem != null) {
QName qn = DOMUtils.getElementQName(elem);
if (Constants.isPolicyElement(qn)) {
if (DOMUtils.getFirstChildWithName(elem, consts.getNamespace(),
SPConstants.REQUIRE_DERIVED_KEYS) != null) {
spnegoContextToken.setDerivedKeys(true);
} else if (DOMUtils.getFirstChildWithName(elem,
SP12Constants.REQUIRE_IMPLIED_DERIVED_KEYS) != null) {
spnegoContextToken.setImpliedDerivedKeys(true);
} else if (DOMUtils.getFirstChildWithName(elem,
SP12Constants.REQUIRE_EXPLICIT_DERIVED_KEYS) != null) {
spnegoContextToken.setExplicitDerivedKeys(true);
}
} else if (consts.getNamespace().equals(qn.getNamespaceURI())
&& SPConstants.ISSUER.equals(qn.getLocalPart())) {
spnegoContextToken.setIssuerEpr(DOMUtils.getFirstElement(elem));
}
elem = DOMUtils.getNextElement(elem);
}
return spnegoContextToken;
}