Search in sources :

Example 26 with Step

use of org.openecard.gui.definition.Step in project open-ecard by ecsec.

the class RunGUI method pinInputStep.

private Step pinInputStep(Step requestedDataStep) throws Exception {
    Step pinInputStep = new Step("PIN-Eingabe");
    pinInputStep.setAction(new PinInputAction(pinInputStep, requestedDataStep));
    Text t = new Text();
    t.setText("Durch die Eingabe Ihrer PIN bestätigen Sie, dass folgende markierte Daten an den Anbieter übermittelt werden.");
    pinInputStep.getInputInfoUnits().add(t);
    Checkbox dataToSendSelection = new Checkbox("c1");
    BoxItem vornameBoxItem = new BoxItem();
    vornameBoxItem.setName("vornameBoxItem");
    vornameBoxItem.setChecked(true);
    vornameBoxItem.setDisabled(true);
    vornameBoxItem.setText("Vorname");
    BoxItem nameBoxItem = new BoxItem();
    nameBoxItem.setName("nameBoxItem");
    nameBoxItem.setChecked(true);
    nameBoxItem.setDisabled(true);
    nameBoxItem.setText("Name");
    BoxItem doctordegreeBoxItem = new BoxItem();
    doctordegreeBoxItem.setName("doctordegreeBoxItem");
    doctordegreeBoxItem.setChecked(false);
    doctordegreeBoxItem.setDisabled(true);
    doctordegreeBoxItem.setText("Doktorgrad");
    BoxItem addressBoxItem = new BoxItem();
    addressBoxItem.setName("addressBoxItem");
    addressBoxItem.setChecked(true);
    addressBoxItem.setDisabled(true);
    addressBoxItem.setText("Anschrift");
    BoxItem birthdayBoxItem = new BoxItem();
    birthdayBoxItem.setName("birthdayBoxItem");
    birthdayBoxItem.setChecked(false);
    birthdayBoxItem.setDisabled(true);
    birthdayBoxItem.setText("Geburtstag");
    BoxItem birthplaceBoxItem = new BoxItem();
    birthplaceBoxItem.setName("birthplaceBoxItem");
    birthplaceBoxItem.setChecked(false);
    birthplaceBoxItem.setDisabled(true);
    birthplaceBoxItem.setText("Geburtsort");
    BoxItem pseudonymBoxItem = new BoxItem();
    pseudonymBoxItem.setName("pseudonymBoxItem");
    pseudonymBoxItem.setChecked(false);
    pseudonymBoxItem.setDisabled(true);
    pseudonymBoxItem.setText("Ordens-oder Künstlername");
    BoxItem identiycardtypeBoxItem = new BoxItem();
    identiycardtypeBoxItem.setName("identiycardtypeBoxItem");
    identiycardtypeBoxItem.setChecked(false);
    identiycardtypeBoxItem.setDisabled(true);
    identiycardtypeBoxItem.setText("Ausweistyp");
    BoxItem certificationcountryBoxItem = new BoxItem();
    certificationcountryBoxItem.setName("certificationcountryBoxItem");
    certificationcountryBoxItem.setChecked(false);
    certificationcountryBoxItem.setDisabled(true);
    certificationcountryBoxItem.setText("Ausstellendes Land");
    BoxItem habitationBoxItem = new BoxItem();
    habitationBoxItem.setName("habitationBoxItem");
    habitationBoxItem.setChecked(false);
    habitationBoxItem.setDisabled(true);
    habitationBoxItem.setText("Wohnort");
    BoxItem ageverificationBoxItem = new BoxItem();
    ageverificationBoxItem.setName("ageverificationBoxItem");
    ageverificationBoxItem.setChecked(false);
    ageverificationBoxItem.setDisabled(true);
    ageverificationBoxItem.setText("Altersverifikation");
    Text sendAgreement_Text = new Text();
    sendAgreement_Text.setText("Wenn Sie mit der Übermittlung der ausgewählten\n" + "Daten einverstanden sind, geben Sie bitte\n" + "Ihre 6-stellige PIN ein.");
    PasswordField p1 = new PasswordField("pf1");
    p1.setDescription("pass input1");
    p1.setDescription("PIN:");
    p1.setMaxLength(6);
    dataToSendSelection.getBoxItems().add(vornameBoxItem);
    dataToSendSelection.getBoxItems().add(nameBoxItem);
    // dataToSendSelection.getBoxItems().add(doctordegreeBoxItem);
    // dataToSendSelection.getBoxItems().add(addressBoxItem);
    // dataToSendSelection.getBoxItems().add(birthdayBoxItem);
    // dataToSendSelection.getBoxItems().add(birthplaceBoxItem);
    // dataToSendSelection.getBoxItems().add(identiycardtypeBoxItem);
    // dataToSendSelection.getBoxItems().add(certificationcountryBoxItem);
    // dataToSendSelection.getBoxItems().add(habitationBoxItem);
    // dataToSendSelection.getBoxItems().add(ageverificationBoxItem);
    pinInputStep.getInputInfoUnits().add(dataToSendSelection);
    // pinInputStep.getInputInfoUnits().add(sendAgreement_Text);
    pinInputStep.getInputInfoUnits().add(p1);
    return pinInputStep;
}
Also used : Checkbox(org.openecard.gui.definition.Checkbox) ToggleText(org.openecard.gui.definition.ToggleText) Text(org.openecard.gui.definition.Text) Step(org.openecard.gui.definition.Step) PasswordField(org.openecard.gui.definition.PasswordField) BoxItem(org.openecard.gui.definition.BoxItem)

