pdf/src/main/java/se/idsec/signservice/integration/document/pdf/PdfTbsDocumentProcessor.java
@Override
  public ProcessedTbsDocument preProcess(final TbsDocument document, final SignRequestInput signRequestInput,
      final IntegrationServiceConfiguration config, final DocumentCache documentCache, final String fieldName)
      throws InputValidationException {

    final ProcessedTbsDocument processedTbsDocument = super.preProcess(document, signRequestInput, config, documentCache, fieldName);
    final TbsDocument tbsDocument = processedTbsDocument.getTbsDocument();

    if (tbsDocument.getVisiblePdfSignatureRequirement() == null) {
      if (config.getDefaultVisiblePdfSignatureRequirement() != null) {
        log.debug("{}: Setting default value for visiblePdfSignatureRequirement ({}): {}",
          CorrelationID.id(), tbsDocument.getId(), config.getDefaultVisiblePdfSignatureRequirement());
        tbsDocument.setVisiblePdfSignatureRequirement(config.getDefaultVisiblePdfSignatureRequirement());
      }
    }
    else {

      // Is this a "null" request. If so, remove it ...
      //
      if (Boolean.valueOf(tbsDocument.getVisiblePdfSignatureRequirement()
        .getExtensionValue(VisiblePdfSignatureRequirement.NULL_INDICATOR_EXTENSION))) {

        log.debug("{}: Document '{}' contains a null requirement, removing ...",
          CorrelationID.id(), tbsDocument.getId());
        tbsDocument.setVisiblePdfSignatureRequirement(null);
      }
      else {
        // Validate the input ...
        //
        this.visiblePdfSignatureRequirementValidator.validateObject(
          tbsDocument.getVisiblePdfSignatureRequirement(), fieldName + ".visiblePdfSignatureRequirement", config);

        // Scale ...
        //
        if (tbsDocument.getVisiblePdfSignatureRequirement().getScale() == null) {
          log.info("{}: visiblePdfSignatureRequirement.scale is not set, defaulting to 0", CorrelationID.id());
          tbsDocument.getVisiblePdfSignatureRequirement().setScale(0);
        }
        else if (tbsDocument.getVisiblePdfSignatureRequirement().getScale().intValue() < -100) {
          log.info("{}: visiblePdfSignatureRequirement.scale is set to '{}'. This is illegal, changing to -100",
            CorrelationID.id(), tbsDocument.getVisiblePdfSignatureRequirement().getScale());
          tbsDocument.getVisiblePdfSignatureRequirement().setScale(-100);
        }

        // Page ...
        //
        if (tbsDocument.getVisiblePdfSignatureRequirement().getPage() == null) {
          log.info("{}: visiblePdfSignatureRequirement.page is not set, defaulting to 0", CorrelationID.id());
          tbsDocument.getVisiblePdfSignatureRequirement().setPage(0);
        }
        if (tbsDocument.getVisiblePdfSignatureRequirement().getPage().intValue() < 0) {
          log.info("{}: visiblePdfSignatureRequirement.page is set to '{}'. This is illegal, changing to 0",
            CorrelationID.id(), tbsDocument.getVisiblePdfSignatureRequirement().getPage());
          tbsDocument.getVisiblePdfSignatureRequirement().setPage(0);
        }
      }
    }

    // AdES requirements ...
    //
    final EtsiAdesRequirement requestedAdes = tbsDocument.getAdesRequirement();
    final AdesProfileType ades = PDFIntegrationUtils.getPadesRequirement(requestedAdes);
    tbsDocument.addExtensionValue(PDFExtensionParams.adesRequirement.name(), ades.getStringValue());

    // Visible PDF signature requirements ...
    //
    final VisiblePdfSignatureRequirement visiblePdfSignatureRequirement = tbsDocument.getVisiblePdfSignatureRequirement();
    if (visiblePdfSignatureRequirement != null) {
      final VisibleSignatureImageFactory factory = new VisibleSignatureImageFactory(config.getPdfSignatureImageTemplates());
      try {
        final String encodedVisibleSignImage = factory.getEncodedVisibleSignImage(
          visiblePdfSignatureRequirement, signRequestInput.getAuthnRequirements().getRequestedSignerAttributes());
        tbsDocument.addExtensionValue(PDFExtensionParams.visibleSignImage.name(), encodedVisibleSignImage);
      }
      catch (VisiblePdfSignatureRequirementException e) {
        throw new InputValidationException(fieldName + ".visiblePdfSignatureRequirement", e.getMessage(), e);
      }
    }

    return processedTbsDocument;
  }
/**
   * Handles settings for PDF visible signatures.
   */
