Search in sources :

Example 1 with CheckRightV4SingleResponse

use of com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse in project cloudbreak by hortonworks.

the class UtilAuthorizationService method checkRights.

public CheckRightV4Response checkRights(CheckRightV4Request rightReq) {
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    List<AuthorizationProto.RightCheck> rightChecks = rightReq.getRights().stream().map(rightV4 -> createRightCheckObject(umsRightProvider.getRight(rightV4.getAction()), null)).collect(Collectors.toList());
    List<Boolean> results = grpcUmsClient.hasRights(userCrn, rightChecks, MDCUtils.getRequestId(), regionAwareInternalCrnGeneratorFactory);
    return new CheckRightV4Response(rightReq.getRights().stream().map(rightV4 -> new CheckRightV4SingleResponse(rightV4, results.get(rightReq.getRights().indexOf(rightV4)))).collect(Collectors.toList()));
}
Also used : CheckRightOnResourcesV4Response(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response) CheckRightV4Request(com.sequenceiq.authorization.info.model.CheckRightV4Request) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) ResourceFilteringService(com.sequenceiq.authorization.service.list.ResourceFilteringService) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) StringUtils(org.apache.commons.lang3.StringUtils) AuthorizationRule(com.sequenceiq.authorization.service.model.AuthorizationRule) Inject(javax.inject.Inject) CheckResourceRightV4SingleResponse(com.sequenceiq.authorization.info.model.CheckResourceRightV4SingleResponse) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) RightV4(com.sequenceiq.authorization.info.model.RightV4) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Lists(com.google.common.collect.Lists) Resource(com.sequenceiq.authorization.service.list.Resource) CheckRightV4Response(com.sequenceiq.authorization.info.model.CheckRightV4Response) Service(org.springframework.stereotype.Service) Map(java.util.Map) AuthorizationProto(com.cloudera.thunderhead.service.authorization.AuthorizationProto) CheckResourceRightsV4Request(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request) ResourceListProvider(com.sequenceiq.authorization.service.list.ResourceListProvider) CheckResourceRightsV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response) CheckRightOnResourcesV4Request(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Request) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) Collection(java.util.Collection) CheckRightV4SingleResponse(com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) GrpcUmsClient(com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) List(java.util.List) CheckResourceRightV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightV4Response) MDCUtils(com.sequenceiq.cloudbreak.logger.MDCUtils) Optional(java.util.Optional) CheckRightV4Response(com.sequenceiq.authorization.info.model.CheckRightV4Response) CheckRightV4SingleResponse(com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse)

Example 2 with CheckRightV4SingleResponse

use of com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse in project cloudbreak by hortonworks.

the class UtilAuthorizationService method generateResponse.

private CheckResourceRightsV4Response generateResponse(Multimap<ImmutablePair<String, RightV4>, AuthorizationProto.RightCheck> resourceRightsChecks, Map<AuthorizationProto.RightCheck, Boolean> rightCheckResultMap) {
    CheckResourceRightsV4Response response = new CheckResourceRightsV4Response(Lists.newArrayList());
    Map<ImmutablePair<String, RightV4>, Boolean> rightCheckResults = new HashMap<>();
    for (ImmutablePair<String, RightV4> resourceRight : resourceRightsChecks.keys()) {
        Collection<AuthorizationProto.RightCheck> rightChecks = resourceRightsChecks.get(resourceRight);
        Boolean hasRight = hasRight(rightCheckResultMap, rightChecks);
        rightCheckResults.put(resourceRight, hasRight);
    }
    rightCheckResults.forEach((rightCheck, result) -> {
        if (getResourceRightSingleResponse(response, rightCheck.getLeft()).isEmpty()) {
            response.getResponses().add(new CheckResourceRightV4SingleResponse(rightCheck.getLeft(), Lists.newArrayList()));
        }
        CheckRightV4SingleResponse singleResponse = new CheckRightV4SingleResponse(rightCheck.getRight(), result);
        getResourceRightSingleResponse(response, rightCheck.getLeft()).get().getRights().add(singleResponse);
    });
    return response;
}
Also used : RightV4(com.sequenceiq.authorization.info.model.RightV4) CheckRightV4SingleResponse(com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) HashMap(java.util.HashMap) CheckResourceRightsV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response) CheckResourceRightV4SingleResponse(com.sequenceiq.authorization.info.model.CheckResourceRightV4SingleResponse)

Aggregations

CheckResourceRightV4SingleResponse (com.sequenceiq.authorization.info.model.CheckResourceRightV4SingleResponse)2 CheckResourceRightsV4Response (com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response)2 CheckRightV4SingleResponse (com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse)2 RightV4 (com.sequenceiq.authorization.info.model.RightV4)2 HashMap (java.util.HashMap)2 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)2 AuthorizationProto (com.cloudera.thunderhead.service.authorization.AuthorizationProto)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 LinkedListMultimap (com.google.common.collect.LinkedListMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 CheckResourceRightV4Response (com.sequenceiq.authorization.info.model.CheckResourceRightV4Response)1 CheckResourceRightsV4Request (com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request)1 CheckRightOnResourcesV4Request (com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Request)1 CheckRightOnResourcesV4Response (com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response)1 CheckRightV4Request (com.sequenceiq.authorization.info.model.CheckRightV4Request)1 CheckRightV4Response (com.sequenceiq.authorization.info.model.CheckRightV4Response)1 Resource (com.sequenceiq.authorization.service.list.Resource)1 ResourceFilteringService (com.sequenceiq.authorization.service.list.ResourceFilteringService)1 ResourceListProvider (com.sequenceiq.authorization.service.list.ResourceListProvider)1