@Test public void shouldFailToUpdateCallbackFromRequestWhenHttpAuthorizationIsEmptyString() throws RestAuthCallbackHandlerResponseException { HttpHeaders headers = mock(HttpHeaders.class); HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpCallback httpCallback = mock(HttpCallback.class); given(request.getParameter("httpAuthorization")).willReturn(""); given(httpCallback.getNegotiationHeaderName()).willReturn("WWW-Authenticate"); given(httpCallback.getNegotiationHeaderValue()).willReturn("Negotiate"); boolean exceptionCaught = false; RestAuthCallbackHandlerResponseException exception = null; try { restAuthHttpCallbackHandler.updateCallbackFromRequest(headers, request, response, httpCallback); } catch (RestAuthCallbackHandlerResponseException e) { exceptionCaught = true; exception = e; } assertTrue(exceptionCaught); assertEquals(exception.getResponseStatus(), Response.Status.UNAUTHORIZED); assertEquals(exception.getResponseHeaders().size(), 1); assertTrue(exception.getResponseHeaders().containsKey("WWW-Authenticate")); assertTrue(exception.getResponseHeaders().containsValue("Negotiate")); assertEquals(exception.getJsonResponse().get("failure").asBoolean(), (Boolean) true); assertEquals(exception.getJsonResponse().get("reason").asString(), "http-auth-failed"); }
public boolean updateCallbackFromRequest(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, HttpCallback callback) throws RestAuthCallbackHandlerResponseException { String httpAuthorization = request.getHeader(callback.getAuthorizationHeader()); if (httpAuthorization == null || "".equals(httpAuthorization)) { DEBUG.message("Authorization Header not set in request."); JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("failure", true) .put("reason", HTTP_AUTH_FAILED) .build(); Map<String, String> responseHeaders = new HashMap<String, String>(); responseHeaders.put(callback.getNegotiationHeaderName(), callback.getNegotiationHeaderValue()); throw new RestAuthCallbackHandlerResponseException(Response.Status.UNAUTHORIZED, responseHeaders, jsonValue); } callback.setAuthorization(httpAuthorization); return true; }
RestAuthHttpCallbackHandler extends AbstractRestAuthCallbackHandler<HttpCallback> { public boolean updateCallbackFromRequest(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, HttpCallback callback) throws RestAuthCallbackHandlerResponseException { String httpAuthorization = request.getHeader(callback.getAuthorizationHeader()); if (httpAuthorization == null || "".equals(httpAuthorization)) { DEBUG.message("Authorization Header not set in request."); JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("failure", true) .put("reason", HTTP_AUTH_FAILED) .build(); Map<String, String> responseHeaders = new HashMap<String, String>(); responseHeaders.put(callback.getNegotiationHeaderName(), callback.getNegotiationHeaderValue()); throw new RestAuthCallbackHandlerResponseException(Response.Status.UNAUTHORIZED, responseHeaders, jsonValue); } callback.setAuthorization(httpAuthorization); return true; } }
RestAuthHttpCallbackHandler extends AbstractRestAuthCallbackHandler<HttpCallback> { public boolean updateCallbackFromRequest(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, HttpCallback callback) throws RestAuthCallbackHandlerResponseException { String httpAuthorization = request.getHeader(callback.getAuthorizationHeader()); if (httpAuthorization == null || "".equals(httpAuthorization)) { DEBUG.message("Authorization Header not set in request."); JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("failure", true) .put("reason", HTTP_AUTH_FAILED) .build(); Map<String, String> responseHeaders = new HashMap<String, String>(); responseHeaders.put(callback.getNegotiationHeaderName(), callback.getNegotiationHeaderValue()); throw new RestAuthCallbackHandlerResponseException(Response.Status.UNAUTHORIZED, responseHeaders, jsonValue); } callback.setAuthorization(httpAuthorization); return true; }  }
RestAuthHttpCallbackHandler extends AbstractRestAuthCallbackHandler<HttpCallback> { public boolean updateCallbackFromRequest(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, HttpCallback callback) throws RestAuthCallbackHandlerResponseException { String httpAuthorization = request.getHeader(callback.getAuthorizationHeader()); if (httpAuthorization == null || "".equals(httpAuthorization)) { DEBUG.message("Authorization Header not set in request."); JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("failure", true) .put("reason", HTTP_AUTH_FAILED) .build(); Map<String, String> responseHeaders = new HashMap<String, String>(); responseHeaders.put(callback.getNegotiationHeaderName(), callback.getNegotiationHeaderValue()); throw new RestAuthCallbackHandlerResponseException(Response.Status.UNAUTHORIZED, responseHeaders, jsonValue); } callback.setAuthorization(httpAuthorization); return true; }  boolean updateCallbackFromRequest(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, HttpCallback callback); HttpCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, HttpCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(HttpCallback callback, int index); HttpCallback convertFromJson(HttpCallback callback, JsonValue jsonCallback); }
RestAuthHttpCallbackHandler extends AbstractRestAuthCallbackHandler<HttpCallback> { public boolean updateCallbackFromRequest(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response, HttpCallback callback) throws RestAuthCallbackHandlerResponseException { String httpAuthorization = request.getHeader(callback.getAuthorizationHeader()); if (httpAuthorization == null || "".equals(httpAuthorization)) { DEBUG.message("Authorization Header not set in request."); JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("failure", true) .put("reason", HTTP_AUTH_FAILED) .build(); Map<String, String> responseHeaders = new HashMap<String, String>(); responseHeaders.put(callback.getNegotiationHeaderName(), callback.getNegotiationHeaderValue()); throw new RestAuthCallbackHandlerResponseException(Response.Status.UNAUTHORIZED, responseHeaders, jsonValue); } callback.setAuthorization(httpAuthorization); return true; }  boolean updateCallbackFromRequest(HttpHeaders headers, HttpServletRequest request,
            HttpServletResponse response, HttpCallback callback); HttpCallback handle(HttpHeaders headers, HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, HttpCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(HttpCallback callback, int index); HttpCallback convertFromJson(HttpCallback callback, JsonValue jsonCallback);  }