コード例 #1
0
  private String getEncryptedKey() {

    List<WSHandlerResult> results =
        CastUtils.cast(
            (List<?>) message.getExchange().getInMessage().get(WSHandlerConstants.RECV_RESULTS));

    for (WSHandlerResult rResult : results) {
      List<WSSecurityEngineResult> wsSecEngineResults = rResult.getResults();

      for (WSSecurityEngineResult wser : wsSecEngineResults) {
        Integer actInt = (Integer) wser.get(WSSecurityEngineResult.TAG_ACTION);
        String encryptedKeyID = (String) wser.get(WSSecurityEngineResult.TAG_ID);
        if (actInt.intValue() == WSConstants.ENCR
            && encryptedKeyID != null
            && encryptedKeyID.length() != 0) {
          Date created = new Date();
          Date expires = new Date();
          expires.setTime(created.getTime() + 300000);
          SecurityToken tempTok = new SecurityToken(encryptedKeyID, created, expires);
          tempTok.setSecret((byte[]) wser.get(WSSecurityEngineResult.TAG_SECRET));
          tempTok.setSHA1(
              getSHA1((byte[]) wser.get(WSSecurityEngineResult.TAG_ENCRYPTED_EPHEMERAL_KEY)));
          tokenStore.add(tempTok);

          return encryptedKeyID;
        }
      }
    }
    return null;
  }
コード例 #2
0
  private String getUTDerivedKey() throws WSSecurityException {

    List<WSHandlerResult> results =
        CastUtils.cast(
            (List<?>) message.getExchange().getInMessage().get(WSHandlerConstants.RECV_RESULTS));

    for (WSHandlerResult rResult : results) {
      List<WSSecurityEngineResult> wsSecEngineResults = rResult.getResults();

      for (WSSecurityEngineResult wser : wsSecEngineResults) {
        Integer actInt = (Integer) wser.get(WSSecurityEngineResult.TAG_ACTION);
        String utID = (String) wser.get(WSSecurityEngineResult.TAG_ID);
        if (actInt.intValue() == WSConstants.UT_NOPASSWORD) {
          if (utID == null || utID.length() == 0) {
            utID = wssConfig.getIdAllocator().createId("UsernameToken-", null);
          }
          Date created = new Date();
          Date expires = new Date();
          expires.setTime(created.getTime() + 300000);
          SecurityToken tempTok = new SecurityToken(utID, created, expires);

          byte[] secret = (byte[]) wser.get(WSSecurityEngineResult.TAG_SECRET);
          tempTok.setSecret(secret);
          tokenStore.add(tempTok);

          return utID;
        }
      }
    }
    return null;
  }
コード例 #3
0
  public void invoke(MessageContext context) throws Exception {

    context.setProperty("TiempoInicial", new Long(System.currentTimeMillis()));

    Vector result = (Vector) context.getProperty(WSHandlerConstants.RECV_RESULTS);
    for (int i = 0; i < result.size(); i++) {
      WSHandlerResult res = (WSHandlerResult) result.get(i);
      for (int j = 0; j < res.getResults().size(); j++) {
        WSSecurityEngineResult secRes = (WSSecurityEngineResult) res.getResults().get(j);
        int action = secRes.getAction();
        // USER TOKEN
        if ((action & WSConstants.UT) > 0) {
          WSUsernameTokenPrincipal principal = (WSUsernameTokenPrincipal) secRes.getPrincipal();
          // Set user property to user from UT to allow response encryption
          context.setProperty(WSHandlerConstants.ENCRYPTION_USER, principal.getName());
          // System.out.print("User : "******" password : "******"\n");

          SOALocalGISLNWS localGISLNWS = new SOALocalGISLNWS();
          Integer idUsuario =
              localGISLNWS.obtenerUsuario(principal.getName(), principal.getPassword(), context);

          if (idUsuario != null) {
            context.setProperty(WSHandlerConstants.USER, idUsuario);
            localGISLNWS.comprobarPermisoLogin(context);
          }
        }
        // SIGNATURE
        if ((action & WSConstants.SIGN) > 0) {
          X509Certificate cert = secRes.getCertificate();
          X500Name principal = (X500Name) secRes.getPrincipal();
          // Do something whith cert
          System.out.print("Signature for : " + principal.getCommonName());
        }
      }
    }
  }