From 255269ab17404fa1249c257e88815cbbee6e0d0f Mon Sep 17 00:00:00 2001 From: clemenso Date: Mon, 13 Oct 2008 12:53:57 +0000 Subject: ExternalDisplaySignRequestHandler git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@105 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../bku/local/stal/LocalSignRequestHandler.java | 93 ++++++++++++++-------- 1 file changed, 59 insertions(+), 34 deletions(-) (limited to 'BKULocal/src/main/java/at/gv/egiz') diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java index ca420f13..4330f570 100644 --- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java +++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java @@ -17,6 +17,7 @@ package at.gv.egiz.bku.local.stal; import at.gv.egiz.bku.slcommands.impl.DataObjectHashDataInput; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -41,68 +42,92 @@ import java.io.InputStream; */ public class LocalSignRequestHandler extends SignRequestHandler { - private static final Log log = LogFactory - .getLog(LocalSignRequestHandler.class); - private List hashDataInput = Collections.EMPTY_LIST; - - public LocalSignRequestHandler() { - } + private static final Log log = LogFactory.getLog(LocalSignRequestHandler.class); + private List hashDataInputs = Collections.EMPTY_LIST; + /** + * If the request is a SIGN request, it contains a list of DataObjectHashDataInput + * providing the pre-digested input stream (that can be obtained repeatedly) if + * reference caching is enabled (or null otherwise). + * @param request + * @return + */ @SuppressWarnings("unchecked") @Override public STALResponse handleRequest(STALRequest request) { if (request instanceof SignRequest) { SignRequest signReq = (SignRequest) request; - hashDataInput = signReq.getHashDataInput(); + hashDataInputs = signReq.getHashDataInput(); } return super.handleRequest(request); } + /** + * + * @param dsigReferences + * @throws java.lang.Exception + */ @Override - public List getCashedHashDataInputs( - List dsigReferences) throws Exception { - ArrayList result = new ArrayList(); + public void displayHashDataInputs(List dsigReferences) throws Exception { + if (dsigReferences == null || dsigReferences.size() < 1) { + log.error("No hashdata input selected to be displayed: null"); + throw new Exception("No HashData Input selected to be displayed"); + } + + ArrayList selectedHashDataInputs = new ArrayList(); for (ReferenceType dsigRef : dsigReferences) { // don't get Manifest, QualifyingProperties, ... if (dsigRef.getType() == null) { String dsigRefId = dsigRef.getId(); if (dsigRefId != null) { - for (HashDataInput hdi : hashDataInput) { - if (hdi.getReferenceId().equals(dsigRefId)) { - if (hdi instanceof DataObjectHashDataInput) { - if (log.isTraceEnabled()) - log.trace("adding DataObjectHashDataInput"); - result.add(hdi); - } else if (hdi instanceof ByteArrayHashDataInput) { - if (log.isTraceEnabled()) - log.trace("adding ByteArrayHashDataInput"); - result.add(hdi); - } else { - if (log.isDebugEnabled()) - log.debug("provided HashDataInput not chaching enabled, creating ByteArrayHashDataInput"); - - InputStream hdIs = hdi.getHashDataInput(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(hdIs.available()); - int b; - while ((b = hdIs.read()) != -1) { - baos.write(b); - } - ByteArrayHashDataInput baHdi = new ByteArrayHashDataInput(baos.toByteArray(), hdi.getReferenceId(), hdi.getMimeType(), hdi.getEncoding()); - result.add(baHdi); + boolean hdiAvailable = false; + for (HashDataInput hashDataInput : hashDataInputs) { + if (dsigRefId.equals(hashDataInput.getReferenceId())) { + log.debug("display hashdata input for dsig:SignedReference " + dsigRefId); + if (!(hashDataInput instanceof DataObjectHashDataInput)) { + log.warn( + "expected DataObjectHashDataInput for LocalSignRequestHandler, got " + hashDataInput.getClass().getName()); + hashDataInput = getByteArrayHashDataInput(hashDataInput); } + selectedHashDataInputs.add(hashDataInput); + hdiAvailable = true; + break; } } + if (!hdiAvailable) { + log.error("no hashdata input for dsig:SignedReference " + dsigRefId); + throw new Exception( + "No HashDataInput available for dsig:SignedReference " + dsigRefId); + } } else { throw new Exception( - "Cannot get HashDataInput for dsig:Reference without Id attribute"); + "Cannot get HashDataInput for dsig:Reference without Id attribute"); } } } - return result; + + if (selectedHashDataInputs.size() < 1) { + log.error("dsig:SignedInfo does not contain a data reference"); + throw new Exception("dsig:SignedInfo does not contain a data reference"); + } + gui.showHashDataInputDialog(selectedHashDataInputs, this, "ok"); } @Override public SMCCSTALRequestHandler newInstance() { return new LocalSignRequestHandler(); } + + private ByteArrayHashDataInput getByteArrayHashDataInput(HashDataInput hashDataInput) throws IOException { + + InputStream hdIs = hashDataInput.getHashDataInput(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(hdIs.available()); + int b; + while ((b = hdIs.read()) != -1) { + baos.write(b); + } + ByteArrayHashDataInput hdi = new ByteArrayHashDataInput(baos.toByteArray(), hashDataInput.getReferenceId(), hashDataInput.getMimeType(), hashDataInput.getEncoding()); + + return hdi; + } } -- cgit v1.2.3