Search in sources :

Example 1 with AuthorizationRule

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

Example 2 with AuthorizationRule

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);
}
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 3 with AuthorizationRule

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

Example 4 with AuthorizationRule

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

Example 5 with AuthorizationRule

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);
}
Also used : 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)9 Test (org.junit.Test)8 HasRightOnAll (com.sequenceiq.authorization.service.model.HasRightOnAll)4 HasRight (com.sequenceiq.authorization.service.model.HasRight)3 Collection (java.util.Collection)2 ArgumentMatchers.anyCollection (org.mockito.ArgumentMatchers.anyCollection)2 AuthorizationProto (com.cloudera.thunderhead.service.authorization.AuthorizationProto)1 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 HasRightOnAny (com.sequenceiq.authorization.service.model.HasRightOnAny)1