PublicKey publicKey = null;
byte[] secretKey = null;
String signatureMethod = getSignatureMethod(elem);
REFERENCE_TYPE referenceType = null;
Validator validator = data.getValidator(WSSecurityEngine.SIGNATURE);
if (keyInfoElement == null) {
certs = getDefaultCerts(data.getSigVerCrypto());
principal = certs[0].getSubjectX500Principal();
} else {
int result = 0;
Node node = keyInfoElement.getFirstChild();
Element child = null;
while (node != null) {
if (Node.ELEMENT_NODE == node.getNodeType()) {
result++;
child = (Element)node;
}
node = node.getNextSibling();
}
if (result != 1) {
data.getBSPEnforcer().handleBSPRule(BSPRule.R5402);
}
if (!(SecurityTokenReference.SECURITY_TOKEN_REFERENCE.equals(child.getLocalName())
&& WSConstants.WSSE_NS.equals(child.getNamespaceURI()))) {
data.getBSPEnforcer().handleBSPRule(BSPRule.R5417);
publicKey = parseKeyValue(keyInfoElement);
if (validator != null) {
Credential credential = new Credential();
credential.setPublicKey(publicKey);
principal = new PublicKeyPrincipalImpl(publicKey);
credential.setPrincipal(principal);
validator.validate(credential, data);
}
} else {
STRParser strParser = new SignatureSTRParser();
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put(SignatureSTRParser.SIGNATURE_METHOD, signatureMethod);
strParser.parseSecurityTokenReference(
child, data, wsDocInfo, parameters
);
principal = strParser.getPrincipal();
certs = strParser.getCertificates();
publicKey = strParser.getPublicKey();
secretKey = strParser.getSecretKey();
referenceType = strParser.getCertificatesReferenceType();
boolean trusted = strParser.isTrustedCredential();
if (trusted && LOG.isDebugEnabled()) {
LOG.debug("Direct Trust for SAML/BST credential");
}
if (!trusted && (publicKey != null || certs != null) && validator != null) {
Credential credential = new Credential();
credential.setPublicKey(publicKey);
credential.setCertificates(certs);
credential.setPrincipal(principal);
validator.validate(credential, data);
}
}
}
//