Esempio n. 1
0
  /**
   * Invoke a handler. If a fault occurs it will be handled via the <code>handleFault</code> method.
   *
   * @param context The message context.
   */
  public void invoke(MessageContext context) throws Exception {
    UMOEvent event = (UMOEvent) context.getProperty(MuleProperties.MULE_EVENT_PROPERTY);

    if (event == null && context.getClient() != null) {
      event = (UMOEvent) context.getClient().getProperty(MuleProperties.MULE_EVENT_PROPERTY);
    }

    if (event != null) {
      MuleSoapHeaders muleHeaders = new MuleSoapHeaders(event);
      Element header = context.getOutMessage().getHeader();

      if (header == null) {
        header =
            new Element(
                "Header",
                context.getOutMessage().getSoapVersion().getPrefix(),
                context.getOutMessage().getSoapVersion().getNamespace());
      }

      // we can also add some extra properties like
      // Enconding Property, Session Property

      Element muleHeader = null;
      Namespace ns =
          Namespace.getNamespace(MuleSoapHeaders.MULE_NAMESPACE, MuleSoapHeaders.MULE_10_ACTOR);
      if (muleHeaders.getCorrelationId() != null || muleHeaders.getReplyTo() != null) {
        muleHeader = new Element(MuleSoapHeaders.MULE_HEADER, ns);
      } else {
        return;
      }

      Element e = null;
      if (muleHeaders.getCorrelationId() != null) {

        e = new Element(MuleProperties.MULE_CORRELATION_ID_PROPERTY, ns);
        e.setText(muleHeaders.getCorrelationId());
        muleHeader.addContent(e);

        e = new Element(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, ns);
        e.setText(muleHeaders.getCorrelationGroup());
        muleHeader.addContent(e);

        e = new Element(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, ns);
        e.setText(muleHeaders.getCorrelationSequence());
        muleHeader.addContent(e);
      }
      if (muleHeaders.getReplyTo() != null) {

        e = new Element(MuleProperties.MULE_REPLY_TO_PROPERTY, ns);
        e.setText(muleHeaders.getReplyTo());
        muleHeader.addContent(e);
      }
      header.addContent(muleHeader);

      context.getOutMessage().setHeader(header);
    }
  }
Esempio n. 2
0
  public void send(MessageContext context, OutMessage message) throws XFireException {
    if (message.getUri().equals(Channel.BACKCHANNEL_URI)) {
      final OutputStream out = (OutputStream) context.getProperty(Channel.BACKCHANNEL_URI);
      if (out != null) {
        final XMLStreamWriter writer =
            STAXUtils.createXMLStreamWriter(out, message.getEncoding(), context);

        message.getSerializer().writeMessage(message, writer, context);
      } else {
        throw new XFireRuntimeException("No backchannel exists for message");
      }

      try {
        Attachments atts = message.getAttachments();
        if (atts != null && atts.size() > 0) {
          writeAttachmentBody(context, message);
          // TODO response.setContentType(atts.getContentType());
          atts.write(out);
        } else {
          // TODO response.setContentType(getSoapMimeType(message));
          writeWithoutAttachments(context, message, out);
        }
      } catch (IOException e) {
        throw new XFireException("Couldn't send message.", e);
      }
    } else {
      try {
        sendViaClient(context, message);
      } catch (Exception e) {
        throw new XFireException("Failed to Send via MuleUniversalChannel: " + e.getMessage(), e);
      }
    }
  }
  public void invoke(MessageContext context) throws Exception {
    XFireFault fault = (XFireFault) context.getExchange().getFaultMessage().getBody();

    Throwable cause = fault.getCause();
    OperationInfo op = null;

    if (context.getExchange() != null) op = context.getExchange().getOperation();

    if (cause == null || op == null) return;

    FaultInfo faultPart = getFaultForClass(op, cause.getClass());

    if (faultPart != null) {
      handleFault(context, fault, cause, (MessagePartInfo) faultPart.getMessageParts().get(0));
    }
  }
Esempio n. 4
0
  public void invoke(MessageContext context) throws Exception {

    // 为SOAP Header构造验证信息
    Element el = new Element("header");
    context.getOutMessage().setHeader(el);
    Element auth = new Element("AuthenticationToken");
    Element username_el = new Element("Username");
    username_el.addContent(username);
    Element password_el = new Element("Password");
    password_el.addContent(password);
    auth.addContent(username_el);
    auth.addContent(password_el);
    el.addContent(auth);
  }
  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());
        }
      }
    }
  }
Esempio n. 6
0
  public void send(final MessageContext context, final OutMessage message) throws XFireException {
    if (message.getUri().equals(Channel.BACKCHANNEL_URI)) {
      final OutputStream out = (OutputStream) context.getProperty(Channel.BACKCHANNEL_URI);
      if (out != null) {
        final XMLStreamWriter writer =
            STAXUtils.createXMLStreamWriter(out, message.getEncoding(), context);

        message.getSerializer().writeMessage(message, writer, context);
      } else {
        MessageContext oldContext = (MessageContext) context.getProperty(OLD_CONTEXT);

        sendViaNewChannel(context, oldContext, message, (String) context.getProperty(SENDER_URI));
      }
    } else {
      MessageContext receivingContext = new MessageContext();
      receivingContext.setXFire(context.getXFire());
      receivingContext.setService(getService(context.getXFire(), message.getUri()));
      receivingContext.setProperty(OLD_CONTEXT, context);
      receivingContext.setProperty(SENDER_URI, getUri());
      receivingContext.setSession(session);

      sendViaNewChannel(context, receivingContext, message, message.getUri());
    }
  }
