Search in sources :

Example 1 with AccountStatusException

use of io.gravitee.am.common.exception.authentication.AccountStatusException in project gravitee-access-management by gravitee-io.

the class ForgotPasswordSubmissionEndpoint method handle.

@Override
public void handle(RoutingContext context) {
    final String email = context.request().getParam(ConstantKeys.EMAIL_PARAM_KEY);
    final String username = context.request().getParam(ConstantKeys.USERNAME_PARAM_KEY);
    final Client client = context.get(ConstantKeys.CLIENT_CONTEXT_KEY);
    MultiMap queryParams = RequestUtils.getCleanedQueryParams(context.request());
    AccountSettings settings = AccountSettings.getInstance(domain, client);
    final ForgotPasswordParameters parameters = new ForgotPasswordParameters(email, username, settings != null && settings.isResetPasswordCustomForm(), settings != null && settings.isResetPasswordConfirmIdentity());
    userService.forgotPassword(parameters, client, getAuthenticatedUser(context)).subscribe(() -> {
        queryParams.set(ConstantKeys.SUCCESS_PARAM_KEY, "forgot_password_completed");
        redirectToPage(context, queryParams);
    }, error -> {
        // the actual error continue to be stored in the audit logs
        if (error instanceof UserNotFoundException || error instanceof AccountStatusException) {
            queryParams.set(ConstantKeys.SUCCESS_PARAM_KEY, "forgot_password_completed");
            redirectToPage(context, queryParams);
        } else if (error instanceof EnforceUserIdentityException) {
            if (settings.isResetPasswordConfirmIdentity()) {
                queryParams.set(ConstantKeys.WARNING_PARAM_KEY, FORGOT_PASSWORD_CONFIRM);
            } else {
                queryParams.set(ConstantKeys.SUCCESS_PARAM_KEY, "forgot_password_completed");
            }
            redirectToPage(context, queryParams);
        } else {
            queryParams.set(ConstantKeys.ERROR_PARAM_KEY, "forgot_password_failed");
            redirectToPage(context, queryParams, error);
        }
    });
}
Also used : AccountSettings(io.gravitee.am.model.account.AccountSettings) UserNotFoundException(io.gravitee.am.service.exception.UserNotFoundException) AccountStatusException(io.gravitee.am.common.exception.authentication.AccountStatusException) MultiMap(io.vertx.reactivex.core.MultiMap) EnforceUserIdentityException(io.gravitee.am.service.exception.EnforceUserIdentityException) Client(io.gravitee.am.model.oidc.Client) ForgotPasswordParameters(io.gravitee.am.gateway.handler.root.service.user.model.ForgotPasswordParameters)

Aggregations

AccountStatusException (io.gravitee.am.common.exception.authentication.AccountStatusException)1 ForgotPasswordParameters (io.gravitee.am.gateway.handler.root.service.user.model.ForgotPasswordParameters)1 AccountSettings (io.gravitee.am.model.account.AccountSettings)1 Client (io.gravitee.am.model.oidc.Client)1 EnforceUserIdentityException (io.gravitee.am.service.exception.EnforceUserIdentityException)1 UserNotFoundException (io.gravitee.am.service.exception.UserNotFoundException)1 MultiMap (io.vertx.reactivex.core.MultiMap)1