Search in sources :

Example 1 with UrlBuilder

use of org.openecard.common.util.UrlBuilder in project open-ecard by ecsec.

the class TCTokenRequest method addTokenUrlParameter.

/**
 * Adds the card type given in the given RecognitionInfo object as type to the tcTokenURL contained in the given map.
 *
 * @param queries Map which contains the tcTokenURL and shall contain the new cardType.
 * @param recInfo RecognitionInfo object containing the cardType or type parameter.
 */
private static void addTokenUrlParameter(@Nonnull Map<String, String> queries, @Nonnull String selectedCardType) {
    if (queries.containsKey("tcTokenURL")) {
        String tcTokenURL = queries.get("tcTokenURL");
        try {
            UrlBuilder builder = UrlBuilder.fromUrl(tcTokenURL);
            // url encoding is done by the builder
            builder = builder.queryParam("type", selectedCardType, true);
            queries.put("tcTokenURL", builder.build().toString());
            queries.put("cardType", selectedCardType);
        } catch (URISyntaxException ex) {
        // ignore if this happens the authentication will fail at all.
        }
    }
}
Also used : UrlBuilder(org.openecard.common.util.UrlBuilder) URISyntaxException(java.net.URISyntaxException)

Example 2 with UrlBuilder

use of org.openecard.common.util.UrlBuilder in project open-ecard by ecsec.

the class TCTokenRequest method addTokenUrlParameter.

/**
 * Adds the card type given in the given RecognitionInfo object as type to the tcTokenURL contained in the given map.
 *
 * @param queries Map which contains the tcTokenURL and shall contain the new cardType.
 * @param recInfo RecognitionInfo object containing the cardType or type parameter.
 */
private static void addTokenUrlParameter(@Nonnull Map<String, String> queries, @Nonnull RecognitionInfo recInfo) {
    if (queries.containsKey("tcTokenURL")) {
        String tcTokenURL = queries.get("tcTokenURL");
        try {
            UrlBuilder builder = UrlBuilder.fromUrl(tcTokenURL);
            // url encoding is done by the builder
            builder = builder.queryParam("type", recInfo.getCardType(), true);
            queries.put("tcTokenURL", builder.build().toString());
            queries.put("cardType", recInfo.getCardType());
        } catch (URISyntaxException ex) {
        // ignore if this happens the authentication will fail at all.
        }
    }
}
Also used : UrlBuilder(org.openecard.common.util.UrlBuilder) URISyntaxException(java.net.URISyntaxException)

Example 3 with UrlBuilder

use of org.openecard.common.util.UrlBuilder in project open-ecard by ecsec.

the class TCTokenResponse method finishResponse.

/**
 * Completes the response, so that it can be used in the binding.
 * The values extended include result code, result message and the redirect address.
 *
 * @param clearContext If {@code true} then delete context. Keep it otherwise.
 * @throws InvalidRedirectUrlException Thrown in case the error redirect URL could not be determined.
 */
public void finishResponse(boolean clearContext) throws InvalidRedirectUrlException {
    try {
        DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
        UrlBuilder ub = UrlBuilder.fromUrl(getRefreshAddress());
        if (ECardConstants.Major.OK.equals(result.getResultMajor())) {
            setResultCode(BindingResultCode.REDIRECT);
            String refreshURL = ub.queryParam("ResultMajor", "ok").build().toString();
            getAuxResultData().put(AuxDataKeys.REDIRECT_LOCATION, refreshURL);
        } else {
            boolean isRefreshAddressValid = (Boolean) dynCtx.get(TR03112Keys.IS_REFRESH_URL_VALID);
            setResultCode(BindingResultCode.REDIRECT);
            String refreshURL;
            String fixedMinor = TCTokenHacks.fixResultMinor(result.getResultMinor());
            if (isRefreshAddressValid) {
                refreshURL = ub.queryParam("ResultMajor", "error").queryParamUrl("ResultMinor", fixedMinor).build().toString();
            } else {
                refreshURL = token.getComErrorAddressWithParams(result.getResultMinor());
            }
            getAuxResultData().put(AuxDataKeys.REDIRECT_LOCATION, refreshURL);
            if (result.getResultMessage().getValue() != null) {
                setResultMessage(result.getResultMessage().getValue());
            }
        }
        // clear and remove the DynamicContext
        if (!clearContext) {
            dynCtx.clear();
            DynamicContext.remove();
        }
    } catch (URISyntaxException ex) {
        // TODO: translate when exception changes
        throw new IllegalArgumentException(lang.getOriginalMessage(INVALID_URL), ex);
    }
}
Also used : UrlBuilder(org.openecard.common.util.UrlBuilder) URISyntaxException(java.net.URISyntaxException) DynamicContext(org.openecard.common.DynamicContext)

Aggregations

URISyntaxException (java.net.URISyntaxException)3 UrlBuilder (org.openecard.common.util.UrlBuilder)3 DynamicContext (org.openecard.common.DynamicContext)1