Example 27 with Step

use of org.openecard.gui.definition.Step in project open-ecard by ecsec.

the class RunGUI method checkDataStep.

private Step checkDataStep() {
    // wird durchgeführt");
    Step dataTransaction_Step = new Step("Identitätsnachweis");
    Text requestedPIN_Text = new Text();
    requestedPIN_Text.setText("Eingegebene PIN");
    BoxItem pinCorrekt = new BoxItem();
    pinCorrekt.setName("pinCorrect");
    pinCorrekt.setChecked(true);
    pinCorrekt.setText("OK");
    dataTransaction_Step.getInputInfoUnits().add(requestedPIN_Text);
    Text cerificate_Text = new Text();
    cerificate_Text.setText("Berechtigungszertifikat");
    BoxItem certificateCorrekt = new BoxItem();
    certificateCorrekt.setName("certificateCorrekt");
    certificateCorrekt.setChecked(true);
    certificateCorrekt.setText("OK");
    // statusMessages_CheckBox.getBoxItems().add(certificateCorrekt);
    dataTransaction_Step.getInputInfoUnits().add(cerificate_Text);
    Text eCard_Text = new Text();
    eCard_Text.setText("Verwendete Karte");
    BoxItem eCardCorrekt = new BoxItem();
    eCardCorrekt.setName("eCardCorrekt");
    eCardCorrekt.setChecked(true);
    eCardCorrekt.setText("OK");
    dataTransaction_Step.getInputInfoUnits().add(eCard_Text);
    // statusMessages_CheckBox.getBoxItems().add(eCardCorrekt);
    Text dataTransaction_Text = new Text();
    dataTransaction_Text.setText("Datenübermittlung wird geprüft");
    BoxItem dataTransactionCorrekt = new BoxItem();
    dataTransactionCorrekt.setName("dataTransactionCorrekt");
    dataTransactionCorrekt.setChecked(true);
    dataTransactionCorrekt.setText("OK");
    // statusMessages_CheckBox.getBoxItems().add(dataTransactionCorrekt);
    dataTransaction_Step.getInputInfoUnits().add(dataTransaction_Text);
    return dataTransaction_Step;
}
Also used : ToggleText(org.openecard.gui.definition.ToggleText) Text(org.openecard.gui.definition.Text) Step(org.openecard.gui.definition.Step) BoxItem(org.openecard.gui.definition.BoxItem)

