public Assertion build(Element element, AssertionBuilderFactory factory) {
SPConstants consts = MS_NS.equals(element.getNamespaceURI())
? SP11Constants.INSTANCE : SP12Constants.INSTANCE;
KeyValueToken token = new KeyValueToken(consts);
token.setOptional(PolicyConstants.isOptional(element));
token.setIgnorable(PolicyConstants.isIgnorable(element));
String attribute = element.getAttributeNS(element.getNamespaceURI(), SPConstants.ATTR_INCLUDE_TOKEN);
if (StringUtils.isEmpty(attribute)) {
attribute = element.getAttributeNS(consts.getNamespace(), SPConstants.ATTR_INCLUDE_TOKEN);
}
if (StringUtils.isEmpty(attribute)) {
attribute = element.getAttributeNS(SP11Constants.INSTANCE.getNamespace(),
SPConstants.ATTR_INCLUDE_TOKEN);
}
if (!StringUtils.isEmpty(attribute)) {
token.setInclusion(consts.getInclusionFromAttributeValue(attribute));
}
Element polEl = PolicyConstants.findPolicyElement(element);
if (polEl == null) {
throw new IllegalArgumentException(
"sp:KeyValueToken/wsp:Policy must have a value"
);
}
token.setPolicy(polEl);
Element child = DOMUtils.getFirstElement(polEl);
if (child != null) {
QName qname = new QName(child.getNamespaceURI(), child.getLocalName());
if ("RsaKeyValue".equals(qname.getLocalPart())) {
token.setForceRsaKeyValue(true);
}
}
return token;
}