Search in sources :

Example 1 with Clustered

use of com.sequenceiq.periscope.domain.Clustered in project cloudbreak by hortonworks.

the class TenantBasedPermissionEvaluator method hasPermission.

@Override
public boolean hasPermission(Authentication authentication, Object target, Object permission) {
    if (!authentication.isAuthenticated()) {
        return true;
    }
    if (target instanceof Optional) {
        target = ((Optional<?>) target).orElse(null);
    }
    if (target == null) {
        return false;
    }
    CloudbreakUser cloudbreakUser = restRequestThreadLocalService.getCloudbreakUser();
    Collection<?> targets = target instanceof Collection ? (Collection<?>) target : Collections.singleton(target);
    return targets.stream().allMatch(t -> {
        if (!(t instanceof Clustered)) {
            return true;
        }
        Cluster cluster = ((Clustered) t).getCluster();
        if (cluster == null || !cloudbreakUser.getTenant().contentEquals(cluster.getClusterPertain().getTenant())) {
            return false;
        }
        cloudbreakAuthorizationService.hasAccess(cluster.getStackCrn(), cloudbreakUser.getUserId(), cloudbreakUser.getTenant(), permission.toString());
        return true;
    });
}
Also used : Optional(java.util.Optional) Collection(java.util.Collection) Clustered(com.sequenceiq.periscope.domain.Clustered) Cluster(com.sequenceiq.periscope.domain.Cluster) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser)

Aggregations

CloudbreakUser (com.sequenceiq.cloudbreak.common.user.CloudbreakUser)1 Cluster (com.sequenceiq.periscope.domain.Cluster)1 Clustered (com.sequenceiq.periscope.domain.Clustered)1 Collection (java.util.Collection)1 Optional (java.util.Optional)1