Search in sources :

Example 1 with CredentialsSupplier

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());
}
Also used : ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) ServiceInfo(io.scalecube.services.ServiceInfo) Mono(reactor.core.publisher.Mono) Authenticator(io.scalecube.services.auth.Authenticator) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices) CredentialsSupplier(io.scalecube.services.auth.CredentialsSupplier) Duration(java.time.Duration) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) ServiceMessage(io.scalecube.services.api.ServiceMessage) Collections(java.util.Collections) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) MonoAuthUtil.deferWithPrincipal(io.scalecube.services.auth.MonoAuthUtil.deferWithPrincipal) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) ServiceMessage(io.scalecube.services.api.ServiceMessage) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices)

Example 2 with CredentialsSupplier

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);
}
Also used : ServiceEndpoint(io.scalecube.services.ServiceEndpoint) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) Microservices(io.scalecube.services.Microservices) CredentialsSupplier(io.scalecube.services.auth.CredentialsSupplier) Duration(java.time.Duration) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) Authenticator(io.scalecube.services.auth.Authenticator) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices)

Example 3 with CredentialsSupplier

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);
}
Also used : ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) ServiceInfo(io.scalecube.services.ServiceInfo) HashMap(java.util.HashMap) Mono(reactor.core.publisher.Mono) UUID(java.util.UUID) Authenticator(io.scalecube.services.auth.Authenticator) ServiceEndpoint(io.scalecube.services.ServiceEndpoint) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices) CredentialsSupplier(io.scalecube.services.auth.CredentialsSupplier) Duration(java.time.Duration) Map(java.util.Map) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) UnauthorizedException(io.scalecube.services.exceptions.UnauthorizedException) ScalecubeServiceDiscovery(io.scalecube.services.discovery.ScalecubeServiceDiscovery) WebsocketTransportFactory(io.scalecube.transport.netty.websocket.WebsocketTransportFactory) RSocketServiceTransport(io.scalecube.services.transport.rsocket.RSocketServiceTransport) Microservices(io.scalecube.services.Microservices)

Aggregations

Microservices (io.scalecube.services.Microservices)3 ServiceEndpoint (io.scalecube.services.ServiceEndpoint)3 Authenticator (io.scalecube.services.auth.Authenticator)3 CredentialsSupplier (io.scalecube.services.auth.CredentialsSupplier)3 ScalecubeServiceDiscovery (io.scalecube.services.discovery.ScalecubeServiceDiscovery)3 UnauthorizedException (io.scalecube.services.exceptions.UnauthorizedException)3 RSocketServiceTransport (io.scalecube.services.transport.rsocket.RSocketServiceTransport)3 WebsocketTransportFactory (io.scalecube.transport.netty.websocket.WebsocketTransportFactory)3 Duration (java.time.Duration)3 Mono (reactor.core.publisher.Mono)3 ServiceInfo (io.scalecube.services.ServiceInfo)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 ServiceMessage (io.scalecube.services.api.ServiceMessage)1 MonoAuthUtil.deferWithPrincipal (io.scalecube.services.auth.MonoAuthUtil.deferWithPrincipal)1 Collections (java.util.Collections)1 Map (java.util.Map)1