Handles settings for PDF visible signatures.
Handles settings for PDF visible signatures .
@Override
  public ProcessedTbsDocument preProcess(final TbsDocument document, final SignRequestInput signRequestInput,
      final IntegrationServiceConfiguration config, final DocumentCache documentCache, final String fieldName)
      throws InputValidationException {
    final ProcessedTbsDocument processedTbsDocument = super.preProcess(document, signRequestInput, config, documentCache, fieldName);
    final TbsDocument tbsDocument = processedTbsDocument.getTbsDocument();
    if (tbsDocument.getVisiblePdfSignatureRequirement() == null) {
      if (config.getDefaultVisiblePdfSignatureRequirement() != null) {
        log.debug("{}: Setting default value for visiblePdfSignatureRequirement ({}): {}",
          CorrelationID.id(), tbsDocument.getId(), config.getDefaultVisiblePdfSignatureRequirement());
        tbsDocument.setVisiblePdfSignatureRequirement(config.getDefaultVisiblePdfSignatureRequirement());
      }
    }
    else {
      if (Boolean.valueOf(tbsDocument.getVisiblePdfSignatureRequirement()
        .getExtensionValue(VisiblePdfSignatureRequirement.NULL_INDICATOR_EXTENSION))) {
        log.debug("{}: Document '{}' contains a null requirement, removing ...",
          CorrelationID.id(), tbsDocument.getId());
        tbsDocument.setVisiblePdfSignatureRequirement(null);
      }
      else {
         Validate the input ...
        this.visiblePdfSignatureRequirementValidator.validateObject(
          tbsDocument.getVisiblePdfSignatureRequirement(), fieldName + ".visiblePdfSignatureRequirement", config);
         Scale ...
        if (tbsDocument.getVisiblePdfSignatureRequirement().getScale() == null) {
          log.info("{}: visiblePdfSignatureRequirement.scale is not set, defaulting to 0", CorrelationID.id());
          tbsDocument.getVisiblePdfSignatureRequirement().setScale(0);
        }
        else if (tbsDocument.getVisiblePdfSignatureRequirement().getScale().intValue() < -100) {
          log.info("{}: visiblePdfSignatureRequirement.scale is set to '{}'. This is illegal, changing to -100",
            CorrelationID.id(), tbsDocument.getVisiblePdfSignatureRequirement().getScale());
          tbsDocument.getVisiblePdfSignatureRequirement().setScale(-100);
        }
         Page ...
        if (tbsDocument.getVisiblePdfSignatureRequirement().getPage() == null) {
          log.info("{}: visiblePdfSignatureRequirement.page is not set, defaulting to 0", CorrelationID.id());
          tbsDocument.getVisiblePdfSignatureRequirement().setPage(0);
        }
        if (tbsDocument.getVisiblePdfSignatureRequirement().getPage().intValue() < 0) {
          log.info("{}: visiblePdfSignatureRequirement.page is set to '{}'. This is illegal, changing to 0",
            CorrelationID.id(), tbsDocument.getVisiblePdfSignatureRequirement().getPage());
          tbsDocument.getVisiblePdfSignatureRequirement().setPage(0);
        }
      }
    }
     AdES requirements ...
    final EtsiAdesRequirement requestedAdes = tbsDocument.getAdesRequirement();
    final AdesProfileType ades = PDFIntegrationUtils.getPadesRequirement(requestedAdes);
    tbsDocument.addExtensionValue(PDFExtensionParams.adesRequirement.name(), ades.getStringValue());
     Visible PDF signature requirements ...
    final VisiblePdfSignatureRequirement visiblePdfSignatureRequirement = tbsDocument.getVisiblePdfSignatureRequirement();
    if (visiblePdfSignatureRequirement != null) {
      final VisibleSignatureImageFactory factory = new VisibleSignatureImageFactory(config.getPdfSignatureImageTemplates());
      try {
        final String encodedVisibleSignImage = factory.getEncodedVisibleSignImage(
          visiblePdfSignatureRequirement, signRequestInput.getAuthnRequirements().getRequestedSignerAttributes());
        tbsDocument.addExtensionValue(PDFExtensionParams.visibleSignImage.name(), encodedVisibleSignImage);
      }
      catch (VisiblePdfSignatureRequirementException e) {
        throw new InputValidationException(fieldName + ".visiblePdfSignatureRequirement", e.getMessage(), e);
      }
    }
    return processedTbsDocument;
  }
