Search in sources :

Example 1 with ActivationError

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

the class ActivateAction method processTcToken.

/**
 * Process the tcTokenURL or the activation object and perform a authentication.
 *
 * @param params Parameters of the request.
 * @return A {@link BindingResult} representing the result of the authentication.
 */
private BindingResult processTcToken(Map<String, String> params) {
    BindingResult response;
    DynamicContext dynCtx = DynamicContext.getInstance(TR03112Keys.INSTANCE_KEY);
    dynCtx.put(TR03112Keys.COOKIE_MANAGER, new CookieManager());
    try {
        TCTokenRequest tcTokenRequest = null;
        try {
            tcTokenRequest = TCTokenRequest.convert(params, ctx);
            response = tokenHandler.handleActivate(tcTokenRequest);
            // Show success message. If we get here we have a valid StartPAOSResponse and a valid refreshURL
            showFinishMessage((TCTokenResponse) response);
        } catch (ActivationError ex) {
            if (ex instanceof NonGuiException) {
            // error already displayed to the user so do not repeat it here
            } else {
                if (ex.getMessage().equals("Invalid HTTP message received.")) {
                    showErrorMessage(lang.translationForKey(ACTIVATION_INVALID_REFRESH_ADDRESS));
                } else {
                    showErrorMessage(ex.getLocalizedMessage());
                }
            }
            LOG.error(ex.getMessage());
            // stack trace only in debug level
            LOG.debug(ex.getMessage(), ex);
            LOG.debug("Returning result: \n{}", ex.getBindingResult());
            if (ex instanceof FatalActivationError) {
                LOG.info("Authentication failed, displaying error in Browser.");
            } else {
                LOG.info("Authentication failed, redirecting to with errors attached to the URL.");
            }
            response = ex.getBindingResult();
        } finally {
            if (tcTokenRequest != null && tcTokenRequest.getTokenContext() != null) {
                // close connection to tctoken server in case PAOS didn't already perform this action
                tcTokenRequest.getTokenContext().closeStream();
            }
        }
    } catch (RuntimeException e) {
        response = new BindingResult(BindingResultCode.INTERNAL_ERROR);
        LOG.error(e.getMessage(), e);
    }
    return response;
}
Also used : FatalActivationError(org.openecard.binding.tctoken.ex.FatalActivationError) BindingResult(org.openecard.addon.bind.BindingResult) TCTokenRequest(org.openecard.binding.tctoken.TCTokenRequest) NonGuiException(org.openecard.binding.tctoken.ex.NonGuiException) CookieManager(org.openecard.transport.httpcore.cookies.CookieManager) DynamicContext(org.openecard.common.DynamicContext) FatalActivationError(org.openecard.binding.tctoken.ex.FatalActivationError) ActivationError(org.openecard.binding.tctoken.ex.ActivationError)

Aggregations

BindingResult (org.openecard.addon.bind.BindingResult)1 TCTokenRequest (org.openecard.binding.tctoken.TCTokenRequest)1 ActivationError (org.openecard.binding.tctoken.ex.ActivationError)1 FatalActivationError (org.openecard.binding.tctoken.ex.FatalActivationError)1 NonGuiException (org.openecard.binding.tctoken.ex.NonGuiException)1 DynamicContext (org.openecard.common.DynamicContext)1 CookieManager (org.openecard.transport.httpcore.cookies.CookieManager)1