Search in sources :

Example 1 with InvalidTCTokenUrlException

use of org.openecard.binding.tctoken.ex.InvalidTCTokenUrlException in project open-ecard by ecsec.

the class TCTokenRequest method parseTCTokenRequestURI.

private static TCTokenRequest parseTCTokenRequestURI(Map<String, String> queries, Context ctx) throws InvalidTCTokenException, MissingActivationParameterException, AuthServerException, InvalidRedirectUrlException, InvalidTCTokenElement, InvalidTCTokenUrlException, SecurityViolationException, InvalidAddressException, UserCancellationException {
    TCTokenRequest tcTokenRequest = new TCTokenRequest();
    try {
        if (queries.containsKey("cardTypes") || queries.containsKey("cardType")) {
            String[] types;
            if (queries.containsKey("cardType")) {
                types = new String[] { queries.get("cardType") };
            } else {
                types = queries.get("cardTypes").split(",");
            }
            ConnectionHandleType handle = findCard(types, ctx);
            setIfdName(queries, handle.getIFDName());
            setContextHandle(queries, handle.getContextHandle());
            setSlotIndex(queries, handle.getSlotIndex());
            addTokenUrlParameter(queries, handle.getRecognitionInfo());
        } else {
            String[] types = new String[] { tcTokenRequest.cardType };
            ConnectionHandleType handle = findCard(types, ctx);
            setIfdName(queries, handle.getIFDName());
            setContextHandle(queries, handle.getContextHandle());
            setSlotIndex(queries, handle.getSlotIndex());
        }
    } catch (UserCancellationException ex) {
        if (queries.containsKey("cardTypes")) {
            addTokenUrlParameter(queries, queries.get("cardTypes").split(",")[0]);
        }
        LOG.warn("The user aborted the CardInsertion dialog.", ex);
        DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
        dynCtx.put(TR03112Keys.CARD_SELECTION_CANCELLATION, ex);
    }
    String activationTokenUrl = null;
    for (Map.Entry<String, String> next : queries.entrySet()) {
        String k = next.getKey();
        k = k == null ? "" : k;
        String v = next.getValue();
        if (v == null || v.isEmpty()) {
            LOG.info("Skipping query parameter '{}' because it does not contain a value.", k);
        } else {
            switch(k) {
                case "tcTokenURL":
                    activationTokenUrl = v;
                    break;
                case "ifdName":
                    tcTokenRequest.ifdName = v;
                    break;
                case "contextHandle":
                    tcTokenRequest.contextHandle = StringUtils.toByteArray(v);
                    break;
                case "slotIndex":
                    tcTokenRequest.slotIndex = new BigInteger(v);
                    break;
                case "cardType":
                    tcTokenRequest.cardType = v;
                    break;
                default:
                    LOG.info("Unknown query element: {}", k);
                    break;
            }
        }
    }
    // cardType determined! set in dynamic context, so the information is available in ResourceContext
    DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    dynCtx.put(TR03112Keys.ACTIVATION_CARD_TYPE, tcTokenRequest.cardType);
    if (activationTokenUrl != null) {
        try {
            URL tokenUrl = new URL(activationTokenUrl);
            TCTokenContext tokenCtx = TCTokenContext.generateTCToken(tokenUrl);
            tcTokenRequest.tokenCtx = tokenCtx;
            tcTokenRequest.token = tokenCtx.getToken();
            tcTokenRequest.certificates = tokenCtx.getCerts();
            tcTokenRequest.tcTokenURL = tokenUrl;
        } catch (MalformedURLException ex) {
            // TODO: check if the error type is correct, was WRONG_PARAMETER before
            throw new InvalidTCTokenUrlException(INVALID_TCTOKEN_URL, ex, activationTokenUrl);
        }
    }
    if (tcTokenRequest.token == null) {
        throw new MissingActivationParameterException(NO_TOKEN);
    }
    return tcTokenRequest;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) MalformedURLException(java.net.MalformedURLException) MissingActivationParameterException(org.openecard.binding.tctoken.ex.MissingActivationParameterException) URL(java.net.URL) InvalidTCTokenUrlException(org.openecard.binding.tctoken.ex.InvalidTCTokenUrlException) UserCancellationException(org.openecard.binding.tctoken.ex.UserCancellationException) BigInteger(java.math.BigInteger) HashMap(java.util.HashMap) Map(java.util.Map) DynamicContext(org.openecard.common.DynamicContext)

Aggregations

ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 BigInteger (java.math.BigInteger)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InvalidTCTokenUrlException (org.openecard.binding.tctoken.ex.InvalidTCTokenUrlException)1 MissingActivationParameterException (org.openecard.binding.tctoken.ex.MissingActivationParameterException)1 UserCancellationException (org.openecard.binding.tctoken.ex.UserCancellationException)1 DynamicContext (org.openecard.common.DynamicContext)1