@Override
  public void addSecurity(WSSecurityCredential credential) {
    setAction(credential, WSHandlerConstants.USERNAME_TOKEN);

    credential.getRequestPropterties().put(WSHandlerConstants.USER, this.user);
    if (this.encryptedPassword) {
      credential.getRequestPropterties().put(UsernameToken.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    } else {
      credential.getRequestPropterties().put(UsernameToken.PASSWORD_TYPE, WSConstants.PW_TEXT);
    }
    credential.getRequestPropterties().put(WSHandlerConstants.PW_CALLBACK_REF, this);
  }
Ejemplo n.º 2
0
  private <T> void configureWSSecurity(Dispatch<T> dispatch) {
    if (this.mcf.getAsSecurityType() == WSManagedConnectionFactory.SecurityType.WSSecurity) {
      Bus bus = BusFactory.getThreadDefaultBus();
      BusFactory.setThreadDefaultBus(this.mcf.getBus());
      try {
        Client client = ((DispatchImpl) dispatch).getClient();
        Endpoint ep = client.getEndpoint();

        // spring configuration file
        if (this.mcf.getOutInterceptors() != null) {
          for (Interceptor i : this.mcf.getOutInterceptors()) {
            ep.getOutInterceptors().add(i);
          }
        }

        // ws-security pass-thru from custom jaas domain
        Subject subject = ConnectionContext.getSubject();
        if (subject != null) {
          WSSecurityCredential credential =
              ConnectionContext.getSecurityCredential(subject, WSSecurityCredential.class);
          if (credential != null) {
            if (credential.useSts()) {
              dispatch
                  .getRequestContext()
                  .put(SecurityConstants.STS_CLIENT, credential.buildStsClient(bus));
            }
            if (credential.getSecurityHandler() == WSSecurityCredential.SecurityHandler.WSS4J) {
              ep.getOutInterceptors()
                  .add(new WSS4JOutInterceptor(credential.getRequestPropterties()));
              ep.getInInterceptors()
                  .add(new WSS4JInInterceptor(credential.getResponsePropterties()));
            } else if (credential.getSecurityHandler()
                == WSSecurityCredential.SecurityHandler.WSPOLICY) {
              dispatch.getRequestContext().putAll(credential.getRequestPropterties());
              dispatch.getResponseContext().putAll(credential.getResponsePropterties());
            }
          }

          // When properties are set on subject treat them as they can configure WS-Security
          HashMap<String, String> properties =
              ConnectionContext.getSecurityCredential(subject, HashMap.class);
          for (String key : properties.keySet()) {
            if (key.startsWith("ws-security.")) { // $NON-NLS-1$
              ep.put(key, properties.get(key));
            }
          }
        }
      } finally {
        BusFactory.setThreadDefaultBus(bus);
      }
    }
  }