Search in sources :

Example 1 with IdmIdentity

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity 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 2 with IdmIdentity

use of eu.bcvsolutions.idm.core.model.entity.IdmIdentity 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 3 with IdmIdentity

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

the class DefaultFormServiceItegrationTest method testUnpersistedOwnerWithId.

@Test
public void testUnpersistedOwnerWithId() {
    // unpersisted identity
    FormableEntity owner = new IdmIdentity(UUID.randomUUID());
    assertTrue(formService.getValues(owner).isEmpty());
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) FormableEntity(eu.bcvsolutions.idm.core.eav.api.entity.FormableEntity) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with IdmIdentity

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

the class DefaultAuditServiceTest method diffAuditTest.

@Test
public void diffAuditTest() {
    IdmIdentityDto identity = this.constructIdentity("test_diff", "John", "Doe");
    identity = saveInTransaction(identity, identityService);
    // identityRepository.save(identity);
    identity = identityService.get(identity.getId());
    identity.setEmail("example@example.ex");
    identity.setFirstName("Leonard");
    identity.setLastName("Nimoy");
    identity = saveInTransaction(identity, identityService);
    // identityRepository.save(identity);
    identity = identityService.get(identity.getId());
    identity.setEmail(null);
    identity.setFirstName("John");
    identity.setLastName("Doe");
    identity = saveInTransaction(identity, identityService);
    List<IdmAuditDto> result = auditService.findRevisions(IdmIdentity.class, identity.getId());
    assertEquals(3, result.size());
    getTransactionTemplate().execute(new TransactionCallback<Object>() {

        public Object doInTransaction(TransactionStatus transactionStatus) {
            IdmAuditDto idmAudit = result.get(0);
            IdmIdentity version1 = auditService.findVersion(IdmIdentity.class, idmAudit.getEntityId(), Long.parseLong(idmAudit.getId().toString()));
            idmAudit = result.get(1);
            IdmIdentity version2 = auditService.findVersion(IdmIdentity.class, idmAudit.getEntityId(), Long.parseLong(idmAudit.getId().toString()));
            idmAudit = result.get(2);
            IdmIdentity version3 = auditService.findVersion(IdmIdentity.class, idmAudit.getEntityId(), Long.parseLong(idmAudit.getId().toString()));
            // sample test to default value
            assertEquals(version1.getFirstName(), "John");
            assertEquals(version1.getLastName(), "Doe");
            assertEquals(version2.getFirstName(), "Leonard");
            assertEquals(version2.getLastName(), "Nimoy");
            assertEquals(version2.getEmail(), "example@example.ex");
            assertEquals(version3.getFirstName(), "John");
            assertEquals(version3.getLastName(), "Doe");
            assertNull(version3.getEmail());
            // get diff between version
            // test version #1 with #2
            Map<String, Object> diff = auditService.getDiffBetweenVersion(parseSerializableToString(result.get(0).getId()), parseSerializableToString(result.get(1).getId()));
            // 3 modification from IdmIdentity
            assertEquals(3, diff.size());
            assertTrue(diff.containsKey("firstName"));
            assertTrue(diff.containsKey("lastName"));
            assertTrue(diff.containsKey("email"));
            assertEquals("Leonard", diff.get("firstName"));
            assertEquals("Nimoy", diff.get("lastName"));
            assertEquals("example@example.ex", diff.get("email"));
            // test version #2 with #3
            diff = auditService.getDiffBetweenVersion(parseSerializableToString(result.get(1).getId()), parseSerializableToString(result.get(2).getId()));
            // 3 modification from IdmIdentity
            assertEquals(3, diff.size());
            assertTrue(diff.containsKey("firstName"));
            assertTrue(diff.containsKey("lastName"));
            assertTrue(diff.containsKey("email"));
            assertEquals("John", diff.get("firstName"));
            assertEquals("Doe", diff.get("lastName"));
            assertEquals(null, diff.get("email"));
            // final test version #1 with #3
            diff = auditService.getDiffBetweenVersion(parseSerializableToString(result.get(0).getId()), parseSerializableToString(result.get(2).getId()));
            // all diff values are from AbstractEntity modifier, modified date, modifier id
            // modified only
            assertEquals(0, diff.size());
            return null;
        }
    });
}
Also used : IdmAuditDto(eu.bcvsolutions.idm.core.api.audit.dto.IdmAuditDto) TransactionStatus(org.springframework.transaction.TransactionStatus) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with IdmIdentity

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

