@Test public void testGetUserFromToken() throws Exception { Credentials user = signUpUser(this); String token = user.getAuthToken(); token = URLEncoder.encode(token, "UTF-8"); int status = target("/auth/from/").path(token).request().buildGet().invoke().getStatus(); assertEquals(200,status); }
@GET @Path("/from/{token}") @Produces(MediaType.APPLICATION_JSON) public Response getUserFromToken(@Context ContainerRequestContext context, @PathParam("token") String token) { try{ logger.warning("getUserFromToken"); Credentials user = authServerLogic.getUserFromAuthToken(token); context.setSecurityContext(new UserContext(context.getUriInfo(),user)); return Response.ok(user).build(); }catch (ServerDAO.DAOException e) { e.printStackTrace(); logger.severe(ExceptionUtils.getStackTrace(e)); return fromDAOExpection(e); } }
AuthenticationEndpoint { @GET @Path("/from/{token}") @Produces(MediaType.APPLICATION_JSON) public Response getUserFromToken(@Context ContainerRequestContext context, @PathParam("token") String token) { try{ logger.warning("getUserFromToken"); Credentials user = authServerLogic.getUserFromAuthToken(token); context.setSecurityContext(new UserContext(context.getUriInfo(),user)); return Response.ok(user).build(); }catch (ServerDAO.DAOException e) { e.printStackTrace(); logger.severe(ExceptionUtils.getStackTrace(e)); return fromDAOExpection(e); } } }
AuthenticationEndpoint { @GET @Path("/from/{token}") @Produces(MediaType.APPLICATION_JSON) public Response getUserFromToken(@Context ContainerRequestContext context, @PathParam("token") String token) { try{ logger.warning("getUserFromToken"); Credentials user = authServerLogic.getUserFromAuthToken(token); context.setSecurityContext(new UserContext(context.getUriInfo(),user)); return Response.ok(user).build(); }catch (ServerDAO.DAOException e) { e.printStackTrace(); logger.severe(ExceptionUtils.getStackTrace(e)); return fromDAOExpection(e); } }  }
AuthenticationEndpoint { @GET @Path("/from/{token}") @Produces(MediaType.APPLICATION_JSON) public Response getUserFromToken(@Context ContainerRequestContext context, @PathParam("token") String token) { try{ logger.warning("getUserFromToken"); Credentials user = authServerLogic.getUserFromAuthToken(token); context.setSecurityContext(new UserContext(context.getUriInfo(),user)); return Response.ok(user).build(); }catch (ServerDAO.DAOException e) { e.printStackTrace(); logger.severe(ExceptionUtils.getStackTrace(e)); return fromDAOExpection(e); } }  @PostConstruct void init(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response userSignUp(@Context ContainerRequestContext context, Credentials credentials); @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response userSignIn(@Context ContainerRequestContext context, Credentials credentials); @GET @Path("/key") @Produces(MediaType.APPLICATION_JSON) Response getPublicKey(); @GET @Path("/validate/{token}") @Produces(MediaType.APPLICATION_JSON) Response validateAccount(@PathParam("token") String token); @GET @Path("/from/{token}") @Produces(MediaType.APPLICATION_JSON) Response getUserFromToken(@Context ContainerRequestContext context, @PathParam("token") String token); @GET @Path("/recover/{token}") @Produces(MediaType.APPLICATION_JSON) Response recoverFromOneTimeToken(@Context ContainerRequestContext context, @PathParam("token") String token); @POST @Path("/user/data/{userId}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response recieveUserData(@Context Session session, @PathParam("userId") String userId, Map<String,?> data); @PUT @Path("/user/data/{userId}") @Produces(MediaType.APPLICATION_JSON) Response sendUserData(@Context Session session, @PathParam("userId") String userId); }
AuthenticationEndpoint { @GET @Path("/from/{token}") @Produces(MediaType.APPLICATION_JSON) public Response getUserFromToken(@Context ContainerRequestContext context, @PathParam("token") String token) { try{ logger.warning("getUserFromToken"); Credentials user = authServerLogic.getUserFromAuthToken(token); context.setSecurityContext(new UserContext(context.getUriInfo(),user)); return Response.ok(user).build(); }catch (ServerDAO.DAOException e) { e.printStackTrace(); logger.severe(ExceptionUtils.getStackTrace(e)); return fromDAOExpection(e); } }  @PostConstruct void init(); @POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response userSignUp(@Context ContainerRequestContext context, Credentials credentials); @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response userSignIn(@Context ContainerRequestContext context, Credentials credentials); @GET @Path("/key") @Produces(MediaType.APPLICATION_JSON) Response getPublicKey(); @GET @Path("/validate/{token}") @Produces(MediaType.APPLICATION_JSON) Response validateAccount(@PathParam("token") String token); @GET @Path("/from/{token}") @Produces(MediaType.APPLICATION_JSON) Response getUserFromToken(@Context ContainerRequestContext context, @PathParam("token") String token); @GET @Path("/recover/{token}") @Produces(MediaType.APPLICATION_JSON) Response recoverFromOneTimeToken(@Context ContainerRequestContext context, @PathParam("token") String token); @POST @Path("/user/data/{userId}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) Response recieveUserData(@Context Session session, @PathParam("userId") String userId, Map<String,?> data); @PUT @Path("/user/data/{userId}") @Produces(MediaType.APPLICATION_JSON) Response sendUserData(@Context Session session, @PathParam("userId") String userId);  }