@Test public void shouldFailToAuthenticateViaPOSTWhenContentTypeHeaderNotSet() { HttpHeaders headers = mock(HttpHeaders.class); Response resp = authenticationRestService.authenticate(headers, null, null, null, null, null, null); assertEquals(resp.getStatus(), 415); JsonValue jsonValue = JsonValueBuilder.toJsonValue((String) resp.getEntity()); assertTrue(jsonValue.isDefined("errorMessage")); }
@POST @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response authenticate(@Context HttpHeaders headers, @Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("authIndexType") String authIndexType, @QueryParam("authIndexValue") String authIndexValue, @QueryParam("sessionUpgrade") String sessionUpgradeSSOTokenId, String postBody) { if (!isJsonContentType(headers)) { return new RestAuthException(Response.Status.UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type") .getResponse(); } JsonValue jsonBody = null; if (StringUtils.isNotEmpty(postBody)) { jsonBody = JsonValueBuilder.toJsonValue(postBody); } if (jsonBody != null && jsonBody.size() > 0) { return restAuthenticationHandler.continueAuthentication(headers, request, response, jsonBody, sessionUpgradeSSOTokenId); } else { return restAuthenticationHandler.initiateAuthentication(headers, request, response, authIndexType, authIndexValue, sessionUpgradeSSOTokenId); } }
AuthenticationRestService { @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response authenticate(@Context HttpHeaders headers, @Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("authIndexType") String authIndexType, @QueryParam("authIndexValue") String authIndexValue, @QueryParam("sessionUpgrade") String sessionUpgradeSSOTokenId, String postBody) { if (!isJsonContentType(headers)) { return new RestAuthException(Response.Status.UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type") .getResponse(); } JsonValue jsonBody = null; if (StringUtils.isNotEmpty(postBody)) { jsonBody = JsonValueBuilder.toJsonValue(postBody); } if (jsonBody != null && jsonBody.size() > 0) { return restAuthenticationHandler.continueAuthentication(headers, request, response, jsonBody, sessionUpgradeSSOTokenId); } else { return restAuthenticationHandler.initiateAuthentication(headers, request, response, authIndexType, authIndexValue, sessionUpgradeSSOTokenId); } } }
AuthenticationRestService { @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response authenticate(@Context HttpHeaders headers, @Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("authIndexType") String authIndexType, @QueryParam("authIndexValue") String authIndexValue, @QueryParam("sessionUpgrade") String sessionUpgradeSSOTokenId, String postBody) { if (!isJsonContentType(headers)) { return new RestAuthException(Response.Status.UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type") .getResponse(); } JsonValue jsonBody = null; if (StringUtils.isNotEmpty(postBody)) { jsonBody = JsonValueBuilder.toJsonValue(postBody); } if (jsonBody != null && jsonBody.size() > 0) { return restAuthenticationHandler.continueAuthentication(headers, request, response, jsonBody, sessionUpgradeSSOTokenId); } else { return restAuthenticationHandler.initiateAuthentication(headers, request, response, authIndexType, authIndexValue, sessionUpgradeSSOTokenId); } } AuthenticationRestService();  AuthenticationRestService(RestAuthenticationHandler restAuthenticationHandler); }
AuthenticationRestService { @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response authenticate(@Context HttpHeaders headers, @Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("authIndexType") String authIndexType, @QueryParam("authIndexValue") String authIndexValue, @QueryParam("sessionUpgrade") String sessionUpgradeSSOTokenId, String postBody) { if (!isJsonContentType(headers)) { return new RestAuthException(Response.Status.UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type") .getResponse(); } JsonValue jsonBody = null; if (StringUtils.isNotEmpty(postBody)) { jsonBody = JsonValueBuilder.toJsonValue(postBody); } if (jsonBody != null && jsonBody.size() > 0) { return restAuthenticationHandler.continueAuthentication(headers, request, response, jsonBody, sessionUpgradeSSOTokenId); } else { return restAuthenticationHandler.initiateAuthentication(headers, request, response, authIndexType, authIndexValue, sessionUpgradeSSOTokenId); } } AuthenticationRestService();  AuthenticationRestService(RestAuthenticationHandler restAuthenticationHandler); @GET @Path("/") @Produces(MediaType.APPLICATION_JSON) Response getMethodNotSupported(); @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) Response authenticate(@Context HttpHeaders headers, @Context HttpServletRequest request,
            @Context HttpServletResponse response, @QueryParam("authIndexType") String authIndexType,
            @QueryParam("authIndexValue") String authIndexValue,
            @QueryParam("sessionUpgrade") String sessionUpgradeSSOTokenId, String postBody); }
AuthenticationRestService { @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) public Response authenticate(@Context HttpHeaders headers, @Context HttpServletRequest request, @Context HttpServletResponse response, @QueryParam("authIndexType") String authIndexType, @QueryParam("authIndexValue") String authIndexValue, @QueryParam("sessionUpgrade") String sessionUpgradeSSOTokenId, String postBody) { if (!isJsonContentType(headers)) { return new RestAuthException(Response.Status.UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type") .getResponse(); } JsonValue jsonBody = null; if (StringUtils.isNotEmpty(postBody)) { jsonBody = JsonValueBuilder.toJsonValue(postBody); } if (jsonBody != null && jsonBody.size() > 0) { return restAuthenticationHandler.continueAuthentication(headers, request, response, jsonBody, sessionUpgradeSSOTokenId); } else { return restAuthenticationHandler.initiateAuthentication(headers, request, response, authIndexType, authIndexValue, sessionUpgradeSSOTokenId); } } AuthenticationRestService();  AuthenticationRestService(RestAuthenticationHandler restAuthenticationHandler); @GET @Path("/") @Produces(MediaType.APPLICATION_JSON) Response getMethodNotSupported(); @POST @Path("/") @Produces(MediaType.APPLICATION_JSON) Response authenticate(@Context HttpHeaders headers, @Context HttpServletRequest request,
            @Context HttpServletResponse response, @QueryParam("authIndexType") String authIndexType,
            @QueryParam("authIndexValue") String authIndexValue,
            @QueryParam("sessionUpgrade") String sessionUpgradeSSOTokenId, String postBody);  }