Search in sources :

Example 1 with HasRightOnAll

use of com.sequenceiq.authorization.service.model.HasRightOnAll 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);
}
Also used : ResourceCrnList(com.sequenceiq.authorization.annotation.ResourceCrnList) CheckPermissionByResourceCrnList(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrnList) Collection(java.util.Collection) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) AuthorizationRule(com.sequenceiq.authorization.service.model.AuthorizationRule) HasRightOnAll(com.sequenceiq.authorization.service.model.HasRightOnAll) Test(org.junit.Test)

Example 2 with HasRightOnAll

use of com.sequenceiq.authorization.service.model.HasRightOnAll 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);
}
Also used : AuthorizationRule(com.sequenceiq.authorization.service.model.AuthorizationRule) HasRightOnAll(com.sequenceiq.authorization.service.model.HasRightOnAll) Test(org.junit.Test)

Example 3 with HasRightOnAll

use of com.sequenceiq.authorization.service.model.HasRightOnAll 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);
}
Also used : AuthorizationRule(com.sequenceiq.authorization.service.model.AuthorizationRule) HasRightOnAll(com.sequenceiq.authorization.service.model.HasRightOnAll) Test(org.junit.Test)

Example 4 with HasRightOnAll

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

the class ResourceNameListAuthorizationFactoryTest method testAuthorization.

@Test
public void testAuthorization() {
    when(commonPermissionCheckingUtils.getParameter(any(), any(), any(), any())).thenReturn(RESOURCES);
    when(resourceBasedCrnProvider.getResourceCrnListByResourceNameList(anyList())).thenReturn(RESOURCE_CRNS);
    Optional<AuthorizationRule> expected = Optional.of(new HasRightOnAll(ACTION, RESOURCE_CRNS));
    when(resourceCrnListAuthorizationFactory.calcAuthorization(anyCollection(), any())).thenReturn(expected);
    Optional<AuthorizationRule> authorization = underTest.getAuthorization(getAnnotation(), USER_CRN, null, null);
    verify(commonPermissionCheckingUtils).getParameter(any(), any(), eq(ResourceNameList.class), eq(Collection.class));
    verify(resourceCrnListAuthorizationFactory).calcAuthorization(RESOURCE_CRNS, ACTION);
    assertEquals(expected, authorization);
}
Also used : CheckPermissionByResourceNameList(com.sequenceiq.authorization.annotation.CheckPermissionByResourceNameList) ResourceNameList(com.sequenceiq.authorization.annotation.ResourceNameList) Collection(java.util.Collection) ArgumentMatchers.anyCollection(org.mockito.ArgumentMatchers.anyCollection) AuthorizationRule(com.sequenceiq.authorization.service.model.AuthorizationRule) HasRightOnAll(com.sequenceiq.authorization.service.model.HasRightOnAll) Test(org.junit.Test)

Aggregations

AuthorizationRule (com.sequenceiq.authorization.service.model.AuthorizationRule)4 HasRightOnAll (com.sequenceiq.authorization.service.model.HasRightOnAll)4 Test (org.junit.Test)4 Collection (java.util.Collection)2 ArgumentMatchers.anyCollection (org.mockito.ArgumentMatchers.anyCollection)2 CheckPermissionByResourceCrnList (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrnList)1 CheckPermissionByResourceNameList (com.sequenceiq.authorization.annotation.CheckPermissionByResourceNameList)1 ResourceCrnList (com.sequenceiq.authorization.annotation.ResourceCrnList)1 ResourceNameList (com.sequenceiq.authorization.annotation.ResourceNameList)1