Search in sources :

Example 16 with IdmIdentity

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

the class DefaultAuditServiceIntegrationTest method diffAuditTest.

@Test
public void diffAuditTest() {
    IdmIdentityDto identity = this.constructIdentity("John", "Doe");
    identity = saveInTransaction(identity, identityService);
    identity = identityService.get(identity.getId());
    identity.setEmail("example@example.ex");
    identity.setFirstName("Leonard");
    identity.setLastName("Nimoy");
    identity = saveInTransaction(identity, identityService);
    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) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 17 with IdmIdentity

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

the class DefaultIdmIdentityServiceUnitTest method testDisabledState.

@Test
public void testDisabledState() {
    IdmIdentity identity = new IdmIdentity(UUID.randomUUID());
    IdmIdentityContractDto contractOne = new IdmIdentityContractDto();
    contractOne.setState(ContractState.DISABLED);
    IdmIdentityContractDto contractTwo = new IdmIdentityContractDto();
    contractTwo.setState(ContractState.DISABLED);
    when(repository.findById(identity.getId())).thenReturn(Optional.of(identity));
    when(identityContractService.findAllByIdentity(identity.getId())).thenReturn(Lists.newArrayList(contractOne, contractTwo));
    // 
    Assert.assertEquals(IdentityState.LEFT, service.evaluateState(identity.getId()));
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 18 with IdmIdentity

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

the class DefaultIdmIdentityServiceUnitTest method testDisabledManuallyState.

@Test
public void testDisabledManuallyState() {
    IdmIdentity identity = new IdmIdentity(UUID.randomUUID());
    identity.setState(IdentityState.DISABLED_MANUALLY);
    when(repository.findById(identity.getId())).thenReturn(Optional.of(identity));
    // 
    Assert.assertEquals(IdentityState.DISABLED_MANUALLY, service.evaluateState(identity.getId()));
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 19 with IdmIdentity

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

the class DefaultIdmIdentityServiceUnitTest method testValidState.

@Test
public void testValidState() {
    IdmIdentity identity = new IdmIdentity(UUID.randomUUID());
    IdmIdentityContractDto contractOne = new IdmIdentityContractDto();
    contractOne.setState(ContractState.DISABLED);
    IdmIdentityContractDto contractTwo = new IdmIdentityContractDto();
    when(repository.findById(identity.getId())).thenReturn(Optional.of(identity));
    when(identityContractService.findAllByIdentity(identity.getId())).thenReturn(Lists.newArrayList(contractOne, contractTwo));
    // 
    Assert.assertEquals(IdentityState.VALID, service.evaluateState(identity.getId()));
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 20 with IdmIdentity

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

the class SelfContractEvaluator method getPermissions.

@Override
public Set<String> getPermissions(IdmIdentityContract entity, AuthorizationPolicy policy) {
    Set<String> permissions = super.getPermissions(entity, policy);
    if (entity == null || !securityService.isAuthenticated()) {
        return permissions;
    }
    IdmIdentity identity = entity.getIdentity();
    if (identity != null && securityService.getCurrentId().equals(identity.getId())) {
        permissions.addAll(policy.getPermissions());
    }
    return permissions;
}
Also used : IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity)

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