Search in sources :

Example 1 with CheckRightV4Response

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

the class UtilAuthorizationServiceTest method testCheckRight.

@Test
public void testCheckRight() {
    when(grpcUmsClient.hasRights(anyString(), any(), any(), any())).thenReturn(Lists.newArrayList(Boolean.TRUE, Boolean.FALSE));
    CheckRightV4Request rightReq = new CheckRightV4Request();
    rightReq.setRights(Lists.newArrayList(RightV4.ENV_CREATE, RightV4.DISTROX_READ));
    CheckRightV4Response rightResult = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkRights(rightReq));
    rightResult.getResponses().forEach(checkRightV4SingleResponse -> {
        if (checkRightV4SingleResponse.getRight().equals(RightV4.ENV_CREATE)) {
            assertTrue(checkRightV4SingleResponse.getResult());
        }
        if (checkRightV4SingleResponse.getRight().equals(RightV4.DISTROX_READ)) {
            assertFalse(checkRightV4SingleResponse.getResult());
        }
    });
    verify(grpcUmsClient, times(1)).hasRights(anyString(), any(), any(), any());
}
Also used : CheckRightV4Response(com.sequenceiq.authorization.info.model.CheckRightV4Response) CheckRightV4Request(com.sequenceiq.authorization.info.model.CheckRightV4Request) Test(org.junit.jupiter.api.Test)

Example 2 with CheckRightV4Response

use of com.sequenceiq.authorization.info.model.CheckRightV4Response 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)

Aggregations

CheckRightV4Request (com.sequenceiq.authorization.info.model.CheckRightV4Request)2 CheckRightV4Response (com.sequenceiq.authorization.info.model.CheckRightV4Response)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 CheckResourceRightV4SingleResponse (com.sequenceiq.authorization.info.model.CheckResourceRightV4SingleResponse)1 CheckResourceRightsV4Request (com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request)1 CheckResourceRightsV4Response (com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response)1 CheckRightOnResourcesV4Request (com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Request)1 CheckRightOnResourcesV4Response (com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response)1 CheckRightV4SingleResponse (com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse)1 RightV4 (com.sequenceiq.authorization.info.model.RightV4)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 AuthorizationRule (com.sequenceiq.authorization.service.model.AuthorizationRule)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1