Search in sources :

Example 1 with UserInvalidException

use of io.gravitee.am.service.exception.UserInvalidException in project gravitee-access-management by gravitee-io.

the class UserResource method resetPassword.

@POST
@Path("resetPassword")
@ApiOperation(value = "Reset password", notes = "User must have the ORGANIZATION_USER[UPDATE] permission on the specified organization")
@ApiResponses({ @ApiResponse(code = 200, message = "Password reset"), @ApiResponse(code = 500, message = "Internal server error") })
public void resetPassword(@PathParam("organizationId") String organizationId, @PathParam("user") String user, @ApiParam(name = "password", required = true) @Valid @NotNull PasswordValue password, @Suspended final AsyncResponse response) {
    final io.gravitee.am.identityprovider.api.User authenticatedUser = getAuthenticatedUser();
    checkPermission(ReferenceType.ORGANIZATION, organizationId, Permission.ORGANIZATION_USER, Acl.UPDATE).andThen(organizationUserService.findById(ReferenceType.ORGANIZATION, organizationId, user).filter(existingUser -> IdentityProviderManagerImpl.IDP_GRAVITEE.equals(existingUser.getSource())).switchIfEmpty(Maybe.error(new UserInvalidException("Unable to reset password"))).flatMapCompletable(existingUser -> organizationUserService.resetPassword(organizationId, existingUser, password.getPassword(), authenticatedUser))).subscribe(() -> response.resume(Response.noContent().build()), response::resume);
}
Also used : UserInvalidException(io.gravitee.am.service.exception.UserInvalidException) ApiParam(io.swagger.annotations.ApiParam) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

UserInvalidException (io.gravitee.am.service.exception.UserInvalidException)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 ApiResponses (io.swagger.annotations.ApiResponses)1