Example usage for io.netty.handler.codec.http HttpHeaderNames AUTHORIZATION

List of usage examples for io.netty.handler.codec.http HttpHeaderNames AUTHORIZATION

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpHeaderNames AUTHORIZATION.

Prototype

AsciiString AUTHORIZATION

To view the source code for io.netty.handler.codec.http HttpHeaderNames AUTHORIZATION.

Click Source Link

Document

"authorization"

Usage

From source file:com.chiorichan.http.HttpAuthenticator.java

License:Mozilla Public License

public String getAuthorization() {
    if (cached == null)
        cached = request.getHeader(HttpHeaderNames.AUTHORIZATION);
    return cached;
}

From source file:com.chiorichan.http.HttpRequestWrapper.java

License:Mozilla Public License

private void initAuthorization() {
    if (auth == null && getHeader(HttpHeaderNames.AUTHORIZATION) != null)
        auth = new HttpAuthenticator(this);
}

From source file:com.google.devtools.build.lib.remote.blobstore.http.AbstractHttpHandler.java

License:Open Source License

protected void addCredentialHeaders(HttpRequest request, URI uri) throws IOException {
    String userInfo = uri.getUserInfo();
    if (userInfo != null) {
        String value = BaseEncoding.base64Url().encode(userInfo.getBytes(Charsets.UTF_8));
        request.headers().set(HttpHeaderNames.AUTHORIZATION, "Basic " + value);
        return;/*from   w  ww . j  a  va2  s.c o m*/
    }
    if (credentials == null || !credentials.hasRequestMetadata()) {
        return;
    }
    Map<String, List<String>> authHeaders = credentials.getRequestMetadata(uri);
    if (authHeaders == null || authHeaders.isEmpty()) {
        return;
    }
    for (Map.Entry<String, List<String>> entry : authHeaders.entrySet()) {
        String name = entry.getKey();
        for (String value : entry.getValue()) {
            request.headers().add(name, value);
        }
    }
}

From source file:com.google.devtools.build.lib.remote.blobstore.http.AbstractHttpHandlerTest.java

License:Open Source License

@Test
public void basicAuthShouldWork() throws Exception {
    URI uri = new URI("http://user:password@does.not.exist/foo");
    EmbeddedChannel ch = new EmbeddedChannel(new HttpDownloadHandler(null));
    ByteArrayOutputStream out = Mockito.spy(new ByteArrayOutputStream());
    DownloadCommand cmd = new DownloadCommand(uri, true, "abcdef", new ByteArrayOutputStream());
    ChannelPromise writePromise = ch.newPromise();
    ch.writeOneOutbound(cmd, writePromise);

    HttpRequest request = ch.readOutbound();
    assertThat(request.headers().get(HttpHeaderNames.AUTHORIZATION)).isEqualTo("Basic dXNlcjpwYXNzd29yZA==");
}

From source file:com.google.devtools.build.lib.remote.blobstore.http.AbstractHttpHandlerTest.java

License:Open Source License

@Test
public void basicAuthShouldNotEnabled() throws Exception {
    URI uri = new URI("http://does.not.exist/foo");
    EmbeddedChannel ch = new EmbeddedChannel(new HttpDownloadHandler(null));
    ByteArrayOutputStream out = Mockito.spy(new ByteArrayOutputStream());
    DownloadCommand cmd = new DownloadCommand(uri, true, "abcdef", new ByteArrayOutputStream());
    ChannelPromise writePromise = ch.newPromise();
    ch.writeOneOutbound(cmd, writePromise);

    HttpRequest request = ch.readOutbound();
    assertThat(request.headers().contains(HttpHeaderNames.AUTHORIZATION)).isFalse();
}

From source file:discord4j.rest.http.client.ClientException.java

License:Open Source License

@Override
public String toString() {
    return "ClientException{" + "request=" + request + ", status=" + status + ", headers="
            + headers.copy().remove(HttpHeaderNames.AUTHORIZATION).toString() + ", errorResponse="
            + errorResponse + "}";
}

