Using CoSign and in case of multiple signatures, how do you specify which signature to use using SOAP API? -
i using cosign developer account , have created several graphical signatures. using sample code sign pdf file , works, able enumerate signatures couldn't figure out how specify signature use out of account's signatures list.
code sample used:
package trial; import com.arx.sapiws.dss._1.*; import java.io.file; import java.io.fileinputstream; import java.io.fileoutputstream; import java.util.list; import oasis.names.tc.dss._1_0.core.schema.documenttype.base64data; import oasis.names.tc.dss._1_0.core.schema.*; import oasis.names.tc.saml._1_0.assertion.*; public class multipesignatures { public static void main(string[] args) throws exception { string filename = "d:/demo - copy.pdf"; string signerusername = ""; string signerpassword = ""; if (!checkfile(filename)) { system.out.println("cannot find '" + filename + "' or read/write protected. aborting."); return; } // user's graphical signatures list<graphicimagetype> gsignatures = listgraphicalsignatures(signerusername, " ", signerpassword); (graphicimagetype image : gsignatures) { system.out.println("image: " + image.getgraphicimagename()); } signpdf(filename, signerusername, signerpassword); } private static void signpdf(string filename, string signerusername, string signerpassword) { system.out.println("trying sign '" + filename + "' '" + signerusername + "' password '" + signerpassword + "' ..."); byte[] filebytes = getpdfbytes(filename); base64data corepdfbytes = new base64data(); corepdfbytes.setvalue(filebytes); corepdfbytes.setmimetype("application/pdf"); documenttype mydoc = new documenttype(); mydoc.setbase64data(corepdfbytes); // set signer - username/domain nameidentifiertype cosignuserprops = new nameidentifiertype(); cosignuserprops.setvalue(signerusername); cosignuserprops.setnamequalifier(" "); // set signer - password cosignauthdatatype cosignpassword = new cosignauthdatatype(); cosignpassword.setlogonpassword(signerpassword); // set signer - username+password claimedidentity cosignuser = new claimedidentity(); cosignuser.setname(cosignuserprops); cosignuser.setsupportinginfo(cosignpassword); //set signature field settings sapisigfieldsettingstype sigfieldsettings = new sapisigfieldsettingstype(); sigfieldsettings.setname("sigfield"); sigfieldsettings.setinvisible(boolean.false); sigfieldsettings.setx(150); sigfieldsettings.sety(110); sigfieldsettings.setwidth(150); sigfieldsettings.setheight(50); sigfieldsettings.setdependencymode(dependencymodeenum.independent); sigfieldsettings.setsignaturetype(signaturetypeenum.digital); sigfieldsettings.setemptyfieldlabel(""); sigfieldsettings.setpage(1); //initiate request components requestbasetype.inputdocuments inputs = new requestbasetype.inputdocuments(); inputs.getotherordocumenthashortransformeddata().add(mydoc); requestbasetype.optionalinputs optinputs = new requestbasetype.optionalinputs(); optinputs.setsignaturetype("http://arx.com/sapiws/dss/1.0/signature-field-create-sign"); optinputs.setclaimedidentity(cosignuser); optinputs.setsapisigfieldsettings(sigfieldsettings); optinputs.setreturnpdftailonly(boolean.true); //initiate connection cosign sapi service dss service = new dss(); dsssoap port = service.getdsssoap12(); //initiate request signrequest request = new signrequest(); request.setoptionalinputs(optinputs); request.setinputdocuments(inputs); request.setrequestid("dummyrequestid"); //make call dsssignresult result = port.dsssign(request); //check result: responsebasetype.result rc = result.getresult(); string errmsg = "" + rc.getresultmajor(); if (errmsg.compareto("urn:oasis:names:tc:dss:1.0:resultmajor:success") != 0) { system.out.println("cannot sign '" + filename + "' got: " + rc.getresultmessage().getvalue()); return; } system.out.println("trying append signature '" + filename + "' ('" + signerusername + "') ..."); // if ok signature: dsssignresult.signatureobject sig = result.getsignatureobject(); dsssignresult.signatureobject.base64signature b64sig = sig.getbase64signature(); try { fileoutputstream fos = new fileoutputstream(filename, true); fos.write(b64sig.getvalue()); fos.close(); } catch (exception e) { system.out.println("error writing pdf file: " + e.getmessage()); return; } system.out.println("signature of '" + signerusername + "' appended '" + filename + "'."); } private static list<graphicimagetype> listgraphicalsignatures(string username, string domain, string password) throws exception { system.out.println("retrieving list of graphical signatures user: " + username); dsssignresult result; try { //initiate connection cosign sapi service dss service = new dss(); dsssoap port = service.getdsssoap12(); signrequest request = new signrequest(); requestbasetype.optionalinputs optinputs = new requestbasetype.optionalinputs(); // set signature type (enumerate graphical signatures) optinputs.setsignaturetype("http://arx.com/sapiws/dss/1.0/enum-graphic-images"); // set username / password claimedidentity cosignuser = new claimedidentity(); nameidentifiertype username = new nameidentifiertype(); username.setvalue(username); username.setnamequalifier(domain); cosignuser.setname(username); cosignauthdatatype userpass = new cosignauthdatatype(); userpass.setlogonpassword(password); cosignuser.setsupportinginfo(userpass); optinputs.setclaimedidentity(cosignuser); // set flags optinputs.setflags(long.parselong("00ff0000", 16)); // done, make call: request.setoptionalinputs(optinputs); request.setinputdocuments(null); result = port.dsssign(request); // check result: responsebasetype.result rc = result.getresult(); string errmsg = "" + rc.getresultmajor(); if (errmsg.compareto("urn:oasis:names:tc:dss:1.0:resultmajor:success") == 0) { return result.getoptionaloutputs().getavailablegraphicsignature(); } else { throw new exception(rc.getresultmessage().getvalue()); } } catch (java.rmi.remoteexception e) { throw e; } catch (exception e) { throw e; } } private static byte[] getpdfbytes(string filename) { byte[] pdf; // read file buffer try { file file = new file(filename); if (!file.canread()) { return null; } if (!file.canwrite()) { return null; } pdf = new byte[(int) file.length()]; fileinputstream fos = new fileinputstream(file); fos.read(pdf, 0, (int) file.length()); fos.close(); } catch (exception e) { return null; } return pdf; } private static boolean checkfile(string filename) { try { file file = new file(filename); if (!file.canread()) { return false; } if (!file.canwrite()) { return false; } } catch (exception e) { return false; } return true; } }
just grab name of preferred graphical signature , set described in answer previous question.
Comments
Post a Comment