Ejemplo n.º 1
0
  @GET
  @Path("/{id}")
  @RolesAllowed({"ADMINISTRATOR"})
  public Response find(@PathParam("id") final Long id) {
    logger.debug("Find user by id: {}", id);
    Response.ResponseBuilder responseBuilder;
    try {
      User user = userService.find(id);
      OperationResult result =
          OperationResult.success(userJsonConverter.convertToJsonElement(user));
      responseBuilder =
          Response.status(HttpCode.OK.getCode()).entity(OperationResultJsonWriter.toJson(result));
      logger.debug("User found by id: {}", user);
    } catch (UserNotFoundException e) {
      logger.error("No user found for id", id);
      responseBuilder = Response.status(HttpCode.NOT_FOUND.getCode());
    }

    return responseBuilder.build();
  }
Ejemplo n.º 2
0
  @POST
  @Path("/authenticate")
  @PermitAll
  public Response findByEmailAndPassword(final String body) {
    logger.debug("Find user by email and password");
    Response.ResponseBuilder responseBuilder;
    try {
      User userWithEmailAndPassword = getUserWithEmailAndPasswordFromJson(body);
      User user =
          userService.find(
              userWithEmailAndPassword.getEmail(), userWithEmailAndPassword.getPassword());
      OperationResult result =
          OperationResult.success(userJsonConverter.convertToJsonElement(user));
      responseBuilder =
          Response.status(HttpCode.OK.getCode()).entity(OperationResultJsonWriter.toJson(result));
      logger.debug("User found by email/password: {}", user);
    } catch (UserNotFoundException e) {
      logger.error("No user found for email/password");
      responseBuilder = Response.status(HttpCode.NOT_FOUND.getCode());
    }

    return responseBuilder.build();
  }