use of com.sequenceiq.authorization.service.model.AuthorizationRule in project cloudbreak by hortonworks.
the class ResourceCrnAthorizationProviderTest method testAuthorizationWhenEnvCrnNotPresent.
@Test
public void testAuthorizationWhenEnvCrnNotPresent() {
Optional<AuthorizationRule> expected = Optional.of(new HasRight(ACTION, RESOURCE_CRN));
when(environmentBasedAuthorizationProvider.getAuthorizations(RESOURCE_CRN, ACTION)).thenReturn(expected);
Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(), USER_CRN, null, null);
assertEquals(expected, authorization);
}
use of com.sequenceiq.authorization.service.model.AuthorizationRule in project cloudbreak by hortonworks.
the class ResourceCrnListAuthorizationFactoryTest method testAuthorization.
@Test
public void testAuthorization() {
when(defaultResourceAuthorizationProvider.authorizeDefaultOrElseCompute(eq(RESOURCE_CRNS), eq(ACTION), any())).then(i -> ((Function) i.getArgument(2)).apply(RESOURCE_CRNS));
when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(RESOURCE_CRNS);
Optional<AuthorizationRule> expected = Optional.of(new HasRightOnAll(ACTION, RESOURCE_CRNS));
when(environmentBasedAuthorizationProvider.getAuthorizations(anyCollection(), any())).thenReturn(expected);
Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(), USER_CRN, null, null);
verify(commonPermissionCheckingUtils).getParameter(any(), any(), eq(ResourceCrnList.class), eq(Collection.class));
assertEquals(expected, authorization);
}
use of com.sequenceiq.authorization.service.model.AuthorizationRule in project cloudbreak by hortonworks.
the class RequestPropertyAuthorizationFactoryTest method testOnCrn.
@Test
public void testOnCrn() {
when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(new SampleRequestObject(RESOURCE_CRN));
Optional<AuthorizationRule> expected = Optional.of(new HasRight(EDIT_CREDENTIAL, RESOURCE_CRN));
when(resourceCrnAthorizationFactory.calcAuthorization(anyString(), any())).thenReturn(expected);
Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(CRN, EDIT_CREDENTIAL, false, "field"), USER_CRN, null, null);
verify(resourceCrnAthorizationFactory).calcAuthorization(RESOURCE_CRN, EDIT_CREDENTIAL);
assertEquals(expected, authorization);
}
use of com.sequenceiq.authorization.service.model.AuthorizationRule in project cloudbreak by hortonworks.
the class RequestPropertyAuthorizationFactoryTest method testOnNameList.
@Test
public void testOnNameList() {
when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(new SampleRequestObject(List.of(RESOURCE_NAME)));
Optional<AuthorizationRule> expected = Optional.of(new HasRightOnAll(EDIT_CREDENTIAL, List.of(RESOURCE_CRN)));
when(resourceNameListAuthorizationFactory.calcAuthorization(anyCollection(), any())).thenReturn(expected);
Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(NAME_LIST, EDIT_CREDENTIAL, false, "field"), USER_CRN, null, null);
verify(resourceNameListAuthorizationFactory).calcAuthorization(List.of(RESOURCE_NAME), EDIT_CREDENTIAL);
assertEquals(expected, authorization);
}
use of com.sequenceiq.authorization.service.model.AuthorizationRule in project cloudbreak by hortonworks.
the class RequestPropertyAuthorizationFactoryTest method testOnCrnList.
@Test
public void testOnCrnList() {
when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(new SampleRequestObject(List.of(RESOURCE_CRN)));
Optional<AuthorizationRule> expected = Optional.of(new HasRightOnAll(EDIT_CREDENTIAL, List.of(RESOURCE_CRN)));
when(resourceCrnListAuthorizationFactory.calcAuthorization(anyCollection(), any())).thenReturn(expected);
Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(CRN_LIST, EDIT_CREDENTIAL, false, "field"), USER_CRN, null, null);
verify(resourceCrnListAuthorizationFactory).calcAuthorization(List.of(RESOURCE_CRN), EDIT_CREDENTIAL);
assertEquals(expected, authorization);
}
Aggregations