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;
}
});
}
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()));
}
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()));
}
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()));
}
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;
}
Aggregations