Search in sources :

Example 6 with CallCredentials

use of io.grpc.CallCredentials in project grpc-java by grpc.

the class AuthClientTest method setUp.

@Before
public void setUp() throws IOException {
    // Generate a unique in-process server name.
    String serverName = InProcessServerBuilder.generateName();
    // Create a server, add service, start, and register for automatic graceful shutdown.
    grpcCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor().addService(ServerInterceptors.intercept(new GreeterGrpc.GreeterImplBase() {

        @Override
        public void sayHello(HelloRequest request, StreamObserver<HelloReply> responseObserver) {
            HelloReply reply = HelloReply.newBuilder().setMessage("AuthClientTest user=" + request.getName()).build();
            responseObserver.onNext(reply);
            responseObserver.onCompleted();
        }
    }, mockServerInterceptor)).build().start());
    CallCredentials credentials = new JwtCredential("test-client");
    ManagedChannel channel = InProcessChannelBuilder.forName(serverName).directExecutor().build();
    client = new AuthClient(credentials, channel);
}
Also used : HelloRequest(io.grpc.examples.helloworld.HelloRequest) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) ManagedChannel(io.grpc.ManagedChannel) HelloReply(io.grpc.examples.helloworld.HelloReply) CallCredentials(io.grpc.CallCredentials) Before(org.junit.Before)

Example 7 with CallCredentials

use of io.grpc.CallCredentials in project grpc-java by grpc.

the class AuthClient method main.

/**
 * Greet server. If provided, the first element of {@code args} is the name to use in the greeting
 * and the second is the client identifier to set in JWT
 */
public static void main(String[] args) throws Exception {
    String host = "localhost";
    int port = 50051;
    String user = "world";
    String clientId = "default-client";
    if (args.length > 0) {
        // Use the arg as the server host if provided
        host = args[0];
    }
    if (args.length > 1) {
        // Use the second argument as the server port if provided
        port = Integer.parseInt(args[1]);
    }
    if (args.length > 2) {
        // Use the the third argument as the name to greet if provided
        user = args[2];
    }
    if (args.length > 3) {
        // Use the fourth argument as the client identifier if provided
        clientId = args[3];
    }
    CallCredentials credentials = new JwtCredential(clientId);
    AuthClient client = new AuthClient(credentials, host, port);
    try {
        client.greet(user);
    } finally {
        client.shutdown();
    }
}
Also used : CallCredentials(io.grpc.CallCredentials)

Example 8 with CallCredentials

use of io.grpc.CallCredentials in project grpc-java by grpc.

the class ProtocolNegotiatorsTest method fromClient_composite.

@Test
public void fromClient_composite() {
    CallCredentials callCredentials = mock(CallCredentials.class);
    ProtocolNegotiators.FromChannelCredentialsResult result = ProtocolNegotiators.from(CompositeChannelCredentials.create(TlsChannelCredentials.create(), callCredentials));
    assertThat(result.error).isNull();
    assertThat(result.callCredentials).isSameInstanceAs(callCredentials);
    assertThat(result.negotiator).isInstanceOf(ProtocolNegotiators.TlsProtocolNegotiatorClientFactory.class);
    result = ProtocolNegotiators.from(CompositeChannelCredentials.create(InsecureChannelCredentials.create(), callCredentials));
    assertThat(result.error).isNull();
    assertThat(result.callCredentials).isSameInstanceAs(callCredentials);
    assertThat(result.negotiator).isInstanceOf(ProtocolNegotiators.PlaintextProtocolNegotiatorClientFactory.class);
}
Also used : CallCredentials(io.grpc.CallCredentials) Test(org.junit.Test)

Example 9 with CallCredentials

use of io.grpc.CallCredentials in project grpc-java by grpc.

the class OkHttpChannelBuilderTest method sslSocketFactoryFrom_composite.

@Test
public void sslSocketFactoryFrom_composite() {
    CallCredentials callCredentials = mock(CallCredentials.class);
    OkHttpChannelBuilder.SslSocketFactoryResult result = OkHttpChannelBuilder.sslSocketFactoryFrom(CompositeChannelCredentials.create(TlsChannelCredentials.create(), callCredentials));
    assertThat(result.error).isNull();
    assertThat(result.callCredentials).isSameInstanceAs(callCredentials);
    assertThat(result.factory).isNotNull();
    result = OkHttpChannelBuilder.sslSocketFactoryFrom(CompositeChannelCredentials.create(InsecureChannelCredentials.create(), callCredentials));
    assertThat(result.error).isNull();
    assertThat(result.callCredentials).isSameInstanceAs(callCredentials);
    assertThat(result.factory).isNull();
}
Also used : CallCredentials(io.grpc.CallCredentials) Test(org.junit.Test)

Example 10 with CallCredentials

use of io.grpc.CallCredentials in project beam by apache.

the class GrpcWindmillServer method initializeWindmillService.

private synchronized void initializeWindmillService(Set<HostAndPort> endpoints) throws IOException {
    LOG.info("Initializing Streaming Engine GRPC client for endpoints: {}", endpoints);
    this.stubList.clear();
    this.syncStubList.clear();
    this.endpoints = ImmutableSet.<HostAndPort>copyOf(endpoints);
    for (HostAndPort endpoint : this.endpoints) {
        if ("localhost".equals(endpoint.getHost())) {
            initializeLocalHost(endpoint.getPort());
        } else {
            CallCredentials creds = MoreCallCredentials.from(new VendoredCredentialsAdapter(options.getGcpCredential()));
            this.stubList.add(CloudWindmillServiceV1Alpha1Grpc.newStub(remoteChannel(endpoint)).withCallCredentials(creds));
            this.syncStubList.add(CloudWindmillServiceV1Alpha1Grpc.newBlockingStub(remoteChannel(endpoint)).withCallCredentials(creds));
        }
    }
}
Also used : HostAndPort(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.net.HostAndPort) MoreCallCredentials(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.auth.MoreCallCredentials) CallCredentials(org.apache.beam.vendor.grpc.v1p43p2.io.grpc.CallCredentials)

Aggregations

CallCredentials (io.grpc.CallCredentials)9 Test (org.junit.Test)4 Credentials (com.google.auth.Credentials)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)3 AccessToken (com.google.auth.oauth2.AccessToken)2 OAuth2Credentials (com.google.auth.oauth2.OAuth2Credentials)2 ServiceAccountCredentials (com.google.auth.oauth2.ServiceAccountCredentials)2 Metadata (io.grpc.Metadata)2 Status (io.grpc.Status)2 MoreCallCredentials (io.grpc.auth.MoreCallCredentials)2 Date (java.util.Date)2 Function (com.google.common.base.Function)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 SubscriberFutureStub (com.google.pubsub.v1.SubscriberGrpc.SubscriberFutureStub)1 Attributes (io.grpc.Attributes)1 ChannelCredentials (io.grpc.ChannelCredentials)1 CompositeChannelCredentials (io.grpc.CompositeChannelCredentials)1 ManagedChannel (io.grpc.ManagedChannel)1 MethodDescriptor (io.grpc.MethodDescriptor)1