Search in sources :

Example 6 with HasRight

use of com.sequenceiq.authorization.service.model.HasRight in project cloudbreak by hortonworks.

the class ResourceAuthorizationServiceTest method testAccessDenied.

@Test
public void testAccessDenied() throws NoSuchMethodException {
    Method method = ExampleClass.class.getMethod("method", String.class);
    when(methodSignature.getMethod()).thenReturn(method);
    when(authorizationFactory1.getAuthorization(any(), any(), any(), any())).thenReturn(Optional.of(new HasRight(AuthorizationResourceAction.EDIT_ENVIRONMENT, "crn")));
    when(grpcUmsClient.hasRights(anyString(), anyList(), any(), any())).thenReturn(List.of(false));
    AccessDeniedException accessDeniedException = assertThrows(AccessDeniedException.class, () -> {
        ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.authorize(USER_CRN, proceedingJoinPoint, methodSignature, Optional.of("requestId")));
    });
    assertEquals("Doesn't have 'environments/editEnvironment' right on unknown resource type [crn: crn].", accessDeniedException.getMessage());
}
Also used : HasRight(com.sequenceiq.authorization.service.model.HasRight) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 7 with HasRight

use of com.sequenceiq.authorization.service.model.HasRight in project cloudbreak by hortonworks.

the class RequestPropertyAuthorizationFactoryTest method testOnName.

@Test
public void testOnName() {
    when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(new SampleRequestObject(RESOURCE_NAME));
    Optional<AuthorizationRule> expected = Optional.of(new HasRight(DELETE_DATAHUB, RESOURCE_CRN));
    when(resourceNameAuthorizationFactory.calcAuthorization(anyString(), any())).thenReturn(expected);
    Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(NAME, DELETE_DATAHUB, false, "field"), USER_CRN, null, null);
    verify(resourceNameAuthorizationFactory).calcAuthorization(RESOURCE_NAME, DELETE_DATAHUB);
    assertEquals(expected, authorization);
}
Also used : HasRight(com.sequenceiq.authorization.service.model.HasRight) AuthorizationRule(com.sequenceiq.authorization.service.model.AuthorizationRule) Test(org.junit.Test)

Aggregations

HasRight (com.sequenceiq.authorization.service.model.HasRight)7 AuthorizationRule (com.sequenceiq.authorization.service.model.AuthorizationRule)3 Method (java.lang.reflect.Method)3 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 RightCheck (com.cloudera.thunderhead.service.authorization.AuthorizationProto.RightCheck)1 HasRightOnAny (com.sequenceiq.authorization.service.model.HasRightOnAny)1