@Override
public InboundSecurityToken validate(final AbstractSecurityContextTokenType securityContextTokenType,
final String identifier, final TokenContext tokenContext)
throws WSSecurityException {
AbstractInboundSecurityToken securityContextToken = new AbstractInboundSecurityToken(
tokenContext.getWsSecurityContext(), identifier,
WSSecurityTokenConstants.KeyIdentifier_ExternalReference, true) {
@Override
public boolean isAsymmetric() {
return false;
}
@Override
public Key getKey(String algorithmURI, XMLSecurityConstants.AlgorithmUsage algorithmUsage,
String correlationID) throws XMLSecurityException {
Key key = getSecretKey().get(algorithmURI);
if (key != null) {
return key;
}
WSPasswordCallback passwordCallback = new WSPasswordCallback(
identifier, WSPasswordCallback.Usage.SECURITY_CONTEXT_TOKEN);
WSSUtils.doSecretKeyCallback(
tokenContext.getWssSecurityProperties().getCallbackHandler(), passwordCallback, null);
if (passwordCallback.getKey() == null) {
throw new WSSecurityException(WSSecurityException.ErrorCode.SECURITY_TOKEN_UNAVAILABLE,
"noKey", securityContextTokenType.getId());
}
String keyAlgorithm = JCEMapper.getJCEKeyAlgorithmFromURI(algorithmURI);
key = new SecretKeySpec(passwordCallback.getKey(), keyAlgorithm);
setSecretKey(algorithmURI, key);
return key;
}
@Override
public WSSecurityTokenConstants.TokenType getTokenType() {
return WSSecurityTokenConstants.SecurityContextToken;
}
};
securityContextToken.setElementPath(tokenContext.getElementPath());
securityContextToken.setXMLSecEvent(tokenContext.getFirstXMLSecEvent());
return securityContextToken;
}