List of usage examples for io.netty.handler.codec.http HttpHeaderNames WWW_AUTHENTICATE
AsciiString WWW_AUTHENTICATE
To view the source code for io.netty.handler.codec.http HttpHeaderNames WWW_AUTHENTICATE.
Click Source Link
From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpBlobStore.java
License:Open Source License
/** See https://tools.ietf.org/html/rfc6750#section-3.1 */ private boolean authTokenExpired(HttpResponse response) { synchronized (credentialsLock) { if (creds == null) { return false; }// w w w . jav a 2 s .c o m } List<String> values = response.headers().getAllAsString(HttpHeaderNames.WWW_AUTHENTICATE); String value = String.join(",", values); if (value != null && value.startsWith("Bearer")) { return INVALID_TOKEN_ERROR.matcher(value).find(); } else { return response.status().equals(HttpResponseStatus.UNAUTHORIZED); } }
From source file:io.crate.protocols.http.HttpAuthUpstreamHandler.java
@VisibleForTesting static void sendUnauthorized(Channel channel, @Nullable String body) { LOGGER.warn(body == null ? "unauthorized http chunk" : body); HttpResponse response;/*from w w w . ja v a 2s .c o m*/ if (body != null) { if (!body.endsWith("\n")) { body += "\n"; } response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED, copiedBuffer(body, StandardCharsets.UTF_8)); HttpUtil.setContentLength(response, body.length()); } else { response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED); } // "Tell" the browser to open the credentials popup // It helps to avoid custom login page in AdminUI response.headers().set(HttpHeaderNames.WWW_AUTHENTICATE, WWW_AUTHENTICATE_REALM_MESSAGE); channel.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE); }
From source file:io.crate.protocols.http.HttpAuthUpstreamHandlerTest.java
private static void assertUnauthorized(DefaultFullHttpResponse resp, String expectedBody) { assertThat(resp.status(), is(HttpResponseStatus.UNAUTHORIZED)); assertThat(resp.content().toString(StandardCharsets.UTF_8), is(expectedBody)); assertThat(resp.headers().get(HttpHeaderNames.WWW_AUTHENTICATE), is(WWW_AUTHENTICATE_REALM_MESSAGE)); }