Add session lifecycle to pinMgmt
package org.openecard.plugins.pinplugin;
import iso.std.iso_iec._24727.tech.schema.ActionType;
+import iso.std.iso_iec._24727.tech.schema.ChannelHandleType;
import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType;
+import iso.std.iso_iec._24727.tech.schema.CreateSession;
+import iso.std.iso_iec._24727.tech.schema.CreateSessionResponse;
import iso.std.iso_iec._24727.tech.schema.DestroyChannel;
+import iso.std.iso_iec._24727.tech.schema.DestroySession;
import iso.std.iso_iec._24727.tech.schema.Disconnect;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
@@ -36,10 +40,13 @@ import org.openecard.addon.Context;
import org.openecard.addon.bind.AppExtensionException;
import org.openecard.common.DynamicContext;
import org.openecard.common.ECardConstants;
+import org.openecard.common.WSHelper;
import org.openecard.common.WSHelper.WSException;
import org.openecard.common.event.EventType;
+import org.openecard.common.interfaces.DispatcherExceptionUnchecked;
import org.openecard.common.interfaces.EventCallback;
import org.openecard.common.interfaces.EventFilter;
+import org.openecard.common.interfaces.InvocationTargetExceptionUnchecked;
import org.openecard.gui.ResultStatus;
import org.openecard.plugins.pinplugin.gui.CardRemovedFilter;
import org.openecard.plugins.pinplugin.gui.PINDialog;
@@ -73,7 +80,10 @@ public class GetCardsAndPINStatusAction extends AbstractPINAction {
// init dyn ctx
DynamicContext ctx = DynamicContext.getInstance(DYNCTX_INSTANCE_KEY);
+ ConnectionHandleType sessionHandle = null;
try {
+ sessionHandle = createSessionHandle();
+
// check if a german identity card is inserted, if not wait for it
cHandle = waitForCardType(GERMAN_IDENTITY_CARD);
@@ -81,6 +91,7 @@ public class GetCardsAndPINStatusAction extends AbstractPINAction {
LOG.debug("User cancelled card insertion.");
return;
}
+ copySession(sessionHandle, cHandle);
cHandle = connectToRootApplication(cHandle);
@@ -147,10 +158,26 @@ public class GetCardsAndPINStatusAction extends AbstractPINAction {
throw new AppExtensionException(ex.getResultMinor(), ex.getMessage());
} finally {
+ try {
+ if (sessionHandle != null) {
+ DestroySession request = new DestroySession();
+ request.setConnectionHandle(sessionHandle);
+ this.dispatcher.safeDeliver(request);
+ }
+ } catch(Exception e) {
+ }
ctx.clear();
}
}
+ private ConnectionHandleType createSessionHandle() throws DispatcherExceptionUnchecked, InvocationTargetExceptionUnchecked, WSException {
+ CreateSessionResponse response = (CreateSessionResponse)this.dispatcher.safeDeliver(new CreateSession());
+ WSHelper.checkResult(response);
+
+ ConnectionHandleType sessionHandle = response.getConnectionHandle();
+ return sessionHandle;
+ }
+
@Override
public void init(Context aCtx) throws ActionInitializationException {
dispatcher = aCtx.getDispatcher();
@@ -164,4 +191,14 @@ public class GetCardsAndPINStatusAction extends AbstractPINAction {
//ignore
}
+ private void copySession(ConnectionHandleType source, ConnectionHandleType target) {
+ ChannelHandleType sourceChannel = source.getChannelHandle();
+ ChannelHandleType targetChannel = target.getChannelHandle();
+ if (targetChannel == null) {
+ targetChannel = new ChannelHandleType();
+ target.setChannelHandle(targetChannel);
+ }
+ targetChannel.setSessionIdentifier(sourceChannel.getSessionIdentifier());
+ }
+
}