From source file:discord4j.rest.http.client.ClientRequest.java

License:Open Source License

@Override
public String toString() {
    return "ClientRequest{" + "method=" + getMethod() + ", url='" + url + '\'' + ", headers="
            + headers.copy().remove(HttpHeaderNames.AUTHORIZATION).toString() + '}';
}

From source file:discord4j.rest.http.client.DiscordWebClient.java

License:Open Source License

/**
 * Create a new {@link DiscordWebClient} wrapping HTTP, Discord and encoding/decoding resources.
 *
 * @param httpClient a Reactor Netty HTTP client
 * @param exchangeStrategies a strategy to transform requests and responses
 * @param token a Discord token for API authorization
 *//*from ww  w  .j  ava 2  s.  c om*/
public DiscordWebClient(HttpClient httpClient, ExchangeStrategies exchangeStrategies, String token) {
    final Properties properties = GitProperties.getProperties();
    final String version = properties.getProperty(GitProperties.APPLICATION_VERSION, "3");
    final String url = properties.getProperty(GitProperties.APPLICATION_URL, "https://discord4j.com");

    final HttpHeaders defaultHeaders = new DefaultHttpHeaders();
    defaultHeaders.add(HttpHeaderNames.CONTENT_TYPE, "application/json");
    defaultHeaders.add(HttpHeaderNames.AUTHORIZATION, "Bot " + token);
    defaultHeaders.add(HttpHeaderNames.USER_AGENT, "DiscordBot(" + url + ", " + version + ")");

    this.httpClient = httpClient;
    this.defaultHeaders = defaultHeaders;
    this.exchangeStrategies = exchangeStrategies;
}

From source file:io.crate.protocols.http.HttpAuthUpstreamHandler.java

@VisibleForTesting
static Tuple<String, SecureString> credentialsFromRequest(HttpRequest request, @Nullable SSLSession session,
        Settings settings) {//from w w  w  .  j  a  v  a 2s  . c o m
    String username = null;
    if (request.headers().contains(HttpHeaderNames.AUTHORIZATION.toString())) {
        // Prefer Http Basic Auth
        return CrateRestMainAction.extractCredentialsFromHttpBasicAuthHeader(
                request.headers().get(HttpHeaderNames.AUTHORIZATION.toString()));
    } else {
        // prefer commonName as userName over AUTH_TRUST_HTTP_DEFAULT_HEADER user
        if (session != null) {
            try {
                Certificate certificate = session.getPeerCertificates()[0];
                username = SSL.extractCN(certificate);
            } catch (ArrayIndexOutOfBoundsException | SSLPeerUnverifiedException ignored) {
                // client cert is optional
            }
        }
        if (username == null) {
            username = AuthSettings.AUTH_TRUST_HTTP_DEFAULT_HEADER.setting().get(settings);
        }
    }
    return new Tuple<>(username, null);
}

From source file:io.crate.protocols.http.HttpAuthUpstreamHandlerTest.java

@Test
public void testNotNoHbaConfig() throws Exception {
    HttpAuthUpstreamHandler handler = new HttpAuthUpstreamHandler(Settings.EMPTY, authService);
    EmbeddedChannel ch = new EmbeddedChannel(handler);

    DefaultHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/_sql");
    request.headers().add(HttpHeaderNames.AUTHORIZATION.toString(), "Basic QWxhZGRpbjpPcGVuU2VzYW1l");
    request.headers().add("X-Real-Ip", "10.1.0.100");

    ch.writeInbound(request);/*from   ww  w . jav  a2s. c  om*/
    assertFalse(handler.authorized());

    assertUnauthorized(ch.readOutbound(),
            "No valid auth.host_based.config entry found for host \"10.1.0.100\", user \"Aladdin\", protocol \"http\"\n");
}