@Test public void verifyToken() throws Exception { LoginToken loginToken = LoginToken.withAccessToken("access").build(); when(authentication.verifyToken(TOKENHEADER)).thenReturn(loginToken); Response response = authenticationResource.verifyToken(TOKENHEADER); assert (loginToken.equals(response.getEntity())); }
@GET @Path("/verifyToken") @Produces(APPLICATION_JSON) @ApiOperation(value = "Verify user's authorization") @Timed public Response verifyToken( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String tokenHeader) { try { return httpHeader.headers().entity(authentication.verifyToken(tokenHeader)).build(); } catch (Exception exception) { LOGGER.error("verifyToken failed with error:", exception); throw exception; } }
AuthenticationResource { @GET @Path("/verifyToken") @Produces(APPLICATION_JSON) @ApiOperation(value = "Verify user's authorization") @Timed public Response verifyToken( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String tokenHeader) { try { return httpHeader.headers().entity(authentication.verifyToken(tokenHeader)).build(); } catch (Exception exception) { LOGGER.error("verifyToken failed with error:", exception); throw exception; } } }
AuthenticationResource { @GET @Path("/verifyToken") @Produces(APPLICATION_JSON) @ApiOperation(value = "Verify user's authorization") @Timed public Response verifyToken( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String tokenHeader) { try { return httpHeader.headers().entity(authentication.verifyToken(tokenHeader)).build(); } catch (Exception exception) { LOGGER.error("verifyToken failed with error:", exception); throw exception; } } @Inject  AuthenticationResource(final Authentication authentication, final HttpHeader httpHeader,
                           final Authorization authorization,
                           final @Named(RATE_LIMIT_ENABLED) Boolean rateLimitEnabled,
                           final @Named(RATE_HOURLY_LIMIT) Integer rateHourlyLimit); }
AuthenticationResource { @GET @Path("/verifyToken") @Produces(APPLICATION_JSON) @ApiOperation(value = "Verify user's authorization") @Timed public Response verifyToken( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String tokenHeader) { try { return httpHeader.headers().entity(authentication.verifyToken(tokenHeader)).build(); } catch (Exception exception) { LOGGER.error("verifyToken failed with error:", exception); throw exception; } } @Inject  AuthenticationResource(final Authentication authentication, final HttpHeader httpHeader,
                           final Authorization authorization,
                           final @Named(RATE_LIMIT_ENABLED) Boolean rateLimitEnabled,
                           final @Named(RATE_HOURLY_LIMIT) Integer rateHourlyLimit); @POST @Path("/login") @Consumes(APPLICATION_FORM_URLENCODED) @Produces(APPLICATION_JSON) @ApiOperation(value = "Log a user in") @Timed Response logUserIn(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader,

            @FormParam("grant_type")
            @DefaultValue("client_credentials")
            @ApiParam(value = "please enter client_credentials in this field")
            final String grantType); @GET @Path("/verifyToken") @Produces(APPLICATION_JSON) @ApiOperation(value = "Verify user's authorization") @Timed Response verifyToken(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String tokenHeader); @GET @Path("/logout") @Produces(APPLICATION_JSON) @ApiOperation(value = "Log a user out") @Timed Response logUserOut(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String tokenHeader); @GET @Path("/users/{userEmail}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Check if user exists using user's email") @Timed Response getUserExists(
            @PathParam("userEmail")
            @ApiParam(value = "Email of the user")
            final String userEmail,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader); }
AuthenticationResource { @GET @Path("/verifyToken") @Produces(APPLICATION_JSON) @ApiOperation(value = "Verify user's authorization") @Timed public Response verifyToken( @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) final String tokenHeader) { try { return httpHeader.headers().entity(authentication.verifyToken(tokenHeader)).build(); } catch (Exception exception) { LOGGER.error("verifyToken failed with error:", exception); throw exception; } } @Inject  AuthenticationResource(final Authentication authentication, final HttpHeader httpHeader,
                           final Authorization authorization,
                           final @Named(RATE_LIMIT_ENABLED) Boolean rateLimitEnabled,
                           final @Named(RATE_HOURLY_LIMIT) Integer rateHourlyLimit); @POST @Path("/login") @Consumes(APPLICATION_FORM_URLENCODED) @Produces(APPLICATION_JSON) @ApiOperation(value = "Log a user in") @Timed Response logUserIn(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader,

            @FormParam("grant_type")
            @DefaultValue("client_credentials")
            @ApiParam(value = "please enter client_credentials in this field")
            final String grantType); @GET @Path("/verifyToken") @Produces(APPLICATION_JSON) @ApiOperation(value = "Verify user's authorization") @Timed Response verifyToken(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String tokenHeader); @GET @Path("/logout") @Produces(APPLICATION_JSON) @ApiOperation(value = "Log a user out") @Timed Response logUserOut(
            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String tokenHeader); @GET @Path("/users/{userEmail}") @Produces(APPLICATION_JSON) @ApiOperation(value = "Check if user exists using user's email") @Timed Response getUserExists(
            @PathParam("userEmail")
            @ApiParam(value = "Email of the user")
            final String userEmail,

            @HeaderParam(AUTHORIZATION)
            @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true)
            final String authorizationHeader);  }