Search in sources :

Example 1 with EventType

use of org.openecard.common.event.EventType in project open-ecard by ecsec.

the class Status method signalEvent.

@Override
public synchronized void signalEvent(EventType eventType, EventObject eventData) {
    LOG.debug("Event: {}", eventType);
    ConnectionHandleType ch = eventData.getHandle();
    if (ch == null) {
        LOG.error("No handle provided in event {}.", eventType);
        return;
    }
    LOG.debug("ConnectionHandle: {}", ch);
    RecognitionInfo info = ch.getRecognitionInfo();
    LOG.debug("RecognitionInfo: {}", info);
    String ifdName = ch.getIFDName();
    LOG.debug("IFDName: {}", ifdName);
    if (null != eventType) {
        switch(eventType) {
            case TERMINAL_ADDED:
                addInfo(ifdName, info);
                break;
            case TERMINAL_REMOVED:
                removeInfo(ifdName);
                break;
            default:
                // track status of the events to prevent double events to overwrite the actual status
                EventType lastStatus = cardStatus.get(ifdName);
                // only update status for recognized cards in case it is a card removed
                if (EventType.CARD_RECOGNIZED == lastStatus) {
                    if (EventType.CARD_REMOVED == eventType) {
                        cardStatus.remove(ifdName);
                        updateInfo(ifdName, info);
                    }
                } else {
                    if (EventType.CARD_REMOVED == eventType) {
                        cardStatus.remove(ifdName);
                    } else {
                        cardStatus.put(ifdName, eventType);
                    }
                    updateInfo(ifdName, info);
                }
        }
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) RecognitionInfo(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo) EventType(org.openecard.common.event.EventType)

Example 2 with EventType

use of org.openecard.common.event.EventType in project open-ecard by ecsec.

the class PAOSTask method call.

@Override
public StartPAOSResponse call() throws MalformedURLException, PAOSException, DispatcherException, InvocationTargetException, ConnectionError, PAOSConnectionException {
    // add event listener terminating the whole process in case the card is removed
    final Thread execThread = Thread.currentThread();
    EventCallback disconnectEventSink = new EventCallback() {

        @Override
        public void signalEvent(EventType eventType, EventObject eventData) {
            if (eventType == EventType.CARD_REMOVED) {
                LOG.info("Card has been removed during authentication. Shutting down EAC process.");
                execThread.interrupt();
            }
        }
    };
    EventFilter evFilter = new CardRemovedFilter(connectionHandle.getIFDName(), connectionHandle.getSlotIndex());
    evManager.add(disconnectEventSink, evFilter);
    try {
        TlsConnectionHandler tlsHandler = new TlsConnectionHandler(dispatcher, tokenRequest, connectionHandle);
        tlsHandler.setUpClient();
        // Set up PAOS connection
        PAOS p = new PAOS(dispatcher, tlsHandler);
        // Create StartPAOS message
        StartPAOS sp = new StartPAOS();
        sp.setProfile(ECardConstants.Profile.ECARD_1_1);
        sp.getConnectionHandle().add(getHandleForServer());
        sp.setSessionIdentifier(tlsHandler.getSessionId());
        StartPAOS.UserAgent ua = new StartPAOS.UserAgent();
        ua.setName(AppVersion.getName());
        ua.setVersionMajor(BigInteger.valueOf(AppVersion.getMajor()));
        ua.setVersionMinor(BigInteger.valueOf(AppVersion.getMinor()));
        ua.setVersionSubminor(BigInteger.valueOf(AppVersion.getPatch()));
        sp.setUserAgent(ua);
        StartPAOS.SupportedAPIVersions sv = new StartPAOS.SupportedAPIVersions();
        sv.setMajor(ECardConstants.ECARD_API_VERSION_MAJOR);
        sv.setMinor(ECardConstants.ECARD_API_VERSION_MINOR);
        sv.setSubminor(ECardConstants.ECARD_API_VERSION_SUBMINOR);
        sp.getSupportedAPIVersions().add(sv);
        sp.getSupportedDIDProtocols().addAll(supportedDIDs);
        return p.sendStartPAOS(sp);
    } finally {
        evManager.del(disconnectEventSink);
        TCTokenHandler.disconnectHandle(dispatcher, connectionHandle);
        TCTokenHandler.killUserConsent();
    }
}
Also used : EventType(org.openecard.common.event.EventType) EventCallback(org.openecard.common.interfaces.EventCallback) EventFilter(org.openecard.common.interfaces.EventFilter) EventObject(org.openecard.common.event.EventObject) StartPAOS(iso.std.iso_iec._24727.tech.schema.StartPAOS) PAOS(org.openecard.transport.paos.PAOS) StartPAOS(iso.std.iso_iec._24727.tech.schema.StartPAOS) CardRemovedFilter(org.openecard.sal.protocol.eac.gui.CardRemovedFilter)

Aggregations

EventType (org.openecard.common.event.EventType)2 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)1 StartPAOS (iso.std.iso_iec._24727.tech.schema.StartPAOS)1 EventObject (org.openecard.common.event.EventObject)1 EventCallback (org.openecard.common.interfaces.EventCallback)1 EventFilter (org.openecard.common.interfaces.EventFilter)1 CardRemovedFilter (org.openecard.sal.protocol.eac.gui.CardRemovedFilter)1 PAOS (org.openecard.transport.paos.PAOS)1