示例#1
0
  /**
   * Secures the SOAP Message response by adding necessary headers to the given SOAP Message and
   * also signs the message if it is required.
   *
   * @param soapMessage SOAP Message that needs to be secured.
   * @param sharedData Any shared data that may be needed between the request and response.
   * @return SOAPMessage Secured SOAP Message by adding liberty headers and also signs the message
   *     if configured.
   * @exception SOAPBindingException for any failure.
   */
  public SOAPMessage secureResponse(SOAPMessage soapMessage, Map sharedData)
      throws SOAPBindingException {

    WSSUtils.debug.message("MessageProcessor.secureResponse : Init");

    try {
      Message req = (Message) sharedData.get(SOAPBindingConstants.LIBERTY_REQUEST);
      addCorrelationHeader(soapMessage, req);

      if (_config.isResponseSignEnabled()) {
        soapMessage = signMessage(soapMessage, null, null);
      }

      if (WSSUtils.debug.messageEnabled()) {
        WSSUtils.debug.message(
            "MessageProcessor.secureResponse: "
                + com.sun.identity.shared.xml.XMLUtils.print(
                    soapMessage.getSOAPPart().getEnvelope()));
      }
      return soapMessage;
    } catch (Exception ex) {
      WSSUtils.debug.error(
          "MessageProcessor.secureResponse: " + "Failed in securing the response", ex);
      throw new SOAPBindingException(WSSUtils.bundle.getString("secureResponseFailed"));
    }
  }
示例#2
0
  /**
   * Validates the SOAP Response from the service and verifies the signature if needed.
   *
   * @param soapMessage SOAPMessage that needs to be validated.
   * @param sharedData Any shared data that may be required between the request and the response.
   * @return SOAPMessage Validated SOAP Response.
   * @exception SOAPBindingException for any failure.
   */
  public SOAPMessage validateResponse(SOAPMessage soapMessage, Map sharedData)
      throws SOAPBindingException {

    try {
      Message msg = new Message(soapMessage);
      if (_config.isResponseSignEnabled() && !SecurityUtils.verifyMessage(msg)) {
        throw new SOAPBindingException(WSSUtils.bundle.getString("cannotVerifySignature"));
      }
      Utils.enforceProcessingRules(msg, null, true);
      return soapMessage;
    } catch (Exception ex) {
      WSSUtils.debug.error(
          "MessageProcessor.validateResponse: " + " Response validation failed.", ex);
      throw new SOAPBindingException(WSSUtils.bundle.getString("validateResponseFailed"));
    }
  }
示例#3
0
  /**
   * This method is used to validate the SOAP Message Request by the processing rules of Liberty
   * SOAPBinding specifications.
   *
   * @param soapMessage SOAPMessage that needs to be validated.
   * @param subject Subject that may be used to populate the authenticated entity/user principal and
   *     any other credential information.
   * @param sharedData that may be used to store any data needed between the request and response.
   * @param httpRequest HttpServletRequest associated with this SOAP Message request.
   * @return Object Credential object after successful validation.
   * @exception SOAPBindingException for any error occured during validation.
   */
  public Object validateRequest(
      SOAPMessage soapMessage, Subject subject, Map sharedData, HttpServletRequest httpRequest)
      throws SOAPBindingException {

    WSSUtils.debug.message("SOAPProvider.validateRequest : Init");
    Message req = null;
    try {
      req = new Message(soapMessage);
      sharedData.put(SOAPBindingConstants.LIBERTY_REQUEST, req);

      if (req.getSecurityProfileType() != Message.ANONYMOUS && !SecurityUtils.verifyMessage(req)) {
        WSSUtils.debug.error(
            "MessageProcessor.validateRequest: Signature" + "Verification failed.");
        throw new SOAPBindingException(WSSUtils.bundle.getString("cannotVerifySignature"));
      }

      Utils.enforceProcessingRules(req, null, true);

      if (_config != null) {
        String authMech = req.getAuthenticationMechanism();
        if (authMech == null || !_config.getSecurityMechanisms().contains(authMech)) {

          throw new SOAPBindingException(WSSUtils.bundle.getString("unsupportedAuthMech"));
        }
      } else {
        throw new SOAPBindingException(WSSUtils.bundle.getString("nullConfiguration"));
      }

      return SOAPRequestHandler.getAuthenticator()
          .authenticate(subject, null, null, _config, req, true);

    } catch (SecurityException se) {

      WSSUtils.debug.error(
          "MessageProcessor.validateRequest: Request" + "Validation has failed.", se);
      throw new SOAPBindingException(se.getMessage());

    } catch (Exception sfe) {

      WSSUtils.debug.error("MessageProcessor.validateRequest: SOAPFault" + "Exception.", sfe);
      throw new SOAPBindingException(sfe.getMessage());
    }
  }