child = (Element)node;
}
node = node.getNextSibling();
}
if (result != 1) {
throw new WSSecurityException(
WSSecurityException.INVALID_SECURITY, "invalidDataRef"
);
}
if ("KeyIdentifier".equals(child.getLocalName())
&& WSConstants.WSSE_NS.equals(child.getNamespaceURI())) {
String valueType = getKeyIdentifierValueType();
// ValueType cannot be null
if (valueType == null || "".equals(valueType)) {
throw new WSSecurityException(
WSSecurityException.INVALID_SECURITY, "invalidValueType"
);
}
String encodingType = getFirstElement().getAttributeNS(null, "EncodingType");
// Encoding Type must be equal to Base64Binary if it's specified
if (encodingType != null && !"".equals(encodingType)
&& !BinarySecurity.BASE64_ENCODING.equals(encodingType)) {
throw new WSSecurityException(
WSSecurityException.INVALID_SECURITY,
"badEncodingType",
new Object[] {encodingType}
);
}
// Encoding type must be specified other than for a SAML Assertion
if (!WSConstants.WSS_SAML_KI_VALUE_TYPE.equals(valueType)
&& !WSConstants.WSS_SAML2_KI_VALUE_TYPE.equals(valueType)
&& (encodingType == null || "".equals(encodingType))) {
throw new WSSecurityException(
WSSecurityException.INVALID_SECURITY, "noEncodingType"
);
}
} else if ("Embedded".equals(child.getLocalName())) {
result = 0;
node = child.getFirstChild();
while (node != null) {
if (Node.ELEMENT_NODE == node.getNodeType()) {
result++;
// We cannot have a SecurityTokenReference child element
if ("SecurityTokenReference".equals(node.getLocalName())
&& WSConstants.WSSE_NS.equals(node.getNamespaceURI())) {
throw new WSSecurityException(
WSSecurityException.INVALID_SECURITY, "invalidEmbeddedRef"
);
}
}
node = node.getNextSibling();
}
// We can only have one embedded child
if (result != 1) {
throw new WSSecurityException(
WSSecurityException.INVALID_SECURITY, "invalidEmbeddedRef"
);
}
}
}