Search in sources :

Example 1 with AUTHORIZATION

use of io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION in project cf-java-client by cloudfoundry.

the class ReactorServerInformation method getAuthenticationCode.

@Override
public Mono<GetAutoLoginAuthenticationCodeResponse> getAuthenticationCode(GetAutoLoginAuthenticationCodeRequest request) {
    return post(request, GetAutoLoginAuthenticationCodeResponse.class, builder -> builder.pathSegment("autologin"), outbound -> outbound.map(r -> {
        String encoded = Base64.getEncoder().encodeToString(new AsciiString(request.getClientId()).concat(":").concat(request.getClientSecret()).toByteArray());
        r.requestHeaders().set(AUTHORIZATION, BASIC_PREAMBLE + encoded);
        return r;
    })).checkpoint();
}
Also used : GetAutoLoginAuthenticationCodeResponse(org.cloudfoundry.uaa.serverinformation.GetAutoLoginAuthenticationCodeResponse) IdentityZones(org.cloudfoundry.uaa.identityzones.IdentityZones) AsciiString(io.netty.util.AsciiString) AutoLoginRequest(org.cloudfoundry.uaa.serverinformation.AutoLoginRequest) Mono(reactor.core.publisher.Mono) TokenProvider(org.cloudfoundry.reactor.TokenProvider) Base64(java.util.Base64) ServerInformation(org.cloudfoundry.uaa.serverinformation.ServerInformation) GetInfoResponse(org.cloudfoundry.uaa.serverinformation.GetInfoResponse) GetInfoRequest(org.cloudfoundry.uaa.serverinformation.GetInfoRequest) ConnectionContext(org.cloudfoundry.reactor.ConnectionContext) AbstractUaaOperations(org.cloudfoundry.reactor.uaa.AbstractUaaOperations) GetAutoLoginAuthenticationCodeRequest(org.cloudfoundry.uaa.serverinformation.GetAutoLoginAuthenticationCodeRequest) AUTHORIZATION(io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION) GetAutoLoginAuthenticationCodeResponse(org.cloudfoundry.uaa.serverinformation.GetAutoLoginAuthenticationCodeResponse) AsciiString(io.netty.util.AsciiString) AsciiString(io.netty.util.AsciiString)

Example 2 with AUTHORIZATION

use of io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION in project cf-java-client by cloudfoundry.

the class ReactorTokens method check.

@Override
public Mono<CheckTokenResponse> check(CheckTokenRequest request) {
    return post(request, CheckTokenResponse.class, builder -> builder.pathSegment("check_token"), outbound -> outbound.map(r -> {
        String encoded = Base64.getEncoder().encodeToString(new AsciiString(request.getClientId()).concat(":").concat(request.getClientSecret()).toByteArray());
        r.requestHeaders().set(AUTHORIZATION, BASIC_PREAMBLE + encoded);
        return r;
    })).checkpoint();
}
Also used : GetTokenByOneTimePasscodeRequest(org.cloudfoundry.uaa.tokens.GetTokenByOneTimePasscodeRequest) GetTokenKeyResponse(org.cloudfoundry.uaa.tokens.GetTokenKeyResponse) ResponseType(org.cloudfoundry.uaa.ResponseType) CLIENT_CREDENTIALS(org.cloudfoundry.uaa.tokens.GrantType.CLIENT_CREDENTIALS) AsciiString(io.netty.util.AsciiString) PASSWORD(org.cloudfoundry.uaa.tokens.GrantType.PASSWORD) GetTokenByAuthorizationCodeResponse(org.cloudfoundry.uaa.tokens.GetTokenByAuthorizationCodeResponse) GetTokenByAuthorizationCodeRequest(org.cloudfoundry.uaa.tokens.GetTokenByAuthorizationCodeRequest) GetTokenKeyRequest(org.cloudfoundry.uaa.tokens.GetTokenKeyRequest) GetTokenByClientCredentialsResponse(org.cloudfoundry.uaa.tokens.GetTokenByClientCredentialsResponse) GetTokenByOneTimePasscodeResponse(org.cloudfoundry.uaa.tokens.GetTokenByOneTimePasscodeResponse) AUTHORIZATION_CODE(org.cloudfoundry.uaa.tokens.GrantType.AUTHORIZATION_CODE) AbstractUaaOperations(org.cloudfoundry.reactor.uaa.AbstractUaaOperations) CheckTokenRequest(org.cloudfoundry.uaa.tokens.CheckTokenRequest) RefreshTokenResponse(org.cloudfoundry.uaa.tokens.RefreshTokenResponse) Mono(reactor.core.publisher.Mono) Tokens(org.cloudfoundry.uaa.tokens.Tokens) GetTokenByOpenIdResponse(org.cloudfoundry.uaa.tokens.GetTokenByOpenIdResponse) GetTokenByPasswordResponse(org.cloudfoundry.uaa.tokens.GetTokenByPasswordResponse) RefreshTokenRequest(org.cloudfoundry.uaa.tokens.RefreshTokenRequest) GetTokenByPasswordRequest(org.cloudfoundry.uaa.tokens.GetTokenByPasswordRequest) ListTokenKeysRequest(org.cloudfoundry.uaa.tokens.ListTokenKeysRequest) CheckTokenResponse(org.cloudfoundry.uaa.tokens.CheckTokenResponse) GetTokenByClientCredentialsRequest(org.cloudfoundry.uaa.tokens.GetTokenByClientCredentialsRequest) TokenProvider(org.cloudfoundry.reactor.TokenProvider) ListTokenKeysResponse(org.cloudfoundry.uaa.tokens.ListTokenKeysResponse) Base64(java.util.Base64) HttpClientRequest(reactor.ipc.netty.http.client.HttpClientRequest) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) APPLICATION_X_WWW_FORM_URLENCODED(io.netty.handler.codec.http.HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED) REFRESH_TOKEN(org.cloudfoundry.uaa.tokens.GrantType.REFRESH_TOKEN) ConnectionContext(org.cloudfoundry.reactor.ConnectionContext) GetTokenByOpenIdRequest(org.cloudfoundry.uaa.tokens.GetTokenByOpenIdRequest) AUTHORIZATION(io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION) AsciiString(io.netty.util.AsciiString) CheckTokenResponse(org.cloudfoundry.uaa.tokens.CheckTokenResponse) AsciiString(io.netty.util.AsciiString)

