Search in sources :

Example 1 with InputInfoUnit

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

the class PinChangeStepAction method getNewPin.

private char[] getNewPin() throws PinsDoNotMatchException {
    char[] pin1 = null;
    char[] pin2 = null;
    for (InputInfoUnit info : pinStep.getInputInfoUnits()) {
        if (PinChangeStep.NEW_PIN_FIELD1.equals(info.getID())) {
            pin1 = ((PasswordField) info).getValue();
        } else if (PinChangeStep.NEW_PIN_FIELD2.equals(info.getID())) {
            pin2 = ((PasswordField) info).getValue();
        }
    }
    if (pin1 != null && Arrays.equals(pin1, pin2)) {
        return pin1;
    } else {
        throw new PinsDoNotMatchException("The PINs entered in the UI do not match.");
    }
}
Also used : InputInfoUnit(org.openecard.gui.definition.InputInfoUnit) PasswordField(org.openecard.gui.definition.PasswordField)

Example 2 with InputInfoUnit

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

the class PINStep method updateAttemptsDisplay.

protected void updateAttemptsDisplay(int newValue) {
    for (InputInfoUnit unit : getInputInfoUnits()) {
        if (unit.getID().equals(PIN_ATTEMPTS_ID)) {
            Text text = (Text) unit;
            text.setText(LANG_PACE.translationForKey("step_pin_retrycount", newValue));
        }
    }
}
Also used : InputInfoUnit(org.openecard.gui.definition.InputInfoUnit) Text(org.openecard.gui.definition.Text)

Example 3 with InputInfoUnit

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

the class EacGuiImpl method getPinResult.

public List<OutputInfoUnit> getPinResult(Step step) throws InterruptedException {
    if (step instanceof PINStep) {
        PINStep pinStep = (PINStep) step;
        switch(pinStep.getStatus()) {
            case RC3:
                this.pinStatus.deliver(PinStatus.RC3);
                break;
            case RC2:
                this.pinStatus.deliver(PinStatus.RC2);
                break;
            case RC1:
                this.pinStatus.deliver(PinStatus.CAN);
                break;
        }
        // read values
        String pinValue = this.userPin.deref();
        String canValue = this.userCan.deref();
        ArrayList<OutputInfoUnit> result = new ArrayList<>();
        for (InputInfoUnit nextIn : pinStep.getInputInfoUnits()) {
            if (pinValue != null && nextIn instanceof PasswordField && nextIn.getID().equals("PACE_PIN_FIELD")) {
                PasswordField pw = new PasswordField(nextIn.getID());
                pw.copyContentFrom(nextIn);
                pw.setValue(pinValue.toCharArray());
                result.add(pw);
            } else if (canValue != null && nextIn instanceof PasswordField && nextIn.getID().equals("PACE_CAN_FIELD")) {
                PasswordField pw = new PasswordField(nextIn.getID());
                pw.copyContentFrom(nextIn);
                pw.setValue(canValue.toCharArray());
                result.add(pw);
            }
        }
        return result;
    } else {
        throw new InterruptedException("The given step is not a PinStep.");
    }
}
Also used : InputInfoUnit(org.openecard.gui.definition.InputInfoUnit) PINStep(org.openecard.sal.protocol.eac.gui.PINStep) ArrayList(java.util.ArrayList) OutputInfoUnit(org.openecard.gui.definition.OutputInfoUnit) PasswordField(org.openecard.gui.definition.PasswordField)

Example 4 with InputInfoUnit

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

the class EacGuiImpl method loadValuesFromSteps.