Example 28 with Step

use of org.openecard.gui.definition.Step in project open-ecard by ecsec.

the class SwingUserConsent method obtainNavigator.

@Override
public UserConsentNavigator obtainNavigator(UserConsentDescription parameters) {
    SwingDialogWrapper dialogWrapper = baseDialogWrapper.derive();
    dialogWrapper.setTitle(parameters.getTitle());
    Container rootPanel = dialogWrapper.getContentPane();
    rootPanel.removeAll();
    boolean isPinEntryDialog = parameters.getDialogType().equals("pin_entry_dialog");
    boolean isPinChangeDialog = parameters.getDialogType().equals("pin_change_dialog");
    boolean isUpdateDialog = parameters.getDialogType().equals("update_dialog");
    // set different size when special dialog type is requested
    if (isPinEntryDialog) {
        dialogWrapper.setSize(350, 284);
    } else if (isPinChangeDialog) {
        dialogWrapper.setSize(570, 430);
    } else if (isUpdateDialog) {
        dialogWrapper.setSize(480, 330);
    }
    String dialogType = parameters.getDialogType();
    List<Step> steps = parameters.getSteps();
    // Set up panels
    JPanel stepPanel = new JPanel(new BorderLayout());
    JPanel sideBar = new JPanel();
    StepBar stepBar = new StepBar(steps);
    final NavigationBar navBar = new NavigationBar(steps.size());
    Logo l = new Logo();
    initializeSidePanel(sideBar, l, stepBar);
    final SwingNavigator navigator = new SwingNavigator(dialogWrapper, dialogType, steps, stepPanel, navBar, stepBar);
    navBar.registerEvents(navigator);
    navBar.setDefaultButton(dialogWrapper.getRootPane());
    dialogWrapper.getDialog().addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent event) {
            // The user has closed the window by pressing the x of the window manager handle this event as
            // cancelation. This is necessary to unlock the app in case of a running authentication.
            ActionEvent e = new ActionEvent(navBar, ActionEvent.ACTION_PERFORMED, GUIConstants.BUTTON_CANCEL);
            navigator.actionPerformed(e);
        }
    });
    // Config layout
    GroupLayout layout = new GroupLayout(rootPanel);
    rootPanel.setLayout(layout);
    layout.setAutoCreateGaps(false);
    layout.setAutoCreateContainerGaps(true);
    if (isPinEntryDialog || isPinChangeDialog || isUpdateDialog) {
        layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup().addComponent(stepPanel).addComponent(navBar)));
        layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addGroup(layout.createSequentialGroup().addComponent(stepPanel).addComponent(navBar)));
    } else {
        layout.setHorizontalGroup(layout.createSequentialGroup().addComponent(sideBar, 200, 200, 200).addGroup(layout.createParallelGroup().addComponent(stepPanel).addComponent(navBar)));
        layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER).addComponent(sideBar).addGroup(layout.createSequentialGroup().addComponent(stepPanel).addComponent(navBar)));
    }
    rootPanel.validate();
    rootPanel.repaint();
    return navigator;
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) WindowAdapter(java.awt.event.WindowAdapter) Step(org.openecard.gui.definition.Step) Container(java.awt.Container) BorderLayout(java.awt.BorderLayout) WindowEvent(java.awt.event.WindowEvent) GroupLayout(javax.swing.GroupLayout)

Example 29 with Step

use of org.openecard.gui.definition.Step in project open-ecard by ecsec.

the class EacNavigatorFactoryTest method testGivenCorrectValuesThenCreateFromShouldCreateCorrectInstance.

@Test
public void testGivenCorrectValuesThenCreateFromShouldCreateCorrectInstance() {
    final List<Step> expectedSteps = createInitialSteps();
    new Expectations() {

        {
            ucd.getDialogType();
            result = "EAC";
            ucd.getSteps();
            result = expectedSteps;
        }
    };
    EacNavigatorFactory sut = new EacNavigatorFactory();
    final UserConsentNavigator result = sut.createFrom(ucd);
    assertEquals(result.getClass(), EacNavigator.class);
}
Also used : Expectations(mockit.Expectations) Step(org.openecard.gui.definition.Step) UserConsentNavigator(org.openecard.gui.UserConsentNavigator) Test(org.testng.annotations.Test)

