AuthRest { @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation("Gets the current user token") public Response getCurrentUser(@Context ContainerRequestContext context) { String token = tokenManager.getTokenString(context); Optional<SignedJWT> tokenOptional = tokenManager.verifyToken(token); if (tokenOptional.isPresent()) { log.debug("Token found and verified."); log.debug("Writing payload to response."); SignedJWT signedToken = tokenOptional.get(); return Response.ok(signedToken.getPayload().toString()).build(); } else { log.debug("Token missing or unverified. Generating unauthenticated token."); SignedJWT signedToken = tokenManager.generateUnauthToken(); log.debug("Writing payload to response."); return createResponse(signedToken); } }  @GET @Produces(MediaType.APPLICATION_JSON) @ApiOperation("Gets the current user token") Response getCurrentUser(@Context ContainerRequestContext context); @POST @Produces(MediaType.APPLICATION_JSON) @ApiOperation("Logs in into Mobi creating a new token") Response login(@Context ContainerRequestContext context,
                   @QueryParam("username") String username,
                   @QueryParam("password") String password); @DELETE @Produces(MediaType.APPLICATION_JSON) @ApiOperation("Logs out of Mobi by setting unauth token") Response logout();  }
@Test public void getCurrentUserTest() throws Exception { Response response = target().path("session").request().get(); assertEquals(response.getStatus(), 200); verify(tokenManager).getTokenString(any(ContainerRequestContext.class)); verify(tokenManager).verifyToken(TOKEN_STRING); verify(tokenManager, never()).generateUnauthToken(); Map<String, NewCookie> cookies = response.getCookies(); assertEquals(0, cookies.size()); try { JSONObject result = JSONObject.fromObject(response.readEntity(String.class)); assertEquals(removeWhitespace(VALID_USER), removeWhitespace(result.toString())); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }