private static void getUserNameTokenFromMessage(FilterProcessingContext context)
throws XWSSecurityException{
SecurableSoapMessage secureMessage = context.getSecurableSoapMessage();
SecurityHeader wsseSecurity = secureMessage.findSecurityHeader();
UsernameToken token = null;
if(context.getMode() == FilterProcessingContext.ADHOC) {
//AuthenticationTokenPolicy policy = (AuthenticationTokenPolicy)context.getSecurityPolicy();
if ( context.makeDynamicPolicyCallback() ) {
try {
AuthenticationTokenPolicy policy =
((AuthenticationTokenPolicy)context.getSecurityPolicy());
AuthenticationTokenPolicy.UsernameTokenBinding userNamePolicy =
(AuthenticationTokenPolicy.UsernameTokenBinding)policy.getFeatureBinding();
userNamePolicy.isReadOnly(true);
DynamicApplicationContext dynamicContext =
new DynamicApplicationContext(context.getPolicyContext());
dynamicContext.setMessageIdentifier(context.getMessageIdentifier());
dynamicContext.inBoundMessage(true);
DynamicPolicyCallback dynamicCallback =
new DynamicPolicyCallback(userNamePolicy, dynamicContext);
ProcessingContext.copy(dynamicContext.getRuntimeProperties(), context.getExtraneousProperties());
HarnessUtil.makeDynamicPolicyCallback(dynamicCallback,
context.getSecurityEnvironment().getCallbackHandler());
policy.setFeatureBinding((AuthenticationTokenPolicy.UsernameTokenBinding)dynamicCallback.getSecurityPolicy());
//context.setSecurityPolicy(policy);
} catch (Exception e) {
log.log(Level.SEVERE, LogStringsMessages.WSS_1427_ERROR_ADHOC(),e);
throw new XWSSecurityException(e);
}
}
AuthenticationTokenPolicy policy = (AuthenticationTokenPolicy)context.getSecurityPolicy();
NodeList nodeList = wsseSecurity.getElementsByTagNameNS(MessageConstants.WSSE_NS,
MessageConstants.USERNAME_TOKEN_LNAME);
if(nodeList.getLength() <= 0){
log.log(Level.SEVERE, LogStringsMessages.WSS_1400_NOUSERNAME_FOUND());
throw new XWSSecurityException("No Username token found ,Receiver requirement not met");
} else if (nodeList.getLength() > 1) {
log.log(Level.SEVERE, LogStringsMessages.WSS_1401_MORETHANONE_USERNAME_FOUND());
throw new XWSSecurityException(
"More than one Username token found, Receiver requirement not met");
}else{
SOAPElement userNameTokenElement = (SOAPElement)nodeList.item(0);
token = new UsernameToken(userNameTokenElement, policy.isBSP());
token.isBSP(policy.isBSP());
}
}else{
if (context.getMode() == FilterProcessingContext.POSTHOC) {
log.log(Level.SEVERE, LogStringsMessages.WSS_1402_ERROR_POSTHOC());
throw new XWSSecurityException(
"Internal Error: Called UsernameTokenFilter in POSTHOC Mode");
}
try{
token = new UsernameToken(wsseSecurity.getCurrentHeaderElement());
} catch(XWSSecurityException ex) {
log.log(Level.SEVERE, LogStringsMessages.WSS_1403_IMPORT_USERNAME_TOKEN(),ex);
throw SecurableSoapMessage.newSOAPFaultException(
MessageConstants.WSSE_INVALID_SECURITY_TOKEN,
"Exception while importing Username Password Token",
ex);
}
}
String username = token.getUsername();
String password = token.getPassword();
String passwordDigest = token.getPasswordDigest();
String passwordType = token.getPasswordType();
String nonce = token.getNonce();
String created = token.getCreated();
boolean authenticated = false;
if (context.getMode() == FilterProcessingContext.ADHOC) {
AuthenticationTokenPolicy policy = (AuthenticationTokenPolicy)context.getSecurityPolicy();