class LoginResource {

  @Path("/login")
  @POST
  public void login(
      @FormParam("username") String username,
      @FormParam("password") String password,
      @FormParam("rememberMe") boolean rememberMe,
      @Auth Subject subject) throws IOException {

    ensurePresent(username, "Invalid credentials: missing username.");
    ensurePresent(password, "Invalid credentials: missing password.");

    try {
      subject.login(new UsernamePasswordToken(username, password, rememberMe));
    } catch (AuthenticationException e) {
      throw new IncorrectCredentialsException("Invalid credentials combination for user: " + username);
    }
  }

}