use of io.scalecube.services.auth.CredentialsSupplier in project scalecube by scalecube.
the class CompositeProfileAuthExample method main.
/**
* Main program.
*
* @param args arguments
*/
public static void main(String[] args) {
Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(call -> Collections.singletonList(ServiceInfo.fromServiceInstance(new SecuredServiceByCompositeProfileImpl()).authenticator(compositeAuthenticator()).build())).startAwait();
Microservices caller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
ServiceMessage response = caller.call().requestOne(ServiceMessage.builder().qualifier("securedServiceByCompositeProfile/hello").header("userProfile.name", "SEGA").header("userProfile.role", "ADMIN").data("hello world").build(), String.class).block(Duration.ofSeconds(3));
System.err.println("### Received 'caller' response: " + response.data());
}
use of io.scalecube.services.auth.CredentialsSupplier in project scalecube by scalecube.
the class ServiceTransportAuthExample method main.
/**
* Main program.
*
* @param args arguments
*/
public static void main(String[] args) {
Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(new SecuredServiceByUserProfileImpl()).startAwait();
Microservices caller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
String response = caller.call().api(SecuredServiceByUserProfile.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
System.err.println("### Received 'caller' response: " + response);
}
use of io.scalecube.services.auth.CredentialsSupplier in project scalecube by scalecube.
the class PrincipalMapperAuthExample method main.
/**
* Main program.
*
* @param args arguments
*/
public static void main(String[] args) {
Microservices service = Microservices.builder().discovery(serviceEndpoint -> new ScalecubeServiceDiscovery().transport(cfg -> cfg.transportFactory(new WebsocketTransportFactory())).options(opts -> opts.metadata(serviceEndpoint))).transport(() -> new RSocketServiceTransport().authenticator(authenticator())).services(ServiceInfo.fromServiceInstance(new SecuredServiceByApiKeyImpl()).principalMapper(PrincipalMapperAuthExample::apiKeyPrincipalMapper).build()).services(ServiceInfo.fromServiceInstance(new SecuredServiceByUserProfileImpl()).principalMapper(PrincipalMapperAuthExample::userProfilePrincipalMapper).build()).startAwait();
Microservices userProfileCaller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
String responseByUserProfile = userProfileCaller.call().api(SecuredServiceByUserProfile.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
System.err.println("### Received 'userProfileCaller' response: " + responseByUserProfile);
Microservices apiKeyCaller = Microservices.builder().discovery(endpoint -> discovery(service, endpoint)).transport(() -> new RSocketServiceTransport().credentialsSupplier(credentialsSupplier())).startAwait();
String responseByApiKey = apiKeyCaller.call().api(SecuredServiceByApiKey.class).hello(UUID.randomUUID().toString()).block(Duration.ofSeconds(3));
System.err.println("### Received 'apiKeyCaller' response: " + responseByApiKey);
}
Aggregations