@Test public void buildResponse() throws Exception { JsonUnauthorizedHandler handler = new JsonUnauthorizedHandler(); Response response = handler.buildResponse("Basic", "TestRealm"); assertEquals(401, response.getStatus()); assertEquals("application/json", response.getMediaType().toString()); assertEquals("Credentials are required to access this resource.", ((Map<String,Object>)response.getEntity()).get("error")); }
@Override public Response buildResponse(String prefix, String realm) { return Response.status(Response.Status.UNAUTHORIZED) .header(HttpHeaders.WWW_AUTHENTICATE, String.format(CHALLENGE_FORMAT, prefix, realm)) .type(MediaType.APPLICATION_JSON_TYPE) .entity(ImmutableMap.of("error", "Credentials are required to access this resource.")) .build(); }
JsonUnauthorizedHandler implements UnauthorizedHandler { @Override public Response buildResponse(String prefix, String realm) { return Response.status(Response.Status.UNAUTHORIZED) .header(HttpHeaders.WWW_AUTHENTICATE, String.format(CHALLENGE_FORMAT, prefix, realm)) .type(MediaType.APPLICATION_JSON_TYPE) .entity(ImmutableMap.of("error", "Credentials are required to access this resource.")) .build(); } }
JsonUnauthorizedHandler implements UnauthorizedHandler { @Override public Response buildResponse(String prefix, String realm) { return Response.status(Response.Status.UNAUTHORIZED) .header(HttpHeaders.WWW_AUTHENTICATE, String.format(CHALLENGE_FORMAT, prefix, realm)) .type(MediaType.APPLICATION_JSON_TYPE) .entity(ImmutableMap.of("error", "Credentials are required to access this resource.")) .build(); }  }
JsonUnauthorizedHandler implements UnauthorizedHandler { @Override public Response buildResponse(String prefix, String realm) { return Response.status(Response.Status.UNAUTHORIZED) .header(HttpHeaders.WWW_AUTHENTICATE, String.format(CHALLENGE_FORMAT, prefix, realm)) .type(MediaType.APPLICATION_JSON_TYPE) .entity(ImmutableMap.of("error", "Credentials are required to access this resource.")) .build(); }  @Override Response buildResponse(String prefix, String realm); }
JsonUnauthorizedHandler implements UnauthorizedHandler { @Override public Response buildResponse(String prefix, String realm) { return Response.status(Response.Status.UNAUTHORIZED) .header(HttpHeaders.WWW_AUTHENTICATE, String.format(CHALLENGE_FORMAT, prefix, realm)) .type(MediaType.APPLICATION_JSON_TYPE) .entity(ImmutableMap.of("error", "Credentials are required to access this resource.")) .build(); }  @Override Response buildResponse(String prefix, String realm);  }