Example 3 with AUTHORIZATION

use of io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION in project ksql by confluentinc.

the class RestIntegrationTestUtil method rawRestRequest.

static VertxCompletableFuture<Void> rawRestRequest(final TestKsqlRestApp restApp, final HttpVersion httpVersion, final HttpMethod method, final String uri, final Object requestBody, final String mediaType, final Consumer<Buffer> chunkConsumer, final Optional<BasicCredentials> credentials) {
    final byte[] bytes;
    try {
        bytes = ApiJsonMapper.INSTANCE.get().writeValueAsBytes(requestBody);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    HttpClientOptions options = new HttpClientOptions().setDefaultPort(restApp.getHttpListener().getPort()).setDefaultHost(restApp.getHttpListener().getHost()).setVerifyHost(false);
    if (httpVersion == HttpVersion.HTTP_2) {
        options.setProtocolVersion(HttpVersion.HTTP_2);
    }
    final Vertx vertx = Vertx.vertx();
    final HttpClient httpClient = vertx.createHttpClient(options);
    final VertxCompletableFuture<Void> vcf = new VertxCompletableFuture<>();
    final HttpClientRequest httpClientRequest = httpClient.request(method, uri, resp -> {
        resp.handler(buffer -> {
            try {
                chunkConsumer.accept(buffer);
            } catch (final Throwable t) {
                vcf.completeExceptionally(t);
            }
        });
        resp.endHandler(v -> {
            chunkConsumer.accept(null);
            vcf.complete(null);
        });
    }).exceptionHandler(vcf::completeExceptionally);
    httpClientRequest.putHeader("Accept", mediaType);
    credentials.ifPresent(basicCredentials -> httpClientRequest.putHeader("Authorization", createBasicAuthHeader(basicCredentials)));
    Buffer bodyBuffer = Buffer.buffer(bytes);
    httpClientRequest.end(bodyBuffer);
    // cleanup
    vcf.handle((v, throwable) -> {
        httpClient.close();
        vertx.close();
        return null;
    });
    return vcf;
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) VertxCompletableFuture(io.confluent.ksql.util.VertxCompletableFuture) MultiMap(io.vertx.core.MultiMap) CommandStatuses(io.confluent.ksql.rest.entity.CommandStatuses) RestResponse(io.confluent.ksql.rest.client.RestResponse) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) HttpVersion(io.vertx.core.http.HttpVersion) ACCEPT(io.netty.handler.codec.http.HttpHeaderNames.ACCEPT) Map(java.util.Map) URI(java.net.URI) KsqlRequestConfig(io.confluent.ksql.util.KsqlRequestConfig) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) ImmutableMap(com.google.common.collect.ImmutableMap) TestKsqlRestApp(io.confluent.ksql.rest.server.TestKsqlRestApp) UrlEscapers(com.google.common.net.UrlEscapers) ApiJsonMapper(io.confluent.ksql.rest.ApiJsonMapper) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) Buffer(io.vertx.core.buffer.Buffer) Status(io.confluent.ksql.rest.entity.CommandStatus.Status) Optional(java.util.Optional) CONTENT_TYPE(io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) AUTHORIZATION(io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION) HttpClient(io.vertx.core.http.HttpClient) HttpResponse(io.vertx.ext.web.client.HttpResponse) StreamedRow(io.confluent.ksql.rest.entity.StreamedRow) WebClient(io.vertx.ext.web.client.WebClient) POST(io.vertx.core.http.HttpMethod.POST) BodyCodec(io.vertx.ext.web.codec.BodyCodec) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) CompletableFuture(java.util.concurrent.CompletableFuture) WebsocketVersion(io.vertx.core.http.WebsocketVersion) ServerClusterId(io.confluent.ksql.rest.entity.ServerClusterId) ArrayList(java.util.ArrayList) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) HttpClientRequest(io.vertx.core.http.HttpClientRequest) ServerInfo(io.confluent.ksql.rest.entity.ServerInfo) KsqlRestClient(io.confluent.ksql.rest.client.KsqlRestClient) Charset(java.nio.charset.Charset) WriteStream(io.vertx.core.streams.WriteStream) HttpClientOptions(io.vertx.core.http.HttpClientOptions) TestDataProvider(io.confluent.ksql.util.TestDataProvider) HTTP_1_1(io.vertx.core.http.HttpVersion.HTTP_1_1) Credentials(io.confluent.ksql.test.util.secure.Credentials) Vertx(io.vertx.core.Vertx) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) BasicCredentials(io.confluent.ksql.rest.client.BasicCredentials) ServerMetadata(io.confluent.ksql.rest.entity.ServerMetadata) KsqlMediaType(io.confluent.ksql.rest.entity.KsqlMediaType) HttpRequest(io.vertx.ext.web.client.HttpRequest) Consumer(java.util.function.Consumer) HttpMethod(io.vertx.core.http.HttpMethod) HealthCheckResponse(io.confluent.ksql.rest.entity.HealthCheckResponse) Collections(java.util.Collections) Buffer(io.vertx.core.buffer.Buffer) VertxCompletableFuture(io.confluent.ksql.util.VertxCompletableFuture) Vertx(io.vertx.core.Vertx) HttpClientOptions(io.vertx.core.http.HttpClientOptions) HttpClientRequest(io.vertx.core.http.HttpClientRequest) HttpClient(io.vertx.core.http.HttpClient)

