requestData.setWssConfig(WSSConfig.getNewInstance());
requestData.setCallbackHandler(callbackHandler);
requestData.setMsgContext(tokenParameters.getWebServiceContext().getMessageContext());
TokenValidatorResponse response = new TokenValidatorResponse();
ReceivedToken validateTarget = tokenParameters.getToken();
validateTarget.setState(STATE.INVALID);
response.setToken(validateTarget);
if (!validateTarget.isBinarySecurityToken()) {
return response;
}
BinarySecurityTokenType binarySecurityType = (BinarySecurityTokenType)validateTarget.getToken();
// Test the encoding type
String encodingType = binarySecurityType.getEncodingType();
if (!BASE64_ENCODING.equals(encodingType)) {
LOG.fine("Bad encoding type attribute specified: " + encodingType);
return response;
}
//
// Turn the received JAXB object into a DOM element
//
Document doc = DOMUtils.createDocument();
BinarySecurity binarySecurity = new X509Security(doc);
binarySecurity.setEncodingType(encodingType);
binarySecurity.setValueType(binarySecurityType.getValueType());
String data = binarySecurityType.getValue();
((Text)binarySecurity.getElement().getFirstChild()).setData(data);
//
// Validate the token
//
try {
Credential credential = new Credential();
credential.setBinarySecurityToken(binarySecurity);
if (sigCrypto != null) {
X509Certificate cert = ((X509Security)binarySecurity).getX509Certificate(sigCrypto);
credential.setCertificates(new X509Certificate[]{cert});
}
Credential returnedCredential = validator.validate(credential, requestData);
response.setPrincipal(returnedCredential.getCertificates()[0].getSubjectX500Principal());
validateTarget.setState(STATE.VALID);
} catch (WSSecurityException ex) {
LOG.log(Level.WARNING, "", ex);
}
return response;
}