public List<WSSecurityEngineResult> handleToken(
Element elem,
RequestData data,
WSDocInfo wsDocInfo
) throws WSSecurityException {
SecurityContextToken sct = new SecurityContextToken(elem);
Validator validator =
data.getValidator(new QName(elem.getNamespaceURI(), elem.getLocalName()));
WSSecurityEngineResult result =
new WSSecurityEngineResult(WSConstants.SCT, sct);
if (validator != null) {
// Hook to allow the user to validate the SecurityContextToken
Credential credential = new Credential();
credential.setSecurityContextToken(sct);
Credential returnedCredential = validator.validate(credential, data);
result.put(WSSecurityEngineResult.TAG_VALIDATED_TOKEN, Boolean.TRUE);
String tokenId = sct.getID();
if (!"".equals(tokenId)) {
result.put(WSSecurityEngineResult.TAG_ID, tokenId);
}
result.put(WSSecurityEngineResult.TAG_SECRET, returnedCredential.getSecretKey());
} else {
String id = sct.getID();
if (!"".equals(id) && id.charAt(0) == '#') {
id = id.substring(1);
}
byte[] secret = null;
try {
secret = getSecret(data.getCallbackHandler(), sct.getIdentifier());
} catch (WSSecurityException ex) {
secret = getSecret(data.getCallbackHandler(), id);
}
if (secret == null || secret.length == 0) {
secret = getSecret(data.getCallbackHandler(), id);
}
result.put(WSSecurityEngineResult.TAG_ID, sct.getID());
result.put(WSSecurityEngineResult.TAG_SECRET, secret);
}
wsDocInfo.addTokenElement(elem);
wsDocInfo.addResult(result);