Package org.wijiscommons.ssaf

Examples of org.wijiscommons.ssaf.ServiceResponseInfo


        HttpServletRequest request = (HttpServletRequest) message
                .get(AbstractHTTPDestination.HTTP_REQUEST);

        // Check the certificate submitted by client
        ServiceResponseInfo sb = SecurityHelperMethods.checkClientCert(request,
                getX509CRLLocation());

        // get input document type
        Element inputDocumentElement = DropOffHelperMethods
                .getInputDocumentType(message);

        String clientsideID = null;
        String recordURI = null;
        String mailBoxURI = null;

        // get the attribute values from inputDocument
        if (inputDocumentElement != null)
        {
            HashMap<String, String> attributesMap = SSAFUtil
                    .getMessageAttributes(inputDocumentElement);
            clientsideID = attributesMap.get("clientsideID");
            recordURI = attributesMap.get("recordURI");
            mailBoxURI = attributesMap.get("dropoffMailBoxURI");
        }
        else
        {
            sb.noteError("Input document did not match with any of excepted types");
            Drop_OffUtil.throwFault(recordURI, clientsideID, null, sb,
                    SSAFErrorTypes.REQUEST_INVALID, mailBoxURI, null);
        }

        // Throw a Fault if cert is invalid
        if (sb.isErrorResponse())
        {
            Drop_OffUtil.throwFault(recordURI, clientsideID, null, sb,
                    SSAFErrorTypes.REQUEST_USER_UNAUTHORIZED, mailBoxURI,
                    inputDocumentElement);
        }
        // go ahead if cert is valid
        else
        {
            X509Certificate certs[] = (X509Certificate[]) request
                    .getAttribute("javax.servlet.request.X509Certificate");

            String dnInCanonicalForm = certs[0].getSubjectX500Principal()
                    .getName("CANONICAL");
            log.info("DN in Cert: " + dnInCanonicalForm);

            X509Name x509NameArgument = new X509Name(dnInCanonicalForm);
            String commonNameInCert = DNUtil.getCommonName(x509NameArgument);
            log.debug("Common Name in Cert: " + commonNameInCert);

            // Check if user is authenticated to MailBox
            sb = Drop_OffUtil.isUserAuthenticated(mailBoxURI, commonNameInCert,
                    authenticateMailBoxURIs);

            if (sb.isErrorResponse())
            {
                sb.noteError("User is not authenticated to use this particular mailbox");
                Drop_OffUtil    .throwFault(
                                recordURI,
                                clientsideID,
                                null,
                                sb, SSAFErrorTypes.REQUEST_USER_UNAUTHORIZED,
View Full Code Here


    if (StringUtils.isBlank(mailBoxURI) && StringUtils.isBlank(commonName))
    {
      throw new IllegalArgumentException(
          "isMailBoxURIValid method arguments passed in should not be null or empty");
    }
    ServiceResponseInfo serviceResponseInfo = new ServiceResponseInfo();

    log.info("Looking for mailBox name in HashMap :" + mailBoxURI
        + " for common name : " + commonName);

    if (mailBoxProperties.containsKey(mailBoxURI))
    {
      HashMap<String, List<String>> mailBoxDetailsHashMap = mailBoxProperties
          .get(mailBoxURI);
     
      if(mailBoxDetailsHashMap.containsKey("certificates"))
      {
        List<String> commonNameList = mailBoxDetailsHashMap.get("certificates");
       
        if (commonNameList.contains(commonName))
        {
          log.info("The Common Name in the Cert was valid for "
                    + mailBoxURI);
          serviceResponseInfo.noteMessage("The Common Name in the Cert was valid for "
                    + mailBoxURI);
          return serviceResponseInfo;
        }
        // if common name is not authorized
        log.error("The common name " + commonName
            + " is not authorized to access mailBoX URI " + mailBoxURI);
        serviceResponseInfo.noteError("The common name " + commonName
            + " is not authorized to access mailBoX URI " + mailBoxURI);
      }
      else
      {
        // if it can not find certificates map
        log.error("Not able to find a map with  name certificates: "
                 + mailBoxURI);
        serviceResponseInfo.noteError("Not able to find a map name certificates : "
                + mailBoxURI);
      }
    }
    else
    {   // if it can not find mailBox name in hashMap
      log.error("Not able to find a mailBox name specified : "
               + mailBoxURI);
      serviceResponseInfo.noteError("Not able to find a mailBox name specified : "
              + mailBoxURI);
    }
    return serviceResponseInfo;
  }
View Full Code Here

    mailBoxProperties = (MailBoxProperties)ac.getBean("mailBoxPropertiesBean");
  }

  public void testIsMailBoxURIValid()
  {
    ServiceResponseInfo serviceResponseInfo = null;
    serviceResponseInfo = mailBoxProperties.isMailBoxURIValid("mailbox1", "lakshmi.doa.wistate.us");
   
    if(serviceResponseInfo.isErrorResponse())
    {
      System.out.println("Error message : "+serviceResponseInfo.getMergedMessages());
      assertEquals("The common name lakshmi.doa.wistate.us   is not authorized to access mailBoX URI mailbox1", serviceResponseInfo.getMergedMessages());
    }
    else
    {
      System.out.println("Success message : "+serviceResponseInfo.getMergedMessages());
      assertEquals("The Common Name in the Cert was valid for mailbox1", serviceResponseInfo.getMergedMessages());
    }
    // lines below are to test if it fails when we give wrong values.
    serviceResponseInfo = mailBoxProperties.isMailBoxURIValid("mailbox", "lakshmi.doa.wistate");
   
    assertTrue(serviceResponseInfo.isErrorResponse());
  }
View Full Code Here

    Element docElement = (Element) dropOffRequestAsync.getAny();

    // Empty element just specifies http 200 status code which represents
    // Standard response for successful HTTP requests.
    Empty empty = new Empty();
    ServiceResponseInfo sb = new ServiceResponseInfo();
    String mailBoxURI = null;
    String clientsideID = null;
    String recordURI = null;

    HashMap<String, String> attributesMap = SSAFUtil
        .getMessageAttributes(docElement);

    clientsideID = attributesMap.get("clientsideID");
    recordURI = attributesMap.get("recordURI");
    mailBoxURI = attributesMap.get("dropoffMailBoxURI");

    String mailBoxAbsolutePath = mailBoxes_root + mailBoxURI;

    // Throw Fault if clientside_Id is not specified
    if (StringUtils.isBlank(clientsideID))
    {
      sb.noteError("clientside_Id attribute is not specified"
          + " in incoming request document");
      Drop_OffUtil.throwFault(recordURI, null, null, sb,
          SSAFErrorTypes.REQUEST_INVALID, mailBoxURI, docElement);

    }
    if (StringUtils.isNotBlank(mailBoxURI))
    {
      boolean fileDropStatus = DropOffHelperMethods.dropOffAFile(
          mailBoxAbsolutePath, docElement, sb, clientsideID,
          recordURI);

      if (!fileDropStatus)
      {
        log.error("Could not dropOff a file at :" + mailBoxAbsolutePath
            + SSAFUtil.fileSeparator + "drop_off"
            + SSAFUtil.fileSeparator + "drop_box");
      }
    }
    else
    {
      // Throw Fault if MailBoxURI is not specified
      sb.noteMessage("mailbox_nominal_uri attribute in incoming request "
          + "document is not specified properly");
      Drop_OffUtil.throwFault(recordURI, null, null, sb,
          SSAFErrorTypes.REQUEST_INVALID, mailBoxURI, docElement);
    }
    return empty;
View Full Code Here

  {
    log.info("Executing checkConfirmation operation");

    CheckConfirmationResponse confirmationResponse = new CheckConfirmationResponse();
    Element docElement = (Element) checkConfirmationRequest.getAny();
    ServiceResponseInfo sb = new ServiceResponseInfo();

    String clientsideID = null;
    String mailBoxURI = null;
    String recordURI = null;
    String messageID = null;
    Element confirmationDocumentElement = null;

    HashMap<String, String> attributesMap = SSAFUtil
        .getMessageAttributes(docElement);
    clientsideID = attributesMap.get("clientsideID");
    mailBoxURI = attributesMap.get("dropoffMailBoxURI");
    recordURI = attributesMap.get("recordURI");
    messageID = attributesMap.get("messageID");

    if (StringUtils.isNotBlank(messageID)
        && StringUtils.isNotBlank(mailBoxURI))
    {
      confirmationDocumentElement = Drop_OffUtil
          .returnConfirmationDocument(messageID,
              mailBoxes_root + mailBoxURI, docElement, sb)
          .getDocumentElement();

      if (confirmationDocumentElement != null)
      {
        confirmationResponse.setAny(confirmationDocumentElement);
        return confirmationResponse;
      }
    }
    else
    {
      // throw FatalFault if message_Id or mailbox_nominal_uri are not
      // specified in incoming request file.
      sb.noteError("message_id or mailbox_nominal_uri attributes in incoming "
              + "request document are not specified properly");
      Drop_OffUtil.throwFault(recordURI, clientsideID, messageID, sb,
          SSAFErrorTypes.REQUEST_INVALID, mailBoxURI, docElement);
    }
View Full Code Here

    log.info("Executing checkDropOffStatus operation");

    CheckDropOffStatusResponse dropOffStatusResponse = new CheckDropOffStatusResponse();
    Element docElement = (Element) checkDropOffStatusRequest.getAny();

    ServiceResponseInfo sb = new ServiceResponseInfo();
    String clientsideID = null;
    String mailBoxURI = null;
    String recordURI = null;

    HashMap<String, String> attributesMap = SSAFUtil
        .getMessageAttributes(docElement);
    clientsideID = attributesMap.get("clientsideID");
    mailBoxURI = attributesMap.get("dropoffMailBoxURI");
    recordURI = attributesMap.get("recordURI");

    if (StringUtils.isNotBlank(clientsideID)
        && StringUtils.isNotBlank(mailBoxURI))
    {
      if (DropOffHelperMethods.checkForDropOffResponse(mailBoxes_root
          + mailBoxURI, clientsideID, recordURI, sb, docElement,
          dropOffStatusResponse))
      {
        // If it can find a error or confirmation file just return.
        return dropOffStatusResponse;
      }
      else
      {
        // throw FatalFault if you are not able to find file with
        // specified clientside_id/message_id in file system.
        sb.noteError("Status Report Not Found with specified clientside_id");
        Drop_OffUtil.throwFault(recordURI, clientsideID, null, sb,
            SSAFErrorTypes.REQUEST_RECORD_ERROR, mailBoxURI,
            docElement);
      }
    }
    else
    { // throw FatalFault if clientside_id or mailbox_nominal_uri
      // attributes are not specified in incoming request file.
      sb.noteError("clientside_id or mailbox_nominal_uri attributes in request"
              + " file are not defined properly");
      Drop_OffUtil.throwFault(recordURI, clientsideID, null, sb,
          SSAFErrorTypes.REQUEST_INVALID, mailBoxURI, docElement);
    }
    return dropOffStatusResponse;
View Full Code Here

    // allow me- so for now I'll go with 20
    String[] messageIDStringArray = new String[20];

    String mailBoxURI = null;
    String recordURI = null;
    ServiceResponseInfo sb = new ServiceResponseInfo();

    // Empty element just specifies http 200 status code which represents
    // Standard response for successful HTTP requests.
    Empty empty = new Empty();

    HashMap<String, String> attributesMap = SSAFUtil
        .getMessageAttributes(docElement);
    mailBoxURI = attributesMap.get("dropoffMailBoxURI");
    recordURI = attributesMap.get("recordURI");

    messageIDsFromRequestFile = docElement.getAttributeNS(
        SSAFNamespaces.ssaf.getNamespace(), SSAFNodes.message_id_list
            .getLocalName());

    if (StringUtils.isNotBlank(messageIDsFromRequestFile)
        && StringUtils.isNotBlank(mailBoxURI))
    {
      // Incoming request file may contain multiple messageIDs which are
      // delimited by space.
      messageIDStringArray = messageIDsFromRequestFile.split(" ");
      log.info("Number of messageIDs in request file  are  : "
          + messageIDStringArray.length);

      for (String messageID : messageIDStringArray)
      {
        File confirmationFileToDelete = Drop_OffUtil
            .lookForConfirmationFileWithMessageID(messageID,
                mailBoxes_root + mailBoxURI, docElement, sb);

        // check if file exists with that name
        if (confirmationFileToDelete != null
            && confirmationFileToDelete.exists())
        {
          if (!DropOffHelperMethods.deleteAFile(
              confirmationFileToDelete, sb))
          {
            // there was error while deleting file from file system
            Drop_OffUtil.throwFault(recordURI, null, messageID, sb,
                    SSAFErrorTypes.NONLOGIC, mailBoxURI,
                    docElement);
          }
        }
        else
        {
          // if confirmationFileToDelete is null- just note down the message_id.
          // In future if you need a list of files which are not deleted use this.
          // At present Bills says it is not required return a list back to client.
          sb.noteMessage("Trying to delete a confirmation file which does'nt exists in a "
                  + "file system - with message_id : "
                  + messageID
                  + " in directory path : "
                  + mailBoxes_root
                  + mailBoxURI
                  + "/drop_off/confirm_box");
          log.info(sb.getMergedMessages());
          // do not throw FatalFault here we need to continue in a loop.
        }
      }
    }
    else
    {
      // throw FatalFault if message_Id or mailbox_nominal_uri are not
      // specified in incoming request file.
      sb.noteMessage("message_id_list or mailbox_nominal_uri attributes in "
              + "request file are not specified properly");
      Drop_OffUtil.throwFault(recordURI, null, null, sb,
          SSAFErrorTypes.REQUEST_INVALID, mailBoxURI, docElement);
    }
    return empty;
View Full Code Here

    String mailBoxURI = null;
    String recordURI = null;
    String clientsideID = null;

    ServiceResponseInfo sb = new ServiceResponseInfo();

    // Empty element just specifies http 200 status code which represents
    // Standard response for successful HTTP requests.
    Empty empty = new Empty();

    HashMap<String, String> attributesMap = SSAFUtil
        .getMessageAttributes(docElement);
    mailBoxURI = attributesMap.get("dropoffMailBoxURI");
    recordURI = attributesMap.get("recordURI");
    clientsideID = attributesMap.get("clientsideID");

    if (StringUtils.isNotBlank(clientsideID)
        && StringUtils.isNotBlank(mailBoxURI))
    {
      String deleteErrorFileLocation = Drop_OffUtil.getFileName(
          mailBoxes_root + mailBoxURI, "fail_box", clientsideID,
          "response");

      File fileToDelete = new File(deleteErrorFileLocation);

      // Check if that file exists or not.
      if (fileToDelete.exists())
      {
        if (DropOffHelperMethods.deleteAFile(fileToDelete, sb))
        {
          log.info("Successfully deleted the a error file with specified clientside_id :"
                  + clientsideID);
        }
        else
        { // not able to delete error file.
          log.error("Not able to delete a error file with specified clientside_id : "
                  + clientsideID);
        }
      }
      else
      {
        // throw FatalFault if you are not able to find a  error file
        // with specified clientside_id in a file system.
        sb.noteError("Trying to delete a error file which does'nt exists in a "
                + "file system with specified clientside_id : "
                + clientsideID);
        Drop_OffUtil.throwFault(recordURI, clientsideID, null, sb,
            SSAFErrorTypes.REQUEST_INVALID, mailBoxURI, docElement);
      }
    }
    else
    {
      // throw FatalFault if message_Id or mailbox_nominal_uri are not
      // specified in incoming request file.
      sb.noteError("clientside_id or mailbox_nominal_uri attributes in request "
              + "file are not specified properly");
      Drop_OffUtil.throwFault(recordURI, clientsideID, null, sb,
          SSAFErrorTypes.REQUEST_INVALID, mailBoxURI, docElement);
    }
    return empty;
View Full Code Here

    {
      throw new IllegalArgumentException("CommonName or mailbox_name or "
          + "authenticateMailBoxURIs injected can not be null");
    }

    ServiceResponseInfo serviceResponseInfo = null;

    serviceResponseInfo = authenticateMailBoxURIs.isMailBoxURIValid(
        mailBox_name, commonNameInCert);

    if (serviceResponseInfo.isErrorResponse())
    {
      log.error("Common name did not match with HashMap");
    }
    return serviceResponseInfo;
  }
View Full Code Here

   */
  public static Document addSamlAssertion(Document dropOffInputDocument,
      String commonNameInCert, String recordURI, String clientsideID,
      String mailBoxURI)
  {
    ServiceResponseInfo sb = new ServiceResponseInfo();
   
    // ssaf:authenticated_user element is a mandatory element in schema,
    // so check for that element and if it is there add saml assertion
    //element if not throw Fault.
   
    NodeList ssafAuthenticatedUserNodeList = dropOffInputDocument
        .getElementsByTagNameNS(
            SSAFNodes.authenticated_user
                .getNamespace(),
            SSAFNodes.authenticated_user
                .getLocalName());
        // check for presence of ssaf:authenticated_user element
    if (ssafAuthenticatedUserNodeList.getLength() > 0)
    {
      NodeList ssafAccountNodeList = dropOffInputDocument
          .getElementsByTagNameNS(SSAFNodes.account
              .getNamespace(), SSAFNodes.account
              .getLocalName());

      if (ssafAccountNodeList.getLength() > 0)
      {
        // as per schema if <ssaf:account> element is there
        // user_nominal_uri attribute should be there -
        // cardinality on that attribute is required.

        Element ssafAccount = (Element) ssafAccountNodeList.item(0);
        String userNominalURI = ssafAccount.getAttributeNS(
            SSAFNodes.user_nominal_uri.getNamespace(),
            SSAFNodes.user_nominal_uri.getLocalName());

        if (StringUtils.isNotBlank(userNominalURI))
        {
          log.info("user_nominal_uri attribute value from <ssaf:account> : "
                  + userNominalURI);
        }
        else
        {
          // throw FatalFault if ssaf:user_nominal_uri is not defined.
          sb.noteError("ssaf:user_nominal_uri attribute in ssaf:account" +
              " is not present in incoming request document");
          log.error(sb.getMergedMessages());
          Drop_OffUtil  .throwFault(
                  recordURI,
                  clientsideID,
                  null,
                  sb, SSAFErrorTypes.REQUEST_USER_UNKNOWN,
                  mailBoxURI, dropOffInputDocument
                      .getDocumentElement());
        }
                // check for presence of ssaf:permission_assertions tag
        NodeList permissionAssertionNodeList = dropOffInputDocument
            .getElementsByTagNameNS(SSAFNodes.permission_assertions
                .getNamespace(),
                SSAFNodes.permission_assertions.getLocalName());

        if (permissionAssertionNodeList.getLength() > 0)
        {
          try
          {
            Node nodeToAppend = dropOffInputDocument.importNode(
                DomUtils.createSamlAssertionDocument(
                    "http://wijiscommons.org",
                    commonNameInCert), true);

            // add saml assertion element
            permissionAssertionNodeList.item(0).appendChild(
                nodeToAppend);
          }
          catch (ParserConfigurationException e)
          {
            // throw FatalFault if there is any problem while
            // adding saml assertion to incoming request
            sb.noteError("Caught ParserConfigurationException while adding a Saml " +
                "Assertion element to incoming document");
            log.error(sb.getMergedMessages());
            Drop_OffUtil  .throwFault(
                    recordURI,
                    clientsideID,
                    null,
                    sb,
                    SSAFErrorTypes.NONLOGIC,
                    mailBoxURI, dropOffInputDocument
                        .getDocumentElement());
          }
        }
        else
        {   // throw FatalFault if ssaf:permission_assertions element is not present
          sb.noteError("ssaf:permission_assertions element is not present" +
              " in incoming request document");
          log.error(sb.getMergedMessages());
          Drop_OffUtil.throwFault(
                  recordURI,
                  clientsideID,
                  null,
                  sb, SSAFErrorTypes.REQUEST_USER_UNKNOWN,
                  mailBoxURI, dropOffInputDocument
                      .getDocumentElement());
        }
      }
      else
      {   // throw FatalFault if ssaf:account element is not present
        sb.noteError("ssaf:account element is not present in incoming request document");
        log.error(sb.getMergedMessages());
        Drop_OffUtil.throwFault(
                recordURI,
                clientsideID,
                null,
                sb, SSAFErrorTypes.REQUEST_USER_UNKNOWN,
                mailBoxURI, dropOffInputDocument
                    .getDocumentElement());
      }
    }
    else
    {
      // throw FatalFault if ssaf:authenticated_user element is not present
      sb.noteError("ssaf:authenticated_user element is not present in incoming request document");
      log.error(sb.getMergedMessages());
      Drop_OffUtil  .throwFault(
              recordURI,
              clientsideID,
              null,
              sb, SSAFErrorTypes.REQUEST_USER_UNKNOWN,
View Full Code Here

TOP

Related Classes of org.wijiscommons.ssaf.ServiceResponseInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.