the class IdentityFindPositionsTest method testFindManagers.

@Test
public void testFindManagers() {
    FilterBuilder<IdmIdentity, DataFilter> filterBuilderSubordinates = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_SUBORDINATES_FOR);
    FilterBuilder<IdmIdentity, DataFilter> filterBuilderManagers = filterManager.getBuilder(IdmIdentity.class, IdmIdentityFilter.PARAMETER_MANAGERS_FOR);
    FilterBuilder<IdmIdentityContract, DataFilter> filterBuilderContractByManager = filterManager.getBuilder(IdmIdentityContract.class, IdmIdentityContractFilter.PARAMETER_SUBORDINATES_FOR);
    Assert.assertEquals(DefaultManagersFilter.FILTER_NAME, filterBuilderManagers.getId());
    Assert.assertEquals(DefaultSubordinatesFilter.FILTER_NAME, filterBuilderSubordinates.getId());
    Assert.assertEquals(DefaultContractByManagerFilter.FILTER_NAME, filterBuilderContractByManager.getId());
    Assert.assertFalse(filterBuilderSubordinates.isDisabled());
    Assert.assertFalse(filterBuilderManagers.isDisabled());
    Assert.assertFalse(filterBuilderContractByManager.isDisabled());
    // 
    IdmIdentityDto user = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto user2 = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto user3 = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto user4 = getHelper().createIdentity((GuardedString) null);
    IdmTreeTypeDto treeTypeFirst = getHelper().createTreeType();
    IdmTreeTypeDto treeTypeSecond = getHelper().createTreeType();
    // create root for second type
    getHelper().createTreeNode(treeTypeSecond, null);
    // create root for first type
    IdmTreeNodeDto nodeRoot = getHelper().createTreeNode(treeTypeFirst, null);
    // create one for first type
    IdmTreeNodeDto nodeOne = getHelper().createTreeNode(treeTypeFirst, nodeRoot);
    // create two for first type
    IdmTreeNodeDto nodeTwo = getHelper().createTreeNode(treeTypeFirst, nodeOne);
    createIdentityContract(user, null, nodeRoot);
    createIdentityContract(user2, null, nodeOne);
    createIdentityContract(user3, null, nodeOne);
    createIdentityContract(user4, null, nodeTwo);
    // createIdentityContract(user, manager3, null);
    List<IdmIdentityDto> managersList = identityService.findAllManagers(user3.getId(), treeTypeFirst.getId());
    assertEquals(1, managersList.size());
    IdmIdentityDto manager = managersList.get(0);
    assertEquals(user.getId(), manager.getId());
    managersList = identityService.findAllManagers(user4.getId(), treeTypeFirst.getId(), Boolean.TRUE);
    assertEquals(2, managersList.size());
    managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
    assertEquals(1, managersList.size());
    createIdentityContract(user, null, nodeTwo);
    managersList = identityService.findAllManagers(user.getId(), treeTypeFirst.getId());
    assertEquals(2, managersList.size());
    List<IdmIdentityDto> managersListSec = identityService.findAllManagers(user.getId(), treeTypeSecond.getId());
    // user with superAdminRole
    assertEquals(1, managersListSec.size());
}
Also used : DataFilter(eu.bcvsolutions.idm.core.api.dto.filter.DataFilter) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)58 Test (org.junit.Test)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)28 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)20 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)18 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)13 Transactional (org.springframework.transaction.annotation.Transactional)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)7 DataFilter (eu.bcvsolutions.idm.core.api.dto.filter.DataFilter)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 IdmIdentityContract (eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)5 Assert (org.junit.Assert)5 IdmAuthorityChange (eu.bcvsolutions.idm.core.model.entity.IdmAuthorityChange)4 UUID (java.util.UUID)4 Identifiable (eu.bcvsolutions.idm.core.api.domain.Identifiable)3 IdmEntityEventDto (eu.bcvsolutions.idm.core.api.dto.IdmEntityEventDto)3 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)3