Aggregations

AUTHORIZATION (io.netty.handler.codec.http.HttpHeaderNames.AUTHORIZATION)3 CONTENT_TYPE (io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE)2 AsciiString (io.netty.util.AsciiString)2 Base64 (java.util.Base64)2 ConnectionContext (org.cloudfoundry.reactor.ConnectionContext)2 TokenProvider (org.cloudfoundry.reactor.TokenProvider)2 AbstractUaaOperations (org.cloudfoundry.reactor.uaa.AbstractUaaOperations)2 Mono (reactor.core.publisher.Mono)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 UrlEscapers (com.google.common.net.UrlEscapers)1 ApiJsonMapper (io.confluent.ksql.rest.ApiJsonMapper)1 BasicCredentials (io.confluent.ksql.rest.client.BasicCredentials)1 KsqlRestClient (io.confluent.ksql.rest.client.KsqlRestClient)1 RestResponse (io.confluent.ksql.rest.client.RestResponse)1 CommandStatus (io.confluent.ksql.rest.entity.CommandStatus)1 Status (io.confluent.ksql.rest.entity.CommandStatus.Status)1 CommandStatusEntity (io.confluent.ksql.rest.entity.CommandStatusEntity)1 CommandStatuses (io.confluent.ksql.rest.entity.CommandStatuses)1 HealthCheckResponse (io.confluent.ksql.rest.entity.HealthCheckResponse)1 KsqlEntity (io.confluent.ksql.rest.entity.KsqlEntity)1