Search in sources :

Example 1 with IdmRole

use of eu.bcvsolutions.idm.core.model.entity.IdmRole in project CzechIdMng by bcvsolutions.

the class BasePermissionEvaluatorUnitTest method testEvaluateReadOnly.

@Test
public void testEvaluateReadOnly() {
    IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
    UUID uuid = UUID.randomUUID();
    IdmRole authorizable = new IdmRole(uuid);
    policy.setPermissions(IdmBasePermission.READ);
    // 
    assertTrue(evaluator.evaluate(authorizable, policy, IdmBasePermission.READ));
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.UPDATE));
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.ADMIN));
}
Also used : IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) UUID(java.util.UUID) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 2 with IdmRole

use of eu.bcvsolutions.idm.core.model.entity.IdmRole in project CzechIdMng by bcvsolutions.

the class UuidEvaluatorUnitTest method testEvaluateAdminPermission.

@Test
public void testEvaluateAdminPermission() {
    IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
    UUID uuid = UUID.randomUUID();
    IdmRole authorizable = new IdmRole(uuid);
    policy.getEvaluatorProperties().put(UuidEvaluator.PARAMETER_UUID, uuid);
    policy.setPermissions(IdmBasePermission.ADMIN);
    // 
    assertTrue(evaluator.evaluate(authorizable, policy, IdmBasePermission.READ));
    assertTrue(evaluator.evaluate(authorizable, policy, IdmBasePermission.UPDATE));
    assertTrue(evaluator.evaluate(authorizable, policy, IdmBasePermission.ADMIN));
}
Also used : IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) UUID(java.util.UUID) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 3 with IdmRole

use of eu.bcvsolutions.idm.core.model.entity.IdmRole in project CzechIdMng by bcvsolutions.

the class RoleGuaranteeEvaluatorUnitTest method testEvaluateReadOnly.

@Test
public void testEvaluateReadOnly() {
    IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
    UUID uuid = UUID.randomUUID();
    IdmRole authorizable = new IdmRole();
    IdmRoleGuarantee guarantee = new IdmRoleGuarantee();
    guarantee.setGuarantee(new IdmIdentity(uuid));
    authorizable.getGuarantees().add(guarantee);
    policy.setPermissions(IdmBasePermission.READ);
    // 
    when(securityService.getAuthentication()).thenReturn(getAuthentication(uuid));
    // 
    assertTrue(evaluator.evaluate(authorizable, policy, IdmBasePermission.READ));
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.UPDATE));
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.ADMIN));
}
Also used : IdmRoleGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) UUID(java.util.UUID) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 4 with IdmRole

use of eu.bcvsolutions.idm.core.model.entity.IdmRole in project CzechIdMng by bcvsolutions.

the class RoleGuaranteeEvaluatorUnitTest method testEvaluateFalse.

@Test
public void testEvaluateFalse() {
    IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
    IdmRole authorizable = new IdmRole();
    IdmRoleGuarantee guarantee = new IdmRoleGuarantee();
    guarantee.setGuarantee(new IdmIdentity(UUID.randomUUID()));
    authorizable.getGuarantees().add(guarantee);
    policy.setPermissions(IdmBasePermission.READ);
    // 
    when(securityService.getAuthentication()).thenReturn(getAuthentication());
    // 
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.READ));
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.UPDATE));
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.ADMIN));
}
Also used : IdmRoleGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 5 with IdmRole

use of eu.bcvsolutions.idm.core.model.entity.IdmRole in project CzechIdMng by bcvsolutions.

the class RoleGuaranteeEvaluatorUnitTest method testEvaluateEmptyGuarantee.

@Test
public void testEvaluateEmptyGuarantee() {
    IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
    IdmRole authorizable = new IdmRole();
    policy.setPermissions(IdmBasePermission.READ);
    // 
    when(securityService.getAuthentication()).thenReturn(getAuthentication());
    // 
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.READ));
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.UPDATE));
    assertFalse(evaluator.evaluate(authorizable, policy, IdmBasePermission.ADMIN));
}
Also used : IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Aggregations

IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)15 Test (org.junit.Test)13 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)9 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)7 UUID (java.util.UUID)7 IdmRoleGuarantee (eu.bcvsolutions.idm.core.model.entity.IdmRoleGuarantee)4 ArrayList (java.util.ArrayList)4 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)2 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)2 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)2 AbstractVerifiableUnitTest (eu.bcvsolutions.idm.test.api.AbstractVerifiableUnitTest)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)1 AccountType (eu.bcvsolutions.idm.acc.domain.AccountType)1 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)1 SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)1 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)1