All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.scalecube.services.examples.auth.SecuredServiceByCompositeProfileImpl Maven / Gradle / Ivy

package io.scalecube.services.examples.auth;

import io.scalecube.services.auth.Authenticator;
import io.scalecube.services.exceptions.ForbiddenException;
import reactor.core.publisher.Mono;

public class SecuredServiceByCompositeProfileImpl implements SecuredServiceByCompositeProfile {

  @Override
  public Mono hello(String name) {
    return Authenticator.deferSecured(CompositeProfile.class)
        .flatMap(
            compositeProfile -> {
              final UserProfile userProfile = compositeProfile.userProfile();
              final ServiceEndpointProfile serviceEndpointProfile =
                  compositeProfile.serviceEndpointProfile();
              checkPermissions(userProfile);
              return Mono.just(
                  "Hello, name="
                      + name
                      + " (userProfile="
                      + userProfile
                      + ", serviceEndpointProfile="
                      + serviceEndpointProfile
                      + ")");
            });
  }

  private void checkPermissions(UserProfile user) {
    if (!user.role().equals("ADMIN")) {
      throw new ForbiddenException("Forbidden");
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy