Search in sources :

Example 1 with GrpcClientSecurity

use of io.helidon.security.integration.grpc.GrpcClientSecurity in project helidon by oracle.

the class SecureGreetClient method main.

/**
 * Program entry point.
 *
 * @param args  program arguments
 */
public static void main(String[] args) {
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    Config config = Config.create();
    // configure Helidon security and add the basic auth provider
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // create the gRPC client security call credentials
    // setting the properties used by the basic auth provider for user name and password
    GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client")).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, "Bob").property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, "password").build();
    // create the GreetService client stub and use the GrpcClientSecurity call credentials
    GreetServiceGrpc.GreetServiceBlockingStub stub = GreetServiceGrpc.newBlockingStub(channel).withCallCredentials(clientSecurity);
    Greet.GreetResponse greetResponse = stub.greet(Greet.GreetRequest.newBuilder().setName("Bob").build());
    System.out.println(greetResponse.getMessage());
    Greet.SetGreetingResponse setGreetingResponse = stub.setGreeting(Greet.SetGreetingRequest.newBuilder().setGreeting("Merhaba").build());
    System.out.println("Greeting set to: " + setGreetingResponse.getGreeting());
    greetResponse = stub.greet(Greet.GreetRequest.newBuilder().setName("Bob").build());
    System.out.println(greetResponse.getMessage());
}
Also used : GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Greet(io.helidon.grpc.examples.common.Greet) Config(io.helidon.config.Config) Channel(io.grpc.Channel) GreetServiceGrpc(io.helidon.grpc.examples.common.GreetServiceGrpc) Security(io.helidon.security.Security) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity)

Example 2 with GrpcClientSecurity

use of io.helidon.security.integration.grpc.GrpcClientSecurity in project helidon by oracle.

the class SecureStringClient method main.

/**
 * Program entry point.
 *
 * @param args  the program arguments - {@code arg[0]} is the user name
 *              and {@code arg[1] is the password}
 */
public static void main(String[] args) {
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    // Obtain the user name and password from the program arguments
    String user = args.length >= 2 ? args[0] : "Ted";
    String password = args.length >= 2 ? args[1] : "secret";
    Config config = Config.create();
    // configure Helidon security and add the basic auth provider
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // create the gRPC client security call credentials
    // setting the properties used by the basic auth provider for user name and password
    GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client")).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, user).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, password).build();
    // Create the client service descriptor and add the call credentials
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(StringServiceGrpc.getServiceDescriptor()).callCredentials(clientSecurity).build();
    // create the client for the service
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    Strings.StringMessage request = Strings.StringMessage.newBuilder().setText("ABCDE").build();
    Strings.StringMessage response = client.blockingUnary("Lower", request);
    System.out.println("Response from Lower method call is '" + response.getText() + "'");
}
Also used : GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Config(io.helidon.config.Config) Channel(io.grpc.Channel) ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient) Security(io.helidon.security.Security) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Strings(io.helidon.grpc.examples.common.Strings)

Example 3 with GrpcClientSecurity

use of io.helidon.security.integration.grpc.GrpcClientSecurity in project helidon by oracle.

the class SecureGreetClient method main.

/**
 * Main entry point.
 *
 * @param args  the program arguments - {@code arg[0]} is the user name
 *              and {@code arg[1] is the password}
 */
public static void main(String[] args) {
    Channel channel = ManagedChannelBuilder.forAddress("localhost", 1408).usePlaintext().build();
    // Obtain the user name and password from the program arguments
    String user = args.length >= 2 ? args[0] : "Ted";
    String password = args.length >= 2 ? args[1] : "secret";
    Config config = Config.create();
    // configure Helidon security and add the basic auth provider
    Security security = Security.builder().addProvider(HttpBasicAuthProvider.create(config.get("http-basic-auth"))).build();
    // create the gRPC client security call credentials
    // setting the properties used by the basic auth provider for user name and password
    GrpcClientSecurity clientSecurity = GrpcClientSecurity.builder(security.createContext("test.client")).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_USER, user).property(HttpBasicAuthProvider.EP_PROPERTY_OUTBOUND_PASSWORD, password).build();
    // Create the client service descriptor and add the call credentials
    ClientServiceDescriptor descriptor = ClientServiceDescriptor.builder(GreetServiceGrpc.getServiceDescriptor()).callCredentials(clientSecurity).build();
    // create the client for the service
    GrpcServiceClient client = GrpcServiceClient.create(channel, descriptor);
    greet(client);
    setGreeting(client);
    greet(client);
}
Also used : GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity) Config(io.helidon.config.Config) Channel(io.grpc.Channel) ClientServiceDescriptor(io.helidon.grpc.client.ClientServiceDescriptor) GrpcServiceClient(io.helidon.grpc.client.GrpcServiceClient) Security(io.helidon.security.Security) GrpcClientSecurity(io.helidon.security.integration.grpc.GrpcClientSecurity)

Aggregations

Channel (io.grpc.Channel)3 Config (io.helidon.config.Config)3 Security (io.helidon.security.Security)3 GrpcClientSecurity (io.helidon.security.integration.grpc.GrpcClientSecurity)3 ClientServiceDescriptor (io.helidon.grpc.client.ClientServiceDescriptor)2 GrpcServiceClient (io.helidon.grpc.client.GrpcServiceClient)2 Greet (io.helidon.grpc.examples.common.Greet)1 GreetServiceGrpc (io.helidon.grpc.examples.common.GreetServiceGrpc)1 Strings (io.helidon.grpc.examples.common.Strings)1