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