コード例 #1
0
  /**
   * preparing data to send to applet for sign process
   *
   * @param dataFromApplet encoded64 data received from applet certificate choice
   * @return the data to passa to sign applet
   */
  protected void prepareDataToAppletSign() {

    // calcolo impronte documenti selezionati
    SinekartaUtility su = SinekartaUtility.getCurrentInstance();

    try {

      // copio il file per la conversione
      NodeRef folder = su.getNodeService().getPrimaryParent(selectedDocumentNode).getParentRef();

      FileInfo newFile =
          su.getFileFolderService().copy(selectedDocumentNode, folder, documentNamePdf);

      selectedDocumentNodePdf = newFile.getNodeRef();

      // conversione documento in PDF/A
      Action documentToPDFA =
          su.getActionService().createAction(DocumentToPDFA.ACTION_NAME_DOCUMENT_TO_PDFA);
      try {
        su.getActionService().executeAction(documentToPDFA, selectedDocumentNodePdf, false, false);
      } catch (Throwable t) {
        tracer.error("Unable to execute PDF/A conversion : " + t.getMessage(), t);
        throw new SignFailedException("Unable to execute PDF/A conversion : " + t.getMessage(), t);
      }

      Action digitalSignaturePrepareAndAddDocument =
          su.getActionService()
              .createAction(
                  DocumentDigitalSignaturePrepareAndAddDocument
                      .ACTION_NAME_DOCUMENT_DIGITAL_SIGNATURE_PREPARE_AND_ADD_DOCUMENT);
      digitalSignaturePrepareAndAddDocument.setParameterValue(
          DocumentDigitalSignaturePrepareAndAddDocument.PARAM_SIGN_DESCRIPTION, description);
      digitalSignaturePrepareAndAddDocument.setParameterValue(
          DocumentDigitalSignaturePrepareAndAddDocument.PARAM_SIGN_LOCATION,
          Constants.SIGN_LOCATION_ITALY);
      digitalSignaturePrepareAndAddDocument.setParameterValue(
          DocumentDigitalSignaturePrepareAndAddDocument.PARAM_CLIENT_AREA,
          su.getDataFromAppletCertificateChoice());
      try {
        su.getActionService()
            .executeAction(
                digitalSignaturePrepareAndAddDocument, selectedDocumentNodePdf, false, false);
      } catch (Throwable t) {
        tracer.error("Unable to prepare data for document sign : " + t.getMessage(), t);
        throw new SignFailedException(
            "Unable to prepare data for document sign : " + t.getMessage(), t);
      }
      su.setDataToAppletSign(
          (String)
              digitalSignaturePrepareAndAddDocument.getParameterValue(
                  DocumentDigitalSignaturePrepareAndAddDocument.PARAM_RESULT));
    } catch (SignFailedException e) {
      tracer.error(e.getMessage(), e);
      throw e;
    } catch (Exception e) {
      tracer.error("Unable to calculate document fingerprint.", e);
      throw new SignFailedException(
          "Unable to calculate document fingerprint : " + e.getMessage(), e);
    }
  }
コード例 #2
0
  /** this method is called when finish button is pressed applying the sign returned from applet */
  protected String finishImpl(FacesContext context, String outcome) throws Exception {
    SinekartaUtility su = SinekartaUtility.getCurrentInstance();

    // applicao firma ai documenti selezionati

    try {

      // invoking generic sign apply action
      Action documentDigitalSignatureApply =
          su.getActionService()
              .createAction(
                  DocumentDigitalSignatureApply.ACTION_NAME_DOCUMENT_DIGITAL_SIGNATURE_APPLY);
      documentDigitalSignatureApply.setParameterValue(
          DocumentDigitalSignatureApply.PARAM_CLIENT_AREA, su.getDataFromAppletSign());
      try {
        su.getActionService()
            .executeAction(documentDigitalSignatureApply, selectedDocumentNodeParent, false, false);
      } catch (Throwable t) {
        tracer.error("Unable to apply sign to document : " + t.getMessage(), t);
        throw new SignFailedException("Unable to apply sign to document : " + t.getMessage(), t);
      }

      su.getNodeService()
          .setProperty(selectedDocumentNodePdf, ContentModel.PROP_NAME, documentName);

    } catch (SignFailedException e) {
      tracer.error(e.getMessage(), e);
      throw e;
    } catch (Exception e) {
      tracer.error("Unable to apply sign to document : " + e.getMessage(), e);
      throw new SignFailedException("Unable to apply sign to document : " + e.getMessage(), e);
    }

    return outcome;
  }