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());
}
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);
}
Aggregations