From 23f82c4d63290cb41dc0fc6ebb86d6cae9a560fe Mon Sep 17 00:00:00 2001 From: clemenso Date: Tue, 20 Jan 2009 14:09:21 +0000 Subject: prepare for stal service extension git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@262 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4 --- .../gv/egiz/stal/service/impl/STALServiceImpl.java | 127 +++++++++++++-------- 1 file changed, 78 insertions(+), 49 deletions(-) (limited to 'BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java') diff --git a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java index 05a3f5e5..45629869 100644 --- a/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java +++ b/BKUOnline/src/main/java/at/gv/egiz/stal/service/impl/STALServiceImpl.java @@ -14,9 +14,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package at.gv.egiz.stal.service.impl; +//import at.buergerkarte.namespaces.cardchannel.service.CommandAPDUType; +//import at.buergerkarte.namespaces.cardchannel.service.ScriptType; import at.gv.egiz.bku.binding.BindingProcessor; import at.gv.egiz.bku.binding.BindingProcessorManager; import at.gv.egiz.bku.binding.Id; @@ -36,6 +37,7 @@ import at.gv.egiz.stal.service.types.QuitRequestType; import at.gv.egiz.stal.service.types.RequestType; import at.gv.egiz.stal.service.types.ResponseType; import at.gv.egiz.stal.service.types.SignRequestType; +import com.sun.xml.ws.developer.UsesJAXBContext; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; @@ -46,6 +48,7 @@ import java.util.Map; import javax.annotation.Resource; import javax.jws.WebService; import javax.servlet.ServletContext; +import javax.xml.bind.JAXBElement; import javax.xml.ws.WebServiceContext; import javax.xml.ws.handler.MessageContext; import org.apache.commons.logging.Log; @@ -56,46 +59,45 @@ import org.apache.commons.logging.LogFactory; * @author clemens */ @WebService(endpointInterface = "at.gv.egiz.stal.service.STALPortType") +@UsesJAXBContext(STALXJAXBContextFactory.class) public class STALServiceImpl implements STALPortType { public static final String BINDING_PROCESSOR_MANAGER = "bindingProcessorManager"; public static final Id TEST_SESSION_ID = IdFactory.getInstance().createId("TestSession"); - protected static final Log log = LogFactory.getLog(STALServiceImpl.class); - + + static { - if (log.isTraceEnabled()) { log.trace("enabling webservice communication dump"); System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true"); } else { System.setProperty("com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace", "false"); } - } - @Resource - WebServiceContext wsContext; + protected WebServiceContext wsContext; protected IdFactory idF = IdFactory.getInstance(); + private at.gv.egiz.stal.service.types.ObjectFactory stalObjFactory = new at.gv.egiz.stal.service.types.ObjectFactory(); +// private at.buergerkarte.namespaces.cardchannel.service.ObjectFactory ccObjFactory = new at.buergerkarte.namespaces.cardchannel.service.ObjectFactory(); - @Override public GetNextRequestResponseType connect(String sessId) { - + if (sessId == null) { throw new NullPointerException("No session id provided"); } - + Id sessionId = idF.createId(sessId); if (log.isDebugEnabled()) { log.debug("Received Connect [" + sessionId + "]"); } - + if (TEST_SESSION_ID.equals(sessionId)) { return getTestSessionNextRequestResponse(null); } - + GetNextRequestResponseType response = new GetNextRequestResponseType(); response.setSessionId(sessionId.toString()); @@ -103,7 +105,7 @@ public class STALServiceImpl implements STALPortType { if (stal != null) { - List requestsOut = ((STALRequestBroker) stal).connect(); + List> requestsOut = ((STALRequestBroker) stal).connect(); response.getInfoboxReadRequestOrSignRequestOrQuitRequest().addAll(requestsOut); if (log.isDebugEnabled()) { @@ -112,29 +114,32 @@ public class STALServiceImpl implements STALPortType { sb.append("] containing "); sb.append(requestsOut.size()); sb.append(" requests: "); - for (RequestType reqOut : requestsOut) { - sb.append(reqOut.getClass()); + for (JAXBElement reqOut : requestsOut) { + sb.append(reqOut.getValue().getClass()); sb.append(' '); } log.debug(sb.toString()); } } else { log.error("Failed to get STAL for session " + sessionId + ", returning QuitRequest"); - response.getInfoboxReadRequestOrSignRequestOrQuitRequest().add(new QuitRequestType()); + QuitRequestType quitT = stalObjFactory.createQuitRequestType(); + JAXBElement quit = stalObjFactory.createGetNextRequestResponseTypeQuitRequest(quitT); + response.getInfoboxReadRequestOrSignRequestOrQuitRequest().add(quit); } return response; } - + @Override public GetNextRequestResponseType getNextRequest(GetNextRequestType request) { if (request.getSessionId() == null) { throw new NullPointerException("No session id provided"); } - + Id sessionId = idF.createId(request.getSessionId()); - List responsesIn = request.getInfoboxReadResponseOrSignResponseOrErrorResponse();//getResponse(); + List> responsesIn = request.getInfoboxReadResponseOrSignResponseOrErrorResponse(); +// List responsesIn = request.getInfoboxReadResponseOrSignResponseOrErrorResponse();//getResponse(); if (log.isDebugEnabled()) { StringBuilder sb = new StringBuilder("Received GetNextRequest ["); @@ -142,25 +147,25 @@ public class STALServiceImpl implements STALPortType { sb.append("] containing "); sb.append(responsesIn.size()); sb.append(" responses: "); - for (ResponseType respIn : responsesIn) { + for (Object respIn : responsesIn) { sb.append(respIn.getClass()); sb.append(' '); } log.debug(sb.toString()); } - + if (TEST_SESSION_ID.equals(sessionId)) { return getTestSessionNextRequestResponse(responsesIn); } GetNextRequestResponseType response = new GetNextRequestResponseType(); response.setSessionId(sessionId.toString()); - + STALRequestBroker stal = getStal(sessionId); if (stal != null) { - List requestsOut = ((STALRequestBroker) stal).nextRequest(responsesIn); + List> requestsOut = ((STALRequestBroker) stal).nextRequest(responsesIn); response.getInfoboxReadRequestOrSignRequestOrQuitRequest().addAll(requestsOut); if (log.isDebugEnabled()) { @@ -169,15 +174,17 @@ public class STALServiceImpl implements STALPortType { sb.append("] containing "); sb.append(requestsOut.size()); sb.append(" requests: "); - for (RequestType reqOut : requestsOut) { - sb.append(reqOut.getClass()); + for (JAXBElement reqOut : requestsOut) { + sb.append(reqOut.getValue().getClass()); sb.append(' '); } log.debug(sb.toString()); } } else { log.error("Failed to get STAL for session " + sessionId + ", returning QuitRequest"); - response.getInfoboxReadRequestOrSignRequestOrQuitRequest().add(new QuitRequestType()); + QuitRequestType quitT = stalObjFactory.createQuitRequestType(); + JAXBElement quit = stalObjFactory.createGetNextRequestResponseTypeQuitRequest(quitT); + response.getInfoboxReadRequestOrSignRequestOrQuitRequest().add(quit); } return response; } @@ -188,7 +195,7 @@ public class STALServiceImpl implements STALPortType { if (request.getSessionId() == null) { throw new NullPointerException("No session id provided"); } - + Id sessionId = idF.createId(request.getSessionId()); if (log.isDebugEnabled()) { @@ -197,13 +204,13 @@ public class STALServiceImpl implements STALPortType { GetHashDataInputResponseType response = new GetHashDataInputResponseType(); response.setSessionId(sessionId.toString()); - + if (TEST_SESSION_ID.equals(sessionId)) { log.debug("Received GetHashDataInput for session " + TEST_SESSION_ID + ", return DummyHashDataInput"); GetHashDataInputResponseType.Reference ref = new GetHashDataInputResponseType.Reference(); ref.setID("signed-data-reference-0-1214921968-27971781-24309"); //Reference-" + TEST_SESSION_ID + "-001"); ref.setMimeType("text/plain"); - + Charset charset; try { charset = Charset.forName("iso-8859-15"); @@ -316,30 +323,52 @@ public class STALServiceImpl implements STALPortType { return (bp == null) ? null : (bp.isFinished() ? null : (STALRequestBroker) bp.getSTAL()); } - private GetNextRequestResponseType getTestSessionNextRequestResponse(List responsesIn) { + private GetNextRequestResponseType getTestSessionNextRequestResponse(List> responsesIn) { GetNextRequestResponseType response = new GetNextRequestResponseType(); response.setSessionId(TEST_SESSION_ID.toString()); - - if (responsesIn != null && responsesIn.size() > 0 && responsesIn.get(0) instanceof ErrorResponseType) { - log.info("Received TestSession GetNextRequest(ErrorResponse), returning QuitRequest"); - response.getInfoboxReadRequestOrSignRequestOrQuitRequest().add(new QuitRequestType()); + + List> reqs = response.getInfoboxReadRequestOrSignRequestOrQuitRequest(); + + if (responsesIn == null) { + log.info("[TestSession] received CONNECT, return dummy requests "); +// ScriptType scriptT = ccObjFactory.createScriptType(); +// CommandAPDUType cmd = ccObjFactory.createCommandAPDUType(); +// cmd.setValue("TestSession CardChannelCMD 1234".getBytes()); +// scriptT.getResetOrCommandAPDUOrVerifyAPDU().add(cmd); +// reqs.add(ccObjFactory.createScript(scriptT)); + addDummyRequests(reqs); + } else if (responsesIn != null && responsesIn.size() > 0 && responsesIn.get(0).getValue() instanceof ErrorResponseType) { + log.info("[TestSession] received ErrorResponse, return QUIT request"); + QuitRequestType quitT = stalObjFactory.createQuitRequestType(); + reqs.add(stalObjFactory.createGetNextRequestResponseTypeQuitRequest(quitT)); } else { - log.info("Received TestSession GetNextRequest, returning SignRequest and 3 InfoboxReadRequests "); - InfoboxReadRequestType req = new InfoboxReadRequestType(); - req.setInfoboxIdentifier("IdentityLink"); - req.setDomainIdentifier("hansiwurzel"); - response.getInfoboxReadRequestOrSignRequestOrQuitRequest().add(req); - SignRequestType sig = new SignRequestType(); - sig.setKeyIdentifier("SecureSignatureKeypair"); - sig.setSignedInfo(" id('signed-data-object-0-1214921968-27971781-13578')/node() H1IePEEfGQ2SG03H6LTzw1TpCuM=yV6Q+I60buqR4mMaxA7fi+CV35A=".getBytes()); - response.getInfoboxReadRequestOrSignRequestOrQuitRequest().add(sig); - req = new InfoboxReadRequestType(); - req.setInfoboxIdentifier("CertifiedKeypair"); - response.getInfoboxReadRequestOrSignRequestOrQuitRequest().add(req); - req = new InfoboxReadRequestType(); - req.setInfoboxIdentifier("SecureSignatureKeypair"); - response.getInfoboxReadRequestOrSignRequestOrQuitRequest().add(req); + log.info("[TestSession] received " + responsesIn.size() + " response(s), return dummy requests" ); + addDummyRequests(reqs); } return response; } + + private void addDummyRequests(List> reqs) { +// log.info("[TestSession] add READ request for Infobox IdentityLink"); +// InfoboxReadRequestType ibrT1 = stalObjFactory.createInfoboxReadRequestType(); +// ibrT1.setInfoboxIdentifier("IdentityLink"); +// reqs.add(stalObjFactory.createGetNextRequestResponseTypeInfoboxReadRequest(ibrT1)); + + log.info("[TestSession] add READ request for Infobox CertifiedKeypair"); + InfoboxReadRequestType ibrT2 = stalObjFactory.createInfoboxReadRequestType(); + ibrT2.setInfoboxIdentifier("CertifiedKeypair"); + reqs.add(stalObjFactory.createGetNextRequestResponseTypeInfoboxReadRequest(ibrT2)); + + log.info("[TestSession] add READ request for Infobox SecureSignatureKeypair"); + InfoboxReadRequestType ibrT3 = stalObjFactory.createInfoboxReadRequestType(); + ibrT3.setInfoboxIdentifier("SecureSignatureKeypair"); + reqs.add(stalObjFactory.createGetNextRequestResponseTypeInfoboxReadRequest(ibrT3)); + + log.info("[TestSession] add SIGN request"); + SignRequestType sigT1 = stalObjFactory.createSignRequestType(); + sigT1.setKeyIdentifier("SecureSignatureKeypair"); + sigT1.setSignedInfo(" id('signed-data-object-0-1214921968-27971781-13578')/node() H1IePEEfGQ2SG03H6LTzw1TpCuM=yV6Q+I60buqR4mMaxA7fi+CV35A=".getBytes()); + reqs.add(stalObjFactory.createGetNextRequestResponseTypeSignRequest(sigT1)); + } + } -- cgit v1.2.3