From a9a7af5f0b14132101da486760ead7e35563cb4d Mon Sep 17 00:00:00 2001 From: Alexander Marsalek Date: Tue, 10 Jun 2014 19:15:39 +0200 Subject: added supoort for Signrequests without DTL link --- .../SignedDocAttributeRequestProvider.java | 104 +++++++++++---------- 1 file changed, 57 insertions(+), 47 deletions(-) (limited to 'id/server') diff --git a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/attributeproviders/SignedDocAttributeRequestProvider.java b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/attributeproviders/SignedDocAttributeRequestProvider.java index 42ef11758..ae10cc1c8 100644 --- a/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/attributeproviders/SignedDocAttributeRequestProvider.java +++ b/id/server/idserverlib/src/main/java/at/gv/egovernment/moa/id/protocols/stork2/attributeproviders/SignedDocAttributeRequestProvider.java @@ -132,7 +132,15 @@ public class SignedDocAttributeRequestProvider extends AttributeProvider { dssId = docId; if (dssId != null && data!=null) { - if(updateDocumentInDtl(data, docId, signResponseString)) + boolean success = false; + try{ + success = updateDocumentInDtl(data, docId, signResponseString); + }catch(Exception e){//No document service used? + Logger.info("No document service used?"); + e.printStackTrace(); + success = false; + } + if(success) { // set the url in the SignResponse DocumentWithSignature documentWithSignature = new DocumentWithSignature(); @@ -165,7 +173,12 @@ public class SignedDocAttributeRequestProvider extends AttributeProvider { IOUtils.copy(istr, writer, "UTF-8"); signResponseString = writer.toString(); Logger.info("SignResponse overwritten:"+signResponseString); - } + } + else + { + //No document service used? + // do nothing.... + } } else throw new Exception("No DSS id found."); @@ -221,6 +234,7 @@ public class SignedDocAttributeRequestProvider extends AttributeProvider { //Parse SignRequest String signRequestString = requestedAttribute.getValue().get(0); + Logger.debug("performRedirect, signrequest:"+signRequestString); Source signDoc = new StreamSource(new java.io.StringReader(signRequestString)); SignRequest signRequest = ApiUtils.unmarshal(signDoc, SignRequest.class); try{ @@ -228,50 +242,46 @@ public class SignedDocAttributeRequestProvider extends AttributeProvider { String dtlURL = getDtlUrlFromRequest(signRequest); String docId = signRequest.getDocUI(); - String docRequest = getDocTransferRequest(docId, dtlURL);//dtlUrl - //Start - code to be removed -// System.out.println("SAML Engine vidp init"); -// final STORKSAMLEngine engine = STORKSAMLEngine.getInstance("VIDP"); -// final byte[] samlToken = UrlBase64.decode(docRequest); -// final STORKAttrQueryRequest request= engine.validateSTORKAttrQueryRequest(samlToken); -// final IPersonalAttributeList pal = request.getPersonalAttributeList(); -// final PersonalAttribute sdoc = pal.get("docRequest"); -// if (sdoc != null) -// { -// String docId1 = sdoc.getValue().get(0); -// System.out.println("docId1:"+docId1); -// } - //End - code to be removed - - byte[] data = getDocumentFromDtl(docRequest, dtlURL);//dtlUrl - //load doc from DTL - Logger.debug("data:"+data); - String mime = getDocumentMimeFromDtl(docId, dtlURL);//dtlUrl - Logger.debug("mime:"+mime); - //add doc as base64* to signrequest => post doc to oasis - try{ - List includeObjects = ApiUtils.findNamedElement( - signRequest.getOptionalInputs(), "IncludeObject", - IncludeObject.class); - signRequest.getOptionalInputs().getAny().removeAll(includeObjects); - - DocumentType document = new DocumentType(); - Base64Data b64data = new Base64Data(); - b64data.setValue(data); - b64data.setMimeType(mime); - document.setBase64Data(b64data); - signRequest.setInputDocuments(ApiUtils.createInputDocuments(document)); - //override old signRequestString - - InputStream istr = ApiUtils.marshalToInputStream(signRequest); - StringWriter writer = new StringWriter(); - IOUtils.copy(istr, writer, "UTF-8"); - signRequestString = writer.toString(); - Logger.info("Signrequest overwritten"); - } catch (Exception e) { - e.printStackTrace(); - throw new Exception("Could not marshall sign request", e); - } + if(dtlURL!=null) + { + String docRequest = getDocTransferRequest(docId, dtlURL);//dtlUrl + + byte[] data = getDocumentFromDtl(docRequest, dtlURL);//dtlUrl + + //load doc from DTL + Logger.debug("data:"+data); + String mime = getDocumentMimeFromDtl(docId, dtlURL);//dtlUrl + Logger.debug("mime:"+mime); + + //add doc as base64* to signrequest => post doc to oasis + try{ + List includeObjects = ApiUtils.findNamedElement( + signRequest.getOptionalInputs(), "IncludeObject", + IncludeObject.class); + signRequest.getOptionalInputs().getAny().removeAll(includeObjects); + + DocumentType document = new DocumentType(); + Base64Data b64data = new Base64Data(); + b64data.setValue(data); + b64data.setMimeType(mime); + document.setBase64Data(b64data); + signRequest.setInputDocuments(ApiUtils.createInputDocuments(document)); + //override old signRequestString + + InputStream istr = ApiUtils.marshalToInputStream(signRequest); + StringWriter writer = new StringWriter(); + IOUtils.copy(istr, writer, "UTF-8"); + signRequestString = writer.toString(); + Logger.info("Signrequest overwritten"); + } catch (Exception e) { + e.printStackTrace(); + throw new Exception("Could not marshall sign request", e); + } + } + else//Do not modify signRequest, document is already included + { + + } }catch(Exception e) { Logger.info("No documentservice used?"); @@ -329,7 +339,7 @@ public class SignedDocAttributeRequestProvider extends AttributeProvider { if (document.getDocumentURL() != null) return document.getDocumentURL(); else - throw new Exception("No document url found"); + return null;//throw new Exception("No document url found"); } else throw new Exception("No input document found"); -- cgit v1.2.3