Example 30 with Step

use of org.openecard.gui.definition.Step in project open-ecard by ecsec.

the class ExecutionEngine method process.

/**
 * Processes the user consent associated with this instance. <br>
 * The following algorithm is used to process the dialog.
 * <ol>
 * <li>Display the first step.</li>
 * <li>Evaluate step result. Break execution on CANCEL.</li>
 * <li>Execute step action. Break execution on CANCEL.</li>
 * <li>Display either next previous or current step, or a replacement according to result.</li>
 * <li>Proceed with point 2.</li>
 * </ol>
 *
 * @return Overall result of the execution.
 * @throws ThreadTerminateException Thrown in case the GUI has been closed externally (interrupted).
 */
public ResultStatus process() throws ThreadTerminateException {
    // get first step
    StepResult next = navigator.next();
    // loop over steps. break inside loop
    while (true) {
        ResultStatus result = next.getStatus();
        // close dialog on cancel and interrupt
        if (result == ResultStatus.INTERRUPTED || Thread.currentThread().isInterrupted()) {
            navigator.close();
            throw new ThreadTerminateException("GUI has been interrupted.");
        } else if (result == ResultStatus.CANCEL) {
            navigator.close();
            return result;
        }
        // get result and put it in resultmap
        List<OutputInfoUnit> stepResults = next.getResults();
        Map<String, ExecutionResults> oldResults = Collections.unmodifiableMap(results);
        results.put(next.getStepID(), new ExecutionResults(next.getStepID(), stepResults));
        // replace InfoInputUnit values in live list
        if (!next.getStep().isResetOnLoad()) {
            Step s = next.getStep();
            List<InputInfoUnit> inputInfo = s.getInputInfoUnits();
            Map<String, InputInfoUnit> infoMap = new HashMap<>();
            // create index over infos
            for (InputInfoUnit nextInfo : inputInfo) {
                infoMap.put(nextInfo.getID(), nextInfo);
            }
            for (OutputInfoUnit nextOut : stepResults) {
                InputInfoUnit matchingInfo = infoMap.get(nextOut.getID());
                // an entry must exist, otherwise this is an error in the GUI implementation
                // this type of error should be found in tests
                matchingInfo.copyContentFrom(nextOut);
            }
        }
        // replace step if told by result value
        if (next.getReplacement() != null) {
            switch(next.getStatus()) {
                case BACK:
                    next = navigator.replacePrevious(next.getReplacement());
                    break;
                case OK:
                    if (navigator.hasNext()) {
                        next = navigator.replaceNext(next.getReplacement());
                    } else {
                        navigator.close();
                        return convertStatus(StepActionResultStatus.NEXT);
                    }
                    break;
                case RELOAD:
                    next = navigator.replaceCurrent(next.getReplacement());
                    break;
                default:
                    // fallthrough because CANCEL and INTERRUPTED are already handled
                    break;
            }
        } else {
            // step replacement did not happen, so we can execute the action
            StepAction action = next.getStep().getAction();
            StepActionCallable actionCallable = new StepActionCallable(action, oldResults, next);
            // use separate thread or tasks running outside the JVM context, like PCSC calls, won't stop on cancellation
            ExecutorService execService = Executors.newSingleThreadExecutor();
            Future<StepActionResult> actionFuture = execService.submit(actionCallable);
            navigator.setRunningAction(actionFuture);
            StepActionResult actionResult;
            try {
                actionResult = actionFuture.get();
            } catch (CancellationException ex) {
                LOG.info("StepAction was canceled.", ex);
                navigator.close();
                return ResultStatus.CANCEL;
            } catch (InterruptedException ex) {
                LOG.info("StepAction was interrupted.", ex);
                navigator.close();
                throw new ThreadTerminateException("GUI has been interrupted.");
            } catch (ExecutionException ex) {
                // there are some special kinds we need to handle here
                if (ex.getCause() instanceof InvocationTargetExceptionUnchecked) {
                    InvocationTargetExceptionUnchecked iex = (InvocationTargetExceptionUnchecked) ex.getCause();
                    if (iex.getCause() instanceof ThreadTerminateException) {
                        LOG.info("StepAction was interrupted.", ex);
                        navigator.close();
                        throw new ThreadTerminateException("GUI has been interrupted.");
                    }
                }
                // all other types
                LOG.error("StepAction failed with error.", ex.getCause());
                navigator.close();
                return ResultStatus.CANCEL;
            }
            // break out if cancel was returned
            if (actionResult.getStatus() == StepActionResultStatus.CANCEL) {
                LOG.info("StepAction was canceled.");
                navigator.close();
                return ResultStatus.CANCEL;
            }
            // replace step if told by result value
            if (actionResult.getReplacement() != null) {
                switch(actionResult.getStatus()) {
                    case BACK:
                        next = navigator.replacePrevious(actionResult.getReplacement());
                        break;
                    case NEXT:
                        if (navigator.hasNext()) {
                            next = navigator.replaceNext(actionResult.getReplacement());
                        } else {
                            navigator.close();
                            return convertStatus(StepActionResultStatus.NEXT);
                        }
                        break;
                    case REPEAT:
                        next = navigator.replaceCurrent(actionResult.getReplacement());
                        break;
                    default:
                        // fallthrough because CANCEL is already handled
                        break;
                }
            } else {
                // no replacement just proceed
                switch(actionResult.getStatus()) {
                    case BACK:
                        next = navigator.previous();
                        break;
                    case NEXT:
                        if (navigator.hasNext()) {
                            next = navigator.next();
                        } else {
                            navigator.close();
                            return convertStatus(StepActionResultStatus.NEXT);
                        }
                        break;
                    case REPEAT:
                        next = navigator.current();
                        break;
                    default:
                        // fallthrough because CANCEL is already handled
                        break;
                }
            }
        }
    }
}
Also used : InvocationTargetExceptionUnchecked(org.openecard.common.interfaces.InvocationTargetExceptionUnchecked) ResultStatus(org.openecard.gui.ResultStatus) HashMap(java.util.HashMap) Step(org.openecard.gui.definition.Step) InputInfoUnit(org.openecard.gui.definition.InputInfoUnit) CancellationException(java.util.concurrent.CancellationException) ExecutorService(java.util.concurrent.ExecutorService) OutputInfoUnit(org.openecard.gui.definition.OutputInfoUnit) StepResult(org.openecard.gui.StepResult) ThreadTerminateException(org.openecard.common.ThreadTerminateException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

Step (org.openecard.gui.definition.Step)38 Text (org.openecard.gui.definition.Text)19 UserConsentDescription (org.openecard.gui.definition.UserConsentDescription)8 ToggleText (org.openecard.gui.definition.ToggleText)6 StepAction (org.openecard.gui.executor.StepAction)5 StepActionResult (org.openecard.gui.executor.StepActionResult)5 ArrayList (java.util.ArrayList)4 BoxItem (org.openecard.gui.definition.BoxItem)3 Checkbox (org.openecard.gui.definition.Checkbox)3 ExecutionResults (org.openecard.gui.executor.ExecutionResults)3 Test (org.testng.annotations.Test)3 DIDAuthenticationDataType (iso.std.iso_iec._24727.tech.schema.DIDAuthenticationDataType)2 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)2 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 Expectations (mockit.Expectations)2 DynamicContext (org.openecard.common.DynamicContext)2 WSException (org.openecard.common.WSHelper.WSException)2 AuthDataMap (org.openecard.common.anytype.AuthDataMap)2 AuthDataResponse (org.openecard.common.anytype.AuthDataResponse)2