Search in sources :

Example 1 with ResourceRightsV4

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

the class CheckResourceRightAction method action.

@Override
public CheckResourceRightTestDto action(TestContext testContext, CheckResourceRightTestDto testDto, CloudbreakClient cloudbreakClient) throws Exception {
    CheckResourceRightsV4Request checkRightByCrnV4Request = new CheckResourceRightsV4Request();
    checkRightByCrnV4Request.setResourceRights(testDto.getRightsToCheck().entrySet().stream().map(entry -> {
        ResourceRightsV4 resourceRightsV4 = new ResourceRightsV4();
        resourceRightsV4.setResourceCrn(entry.getKey());
        resourceRightsV4.setRights(entry.getValue());
        return resourceRightsV4;
    }).collect(Collectors.toList()));
    testDto.setResponse(cloudbreakClient.getDefaultClient().authorizationUtilEndpoint().checkRightByCrn(checkRightByCrnV4Request));
    Log.whenJson(LOGGER, "checking right on resources response:\n", testDto.getResponse());
    return testDto;
}
Also used : CheckResourceRightsV4Request(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request) ResourceRightsV4(com.sequenceiq.authorization.info.model.ResourceRightsV4)

Example 2 with ResourceRightsV4

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

the class UtilAuthorizationServiceTest method createResourceRightV4.

private ResourceRightsV4 createResourceRightV4(String crn, RightV4... rights) {
    ResourceRightsV4 resourceRightsV4 = new ResourceRightsV4();
    resourceRightsV4.setResourceCrn(crn);
    resourceRightsV4.setRights(Lists.newArrayList(rights));
    return resourceRightsV4;
}
Also used : ResourceRightsV4(com.sequenceiq.authorization.info.model.ResourceRightsV4)

Example 3 with ResourceRightsV4

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

the class UtilAuthorizationServiceTest method testCheckResourceRightFallback.

@Test
public void testCheckResourceRightFallback() {
    when(grpcUmsClient.hasRights(anyString(), any(), any(), any())).thenReturn(Lists.newLinkedList(Arrays.asList(Boolean.TRUE, Boolean.FALSE, Boolean.FALSE, Boolean.TRUE)));
    CheckResourceRightsV4Request rightReq = new CheckResourceRightsV4Request();
    List<ResourceRightsV4> resourceRights = new LinkedList<>();
    resourceRights.add(createResourceRightV4("envCrn", RightV4.ENV_STOP, RightV4.ENV_START));
    resourceRights.add(createResourceRightV4("dhCrn", RightV4.DH_START, RightV4.DH_STOP));
    rightReq.setResourceRights(resourceRights);
    CheckResourceRightsV4Response rightResult = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkRightsOnResources(rightReq));
    rightResult.getResponses().forEach(checkResourceRightV4SingleResponse -> checkResourceRightV4SingleResponse.getRights().forEach(checkRightV4SingleResponse -> {
        if (checkRightV4SingleResponse.getRight().equals(RightV4.ENV_STOP) || checkRightV4SingleResponse.getRight().equals(RightV4.DH_STOP)) {
            assertTrue(checkRightV4SingleResponse.getResult());
        }
        if (checkRightV4SingleResponse.getRight().equals(RightV4.DH_START) || checkRightV4SingleResponse.getRight().equals(RightV4.ENV_START)) {
            assertFalse(checkRightV4SingleResponse.getResult());
        }
    }));
    verify(grpcUmsClient, times(1)).hasRights(anyString(), any(), any(), any());
}
Also used : CheckResourceRightsV4Request(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) CheckRightOnResourcesV4Response(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response) CheckRightV4Request(com.sequenceiq.authorization.info.model.CheckRightV4Request) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) ResourceRightsV4(com.sequenceiq.authorization.info.model.ResourceRightsV4) ResourceFilteringService(com.sequenceiq.authorization.service.list.ResourceFilteringService) Mockito.lenient(org.mockito.Mockito.lenient) Function(java.util.function.Function) RightV4(com.sequenceiq.authorization.info.model.RightV4) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Lists(com.google.common.collect.Lists) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Resource(com.sequenceiq.authorization.service.list.Resource) CheckRightV4Response(com.sequenceiq.authorization.info.model.CheckRightV4Response) Mockito.doAnswer(org.mockito.Mockito.doAnswer) AuthorizationProto(com.cloudera.thunderhead.service.authorization.AuthorizationProto) CheckResourceRightsV4Request(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request) ResourceListProvider(com.sequenceiq.authorization.service.list.ResourceListProvider) LinkedList(java.util.LinkedList) CheckResourceRightsV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response) CheckRightOnResourcesV4Request(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Request) InjectMocks(org.mockito.InjectMocks) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Predicate(java.util.function.Predicate) Assert.assertTrue(org.junit.Assert.assertTrue) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Collectors(java.util.stream.Collectors) GrpcUmsClient(com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) HasRightOnAny(com.sequenceiq.authorization.service.model.HasRightOnAny) List(java.util.List) Stream(java.util.stream.Stream) CheckResourceRightV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightV4Response) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ResourceRightsV4(com.sequenceiq.authorization.info.model.ResourceRightsV4) CheckResourceRightsV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response) LinkedList(java.util.LinkedList) Test(org.junit.jupiter.api.Test)

Aggregations

ResourceRightsV4 (com.sequenceiq.authorization.info.model.ResourceRightsV4)3 CheckResourceRightsV4Request (com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request)2 AuthorizationProto (com.cloudera.thunderhead.service.authorization.AuthorizationProto)1 Lists (com.google.common.collect.Lists)1 CheckResourceRightV4Response (com.sequenceiq.authorization.info.model.CheckResourceRightV4Response)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 CheckRightV4Request (com.sequenceiq.authorization.info.model.CheckRightV4Request)1 CheckRightV4Response (com.sequenceiq.authorization.info.model.CheckRightV4Response)1 RightV4 (com.sequenceiq.authorization.info.model.RightV4)1 AuthorizationResourceAction (com.sequenceiq.authorization.resource.AuthorizationResourceAction)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 HasRightOnAny (com.sequenceiq.authorization.service.model.HasRightOnAny)1 ThreadBasedUserCrnProvider (com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider)1 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)1 GrpcUmsClient (com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1