@ Override public ProcessedTbsDocument preProcess ( final TbsDocument document , final SignRequestInput signRequestInput , final IntegrationServiceConfiguration config , final DocumentCache documentCache , final String fieldName ) throws InputValidationException { final ProcessedTbsDocument processedTbsDocument = super . preProcess ( document , signRequestInput , config , documentCache , fieldName ) ; final TbsDocument tbsDocument = processedTbsDocument . getTbsDocument ( ) ; if ( tbsDocument . getVisiblePdfSignatureRequirement ( ) == null ) { if ( config . getDefaultVisiblePdfSignatureRequirement ( ) != null ) { log . debug ( "{}: Setting default value for visiblePdfSignatureRequirement ({}): {}" , CorrelationID . id ( ) , tbsDocument . getId ( ) , config . getDefaultVisiblePdfSignatureRequirement ( ) ) ; tbsDocument . setVisiblePdfSignatureRequirement ( config . getDefaultVisiblePdfSignatureRequirement ( ) ) ; } } else { if ( Boolean . valueOf ( tbsDocument . getVisiblePdfSignatureRequirement ( ) . getExtensionValue ( VisiblePdfSignatureRequirement . NULL_INDICATOR_EXTENSION ) ) ) { log . debug ( "{}: Document '{}' contains a null requirement, removing ..." , CorrelationID . id ( ) , tbsDocument . getId ( ) ) ; tbsDocument . setVisiblePdfSignatureRequirement ( null ) ; } else { this . visiblePdfSignatureRequirementValidator . validateObject ( tbsDocument . getVisiblePdfSignatureRequirement ( ) , fieldName + ".visiblePdfSignatureRequirement" , config ) ; if ( tbsDocument . getVisiblePdfSignatureRequirement ( ) . getScale ( ) == null ) { log . info ( "{}: visiblePdfSignatureRequirement.scale is not set, defaulting to 0" , CorrelationID . id ( ) ) ; tbsDocument . getVisiblePdfSignatureRequirement ( ) . setScale ( 0 ) ; } else if ( tbsDocument . getVisiblePdfSignatureRequirement ( ) . getScale ( ) . intValue ( ) < - 100 ) { log . info ( "{}: visiblePdfSignatureRequirement.scale is set to '{}'. This is illegal, changing to -100" , CorrelationID . id ( ) , tbsDocument . getVisiblePdfSignatureRequirement ( ) . getScale ( ) ) ; tbsDocument . getVisiblePdfSignatureRequirement ( ) . setScale ( - 100 ) ; } if ( tbsDocument . getVisiblePdfSignatureRequirement ( ) . getPage ( ) == null ) { log . info ( "{}: visiblePdfSignatureRequirement.page is not set, defaulting to 0" , CorrelationID . id ( ) ) ; tbsDocument . getVisiblePdfSignatureRequirement ( ) . setPage ( 0 ) ; } if ( tbsDocument . getVisiblePdfSignatureRequirement ( ) . getPage ( ) . intValue ( ) < 0 ) { log . info ( "{}: visiblePdfSignatureRequirement.page is set to '{}'. This is illegal, changing to 0" , CorrelationID . id ( ) , tbsDocument . getVisiblePdfSignatureRequirement ( ) . getPage ( ) ) ; tbsDocument . getVisiblePdfSignatureRequirement ( ) . setPage ( 0 ) ; } } } final EtsiAdesRequirement requestedAdes = tbsDocument . getAdesRequirement ( ) ; final AdesProfileType ades = PDFIntegrationUtils . getPadesRequirement ( requestedAdes ) ; tbsDocument . addExtensionValue ( PDFExtensionParams . adesRequirement . name ( ) , ades . getStringValue ( ) ) ; final VisiblePdfSignatureRequirement visiblePdfSignatureRequirement = tbsDocument . getVisiblePdfSignatureRequirement ( ) ; if ( visiblePdfSignatureRequirement != null ) { final VisibleSignatureImageFactory factory = new VisibleSignatureImageFactory ( config . getPdfSignatureImageTemplates ( ) ) ; try { final String encodedVisibleSignImage = factory . getEncodedVisibleSignImage ( visiblePdfSignatureRequirement , signRequestInput . getAuthnRequirements ( ) . getRequestedSignerAttributes ( ) ) ; tbsDocument . addExtensionValue ( PDFExtensionParams . visibleSignImage . name ( ) , encodedVisibleSignImage ) ; } catch ( VisiblePdfSignatureRequirementException e ) { throw new InputValidationException ( fieldName + ".visiblePdfSignatureRequirement" , e . getMessage ( ) , e ) ; } } return processedTbsDocument ; }
Handles settings for PDF visible signatures.
Handles settings for PDF visible signatures .
// Is this a "null" request. If so, remove it ... // // Validate the input ... // // Scale ... // // Page ... // // AdES requirements ... // // Visible PDF signature requirements ... //