use of io.gravitee.am.service.exception.EnforceUserIdentityException 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);
}
});
}
use of io.gravitee.am.service.exception.EnforceUserIdentityException in project gravitee-access-management by gravitee-io.
the class ForgotPasswordSubmissionEndpointTest method shouldCompleteWithSuccessWhen_EnforceIdentityException_ConfirmIdentityNotEnabled.
@Test
public void shouldCompleteWithSuccessWhen_EnforceIdentityException_ConfirmIdentityNotEnabled() throws Exception {
Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
router.route().order(-1).handler(routingContext -> {
routingContext.put("client", client);
routingContext.next();
});
when(accountSettings.isResetPasswordConfirmIdentity()).thenReturn(false);
when(userService.forgotPassword(argThat(p -> p.getEmail().equals("email@test.com")), eq(client), any(User.class))).thenReturn(Completable.error(new EnforceUserIdentityException()));
testRequest(HttpMethod.POST, "/forgotPassword?client_id=client-id", req -> postEmail(req, "email@test.com"), resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertTrue(location.endsWith("/forgotPassword?client_id=client-id&success=forgot_password_completed"));
}, HttpStatusCode.FOUND_302, "Found", null);
}
use of io.gravitee.am.service.exception.EnforceUserIdentityException in project gravitee-access-management by gravitee-io.
the class ForgotPasswordSubmissionEndpointTest method shouldCompleteWithWarningWhen_EnforceIdentityException_TooManyResult.
@Test
public void shouldCompleteWithWarningWhen_EnforceIdentityException_TooManyResult() throws Exception {
Client client = new Client();
client.setId("client-id");
client.setClientId("client-id");
router.route().order(-1).handler(routingContext -> {
routingContext.put("client", client);
routingContext.next();
});
when(accountSettings.isResetPasswordConfirmIdentity()).thenReturn(true);
when(userService.forgotPassword(argThat(p -> p.getEmail().equals("email@test.com")), eq(client), any(User.class))).thenReturn(Completable.error(new EnforceUserIdentityException()));
testRequest(HttpMethod.POST, "/forgotPassword?client_id=client-id", req -> postEmail(req, "email@test.com"), resp -> {
String location = resp.headers().get("location");
assertNotNull(location);
assertTrue(location.endsWith("/forgotPassword?client_id=client-id&warning=forgot_password_confirm"));
}, HttpStatusCode.FOUND_302, "Found", null);
}
Aggregations