public Assertion build(Element element, AssertionBuilderFactory factory)
throws IllegalArgumentException {
SPConstants consts = SP11Constants.SP_NS.equals(element.getNamespaceURI())
? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
X509Token x509Token = new X509Token(consts);
x509Token.setOptional(PolicyConstants.isOptional(element));
x509Token.setIgnorable(PolicyConstants.isIgnorable(element));
Element policyElement = DOMUtils.getFirstElement(element);
if (policyElement == null && consts != SP11Constants.INSTANCE) {
throw new IllegalArgumentException(
"sp:X509Token/wsp:Policy must have a value"
);
}
// Process token inclusion
String includeAttr = DOMUtils.getAttribute(element, consts.getIncludeToken());
if (includeAttr != null) {
SPConstants.IncludeTokenType inclusion
= consts.getInclusionFromAttributeValue(includeAttr);
x509Token.setInclusion(inclusion);
}
if (policyElement != null) {
if (DOMUtils.getFirstChildWithName(policyElement, consts.getRequiredDerivedKeys()) != null) {
x509Token.setDerivedKeys(true);
} else if (DOMUtils.getFirstChildWithName(policyElement,
SP12Constants.REQUIRE_IMPLIED_DERIVED_KEYS) != null) {
x509Token.setImpliedDerivedKeys(true);
} else if (DOMUtils.getFirstChildWithName(policyElement,
SP12Constants.REQUIRE_EXPLICIT_DERIVED_KEYS) != null) {
x509Token.setExplicitDerivedKeys(true);
}
}
Policy policy = builder.getPolicy(DOMUtils.getFirstElement(element));
policy = policy.normalize(builder.getPolicyRegistry(), false);