Esempio n. 7
0
  /**
   * The method invoke performs the security checks on the soap headers for the incoming message.
   */
  public void invoke(MessageContext msgContext)
      throws SecurityException, XFireFault, WSSecurityException {
    boolean doDebug = log.isDebugEnabled();

    if (doDebug) {
      log.debug("MuleWSSInSecurityHandler: enter invoke()");
    }

    RequestData reqData = new RequestData();

    try {
      reqData.setMsgContext(msgContext);

      Vector actions = new Vector();
      String action = null;

      // the action property in the security header is necessary to know which
      // type of security measure to adopt. It cannot be null.
      if ((action = (String) getOption(WSHandlerConstants.ACTION)) == null) {
        action = getString(WSHandlerConstants.ACTION, msgContext);
      }
      if (action == null) {
        throw new XFireRuntimeException("MuleWSSInHandler: No action defined");
      }

      int doAction = WSSecurityUtil.decodeAction(action, actions);

      String actor = (String) getOption(WSHandlerConstants.ACTOR);

      AbstractMessage sm = msgContext.getCurrentMessage();
      Document doc = (Document) sm.getProperty(DOMInHandler.DOM_MESSAGE);

      if (doc == null)
        throw new XFireRuntimeException("DOMInHandler must be enabled for WS-Security!");

      // Check if it's a response and if its a fault it doesn't continue.
      if (sm.getBody() instanceof XFireFault) return;

      // Get the password using a callback handler
      CallbackHandler cbHandler = null;
      if ((doAction & (WSConstants.ENCR | WSConstants.UT)) != 0) {
        cbHandler = getPasswordCB(reqData);
      }

      // Get and check the parameters pertaining to the signature and
      // encryption actions. Doesn't get SAML properties, though
      doReceiverAction(doAction, reqData);

      // If we're using signed SAML, we need to get the signature file in order
      // to decrypt the SAML token
      if (action.equals(WSHandlerConstants.SAML_TOKEN_SIGNED)) {
        reqData.setSigCrypto(loadSignatureCrypto(reqData));
      }

      Vector wsResult = null;

      // process the security header
      try {
        wsResult =
            secEngine.processSecurityHeader(
                doc, actor, cbHandler, reqData.getSigCrypto(), reqData.getDecCrypto());
      } catch (WSSecurityException ex) {
        throw new XFireFault(
            "MuleWSSInHandler: security processing failed: " + ex.toString(),
            ex,
            XFireFault.SENDER);
      }

      // no security header found we check whether the action was set to
      // "no_security" or else we throw an exception
      if (wsResult == null) {
        if (doAction == WSConstants.NO_SECURITY) {
          return;
        } else {
          throw new XFireFault(
              "MuleWSSInHandler: Request does not contain required Security header",
              XFireFault.SENDER);
        }
      }

      // confim that the signature is valid
      if (reqData.getWssConfig().isEnableSignatureConfirmation()) {
        checkSignatureConfirmation(reqData, wsResult);
      }

      // Extract the signature action result from the action vector
      WSSecurityEngineResult actionResult =
          WSSecurityUtil.fetchActionResult(wsResult, WSConstants.SIGN);

      if (actionResult != null) {
        X509Certificate returnCert = actionResult.getCertificate();

        if (returnCert != null) {
          if (!verifyTrust(returnCert, reqData)) {
            throw new XFireFault(
                "MuleWSSInHandler: The certificate used for the signature is not trusted",
                XFireFault.SENDER);
          }
        }
      }

      if (actions.elementAt(0).equals(new Integer(16))) {
        actions.clear();
        actions.add(new Integer(2));
        actions.add(new Integer(8));
      }

      // now check the security actions: do they match, in right order?
      if (!checkReceiverResults(wsResult, actions)) {
        throw new XFireFault(
            "MuleWSSInHandler: security processing failed (actions mismatch)", XFireFault.SENDER);
      }
      /*
       * Construct and setup the security result structure. The service may
       * fetch this and check it.
       */
      Vector results = null;
      if ((results = (Vector) msgContext.getProperty(WSHandlerConstants.RECV_RESULTS)) == null) {
        results = new Vector();
        msgContext.setProperty(WSHandlerConstants.RECV_RESULTS, results);
      }
      WSHandlerResult rResult = new WSHandlerResult(actor, wsResult);
      results.add(0, rResult);

      if (doDebug) {
        log.debug("MuleWSSInHandler: exit invoke()");
      }
    } catch (WSSecurityException e) {
      throw new WSSecurityException(e.getErrorCode());
    } finally {
      reqData.clear();
      reqData = null;
    }
  }