protected WSSecUsernameToken addUsernameToken(SoapMessage message, UsernameToken token) {
    String userName = (String) message.getContextualProperty(SecurityConstants.USERNAME);
    WSSConfig wssConfig = (WSSConfig) message.getContextualProperty(WSSConfig.class.getName());
    if (wssConfig == null) {
      wssConfig = WSSConfig.getNewInstance();
    }

    if (!StringUtils.isEmpty(userName)) {
      // If NoPassword property is set we don't need to set the password
      if (token.getPasswordType() == UsernameToken.PasswordType.NoPassword) {
        WSSecUsernameToken utBuilder = new WSSecUsernameToken(wssConfig);
        utBuilder.setUserInfo(userName, null);
        utBuilder.setPasswordType(null);
        return utBuilder;
      }

      String password = (String) message.getContextualProperty(SecurityConstants.PASSWORD);
      if (StringUtils.isEmpty(password)) {
        password = getPassword(userName, token, WSPasswordCallback.USERNAME_TOKEN, message);
      }

      if (!StringUtils.isEmpty(password)) {
        // If the password is available then build the token
        WSSecUsernameToken utBuilder = new WSSecUsernameToken(wssConfig);
        if (token.getPasswordType() == UsernameToken.PasswordType.HashPassword) {
          utBuilder.setPasswordType(WSConstants.PASSWORD_DIGEST);
        } else {
          utBuilder.setPasswordType(WSConstants.PASSWORD_TEXT);
        }

        utBuilder.setUserInfo(userName, password);
        return utBuilder;
      } else {
        policyNotAsserted(token, "No username available", message);
      }
    } else {
      policyNotAsserted(token, "No username available", message);
    }
    return null;
  }
 private void handleAddressing(SoapMessage message) {
   final AddressingProperties maps =
       (AddressingProperties)
           message.getContextualProperty(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND);
   if (maps == null) {
     return;
   }
   final EndpointReferenceType rpl = maps.getReplyTo();
   if (rpl == null) {
     return;
   }
   final AttributedURIType addr = rpl.getAddress();
   if (addr == null) {
     return;
   }
   final String replyTo = addr.getValue();
   final Exchange exchange = message.getExchange();
   if (exchange.getDestination() instanceof JMSDestination) {
     ContextUtils.storePartialResponseSent(message);
     if (!exchange.isOneWay()) {
       exchange.setOneWay(true);
     }
   } else {
     if (exchange.isOneWay()) {
       if (!Names.WSA_NONE_ADDRESS.equals(replyTo)) {
         // disable creation of "partial" response
         // by CXF decoupled response feature
         exchange.setOneWay(false);
       }
     } else {
       // A generic default exchange has been created.
       // Provide it to MAP aggregator as anon. request-response
       // and convert it afterwards to one-way.
       if (Names.WSA_NONE_ADDRESS.equals(replyTo)) {
         addr.setValue(Names.WSA_ANONYMOUS_ADDRESS);
       }
     }
   }
 }
 protected boolean isWsiBSPCompliant(final SoapMessage message) {
   String bspc = (String) message.getContextualProperty(SecurityConstants.IS_BSP_COMPLIANT);
   // Default to WSI-BSP compliance enabled
   return !("false".equals(bspc) || "0".equals(bspc));
 }