public void loadValuesFromSteps(Step step1, Step step2) {
    String subject = "", subjectUrl = "";
    TermsOfUsage termsOfUsage = new TermsOfUsage("text/plain", new byte[0]);
    String validity = "";
    String issuer = "", issuerUrl = "";
    for (InputInfoUnit next : step1.getInputInfoUnits()) {
        if ("SubjectName".equals(next.getID()) && next instanceof ToggleText) {
            ToggleText tt = (ToggleText) next;
            subject = tt.getText();
        } else if ("SubjectURL".equals(next.getID()) && next instanceof ToggleText) {
            ToggleText tt = (ToggleText) next;
            subjectUrl = tt.getText();
        } else if ("TermsOfUsage".equals(next.getID()) && next instanceof ToggleText) {
            ToggleText tt = (ToggleText) next;
            Document d = tt.getDocument();
            termsOfUsage = new TermsOfUsage(d.getMimeType(), d.getValue());
        } else if ("Validity".equals(next.getID()) && next instanceof ToggleText) {
            ToggleText tt = (ToggleText) next;
            validity = tt.getText();
        } else if ("IssuerName".equals(next.getID()) && next instanceof ToggleText) {
            ToggleText tt = (ToggleText) next;
            issuer = tt.getText();
        } else if ("IssuerURL".equals(next.getID()) && next instanceof ToggleText) {
            ToggleText tt = (ToggleText) next;
            issuerUrl = tt.getText();
        }
    }
    ArrayList<BoxItem> readAccess = new ArrayList<>();
    ArrayList<BoxItem> writeAccess = new ArrayList<>();
    for (InputInfoUnit next : step2.getInputInfoUnits()) {
        if ("ReadCHATCheckBoxes".equals(next.getID()) && next instanceof Checkbox) {
            Checkbox cb = (Checkbox) next;
            this.readAccessBox = cb;
            for (org.openecard.gui.definition.BoxItem nb : cb.getBoxItems()) {
                BoxItem bi = new BoxItem(nb.getName(), nb.isChecked(), nb.isDisabled(), nb.getText());
                readAccess.add(bi);
            }
        } else if ("WriteCHATCheckBoxes".equals(next.getID()) && next instanceof Checkbox) {
            Checkbox cb = (Checkbox) next;
            this.writeAccessBox = cb;
            for (org.openecard.gui.definition.BoxItem nb : cb.getBoxItems()) {
                BoxItem bi = new BoxItem(nb.getName(), nb.isChecked(), nb.isDisabled(), nb.getText());
                writeAccess.add(bi);
            }
        }
    }
    ServerData sd = new ServerData(subject, subjectUrl, termsOfUsage, validity, issuer, issuerUrl, readAccess, writeAccess);
    serverData.deliver(sd);
}
Also used : TermsOfUsage(org.openecard.gui.android.eac.types.TermsOfUsage) ToggleText(org.openecard.gui.definition.ToggleText) ArrayList(java.util.ArrayList) Document(org.openecard.gui.definition.Document) InputInfoUnit(org.openecard.gui.definition.InputInfoUnit) Checkbox(org.openecard.gui.definition.Checkbox) ServerData(org.openecard.gui.android.eac.types.ServerData) BoxItem(org.openecard.gui.android.eac.types.BoxItem)

Example 5 with InputInfoUnit

use of org.openecard.gui.definition.InputInfoUnit 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

InputInfoUnit (org.openecard.gui.definition.InputInfoUnit)5 ArrayList (java.util.ArrayList)2 OutputInfoUnit (org.openecard.gui.definition.OutputInfoUnit)2 PasswordField (org.openecard.gui.definition.PasswordField)2 HashMap (java.util.HashMap)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 ThreadTerminateException (org.openecard.common.ThreadTerminateException)1 InvocationTargetExceptionUnchecked (org.openecard.common.interfaces.InvocationTargetExceptionUnchecked)1 ResultStatus (org.openecard.gui.ResultStatus)1 StepResult (org.openecard.gui.StepResult)1 BoxItem (org.openecard.gui.android.eac.types.BoxItem)1 ServerData (org.openecard.gui.android.eac.types.ServerData)1 TermsOfUsage (org.openecard.gui.android.eac.types.TermsOfUsage)1 Checkbox (org.openecard.gui.definition.Checkbox)1 Document (org.openecard.gui.definition.Document)1 Step (org.openecard.gui.definition.Step)1 Text (org.openecard.gui.definition.Text)1 ToggleText (org.openecard.gui.definition.ToggleText)1