use of eu.bcvsolutions.idm.core.api.dto.IdmRoleDto in project CzechIdMng by bcvsolutions.
the class IdentityRoleValidRequestSchedulerTest method createAndSaveRole.
private IdmRoleDto createAndSaveRole() {
IdmRoleDto entity = new IdmRoleDto();
entity.setName("valid_role_" + System.currentTimeMillis());
return saveInTransaction(entity, roleService);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAuthenticatorTest method initData.
private void initData() {
SysSystemDto system = createTestSystem();
List<SysSchemaObjectClassDto> objectClasses = sysSystemService.generateSchema(system);
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername(USERNAME);
identity.setLastName(USERNAME);
identity.setPassword(new GuardedString(PASSWORD));
identity = identityService.save(identity);
// Create mapped attributes to schema
SysSystemMappingDto systemMapping = new SysSystemMappingDto();
systemMapping.setName("default_" + System.currentTimeMillis());
systemMapping.setEntityType(SystemEntityType.IDENTITY);
systemMapping.setOperationType(SystemOperationType.PROVISIONING);
systemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto entityHandlingResult = systemEntityHandlingService.save(systemMapping);
SysSchemaAttributeFilter schemaAttributeFilter = new SysSchemaAttributeFilter();
schemaAttributeFilter.setSystemId(system.getId());
SysSystemAttributeMappingDto attributeHandlingLastName = new SysSystemAttributeMappingDto();
SysSystemAttributeMappingDto attributeHandlingPassword = new SysSystemAttributeMappingDto();
SysSystemAttributeMappingDto attributeHandlingUsername = new SysSystemAttributeMappingDto();
Page<SysSchemaAttributeDto> schemaAttributesPage = schemaAttributeService.find(schemaAttributeFilter, null);
for (SysSchemaAttributeDto schemaAttr : schemaAttributesPage) {
if ("__NAME__".equals(schemaAttr.getName())) {
attributeHandlingUsername.setUid(true);
attributeHandlingUsername.setEntityAttribute(true);
attributeHandlingUsername.setAuthenticationAttribute(true);
attributeHandlingUsername.setIdmPropertyName("username");
attributeHandlingUsername.setTransformToResourceScript("if(attributeValue){return \"x\"+ attributeValue;}");
attributeHandlingUsername.setName(schemaAttr.getName());
attributeHandlingUsername.setSchemaAttribute(schemaAttr.getId());
attributeHandlingUsername.setSystemMapping(entityHandlingResult.getId());
attributeHandlingUsername = schemaAttributeHandlingService.save(attributeHandlingUsername);
} else if ("lastname".equalsIgnoreCase(schemaAttr.getName())) {
attributeHandlingLastName.setIdmPropertyName("lastName");
attributeHandlingLastName.setName(schemaAttr.getName());
attributeHandlingLastName.setSchemaAttribute(schemaAttr.getId());
attributeHandlingLastName.setSystemMapping(entityHandlingResult.getId());
attributeHandlingLastName = schemaAttributeHandlingService.save(attributeHandlingLastName);
} else if (IcConnectorFacade.PASSWORD_ATTRIBUTE_NAME.equalsIgnoreCase(schemaAttr.getName())) {
attributeHandlingPassword.setIdmPropertyName("password");
attributeHandlingPassword.setSchemaAttribute(schemaAttr.getId());
attributeHandlingPassword.setName(schemaAttr.getName());
attributeHandlingPassword.setSystemMapping(entityHandlingResult.getId());
attributeHandlingPassword = schemaAttributeHandlingService.save(attributeHandlingPassword);
}
}
// create two roles with same system and different override username
IdmRoleDto role1 = new IdmRoleDto();
role1.setName(ROLE_NAME);
role1 = roleService.save(role1);
SysRoleSystemDto role1System = new SysRoleSystemDto();
role1System.setRole(role1.getId());
role1System.setSystem(system.getId());
role1System.setSystemMapping(entityHandlingResult.getId());
role1System = roleSystemService.save(role1System);
IdmRoleDto role2 = new IdmRoleDto();
role2.setName(ROLE_NAME + "2");
role2 = roleService.save(role2);
SysRoleSystemDto roleSystem2 = new SysRoleSystemDto();
roleSystem2.setSystem(system.getId());
roleSystem2.setSystemMapping(entityHandlingResult.getId());
roleSystem2.setRole(role2.getId());
roleSystem2 = roleSystemService.save(roleSystem2);
SysRoleSystemAttributeDto overloadedRole2 = new SysRoleSystemAttributeDto();
overloadedRole2.setSystemAttributeMapping(attributeHandlingUsername.getId());
overloadedRole2.setUid(true);
overloadedRole2.setEntityAttribute(true);
overloadedRole2.setTransformScript("return \"z" + USERNAME + "\";");
overloadedRole2.setIdmPropertyName("username");
overloadedRole2.setName("username");
overloadedRole2.setRoleSystem(roleSystem2.getId());
overloadedRole2 = roleSystemAttributeService.save(overloadedRole2);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleDto in project CzechIdMng by bcvsolutions.
the class IdentityAccountByRoleEvaluatorIntegrationTest method testCanReadIdentityAccount.
@Test
public void testCanReadIdentityAccount() {
IdmIdentityDto identity;
AccIdentityAccountDto accountIdentityOne;
try {
loginAsAdmin(InitApplicationData.ADMIN_USERNAME);
//
identity = helper.createIdentity();
SysSystemDto system = helper.createTestResourceSystem(true);
AccAccountDto accountOne = new AccAccountDto();
accountOne.setSystem(system.getId());
accountOne.setUid(identity.getUsername());
accountOne.setAccountType(AccountType.PERSONAL);
accountOne = accountService.save(accountOne);
accountIdentityOne = new AccIdentityAccountDto();
accountIdentityOne.setIdentity(identity.getId());
accountIdentityOne.setOwnership(true);
accountIdentityOne.setAccount(accountOne.getId());
accountIdentityOne = identityAccountService.save(accountIdentityOne);
IdmRoleDto role = helper.createRole();
IdmRoleDto defaultRole = roleService.getByCode(InitDemoData.DEFAULT_ROLE_NAME);
IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
policy.setRole(role.getId());
policy.setGroupPermission(AccGroupPermission.IDENTITYACCOUNT.getName());
policy.setAuthorizableType(AccIdentityAccount.class.getCanonicalName());
policy.setEvaluator(IdentityAccountByAccountEvaluator.class);
authorizationPolicyService.save(policy);
IdmAuthorizationPolicyDto policyAccount = new IdmAuthorizationPolicyDto();
policyAccount.setRole(role.getId());
policyAccount.setGroupPermission(AccGroupPermission.ACCOUNT.getName());
policyAccount.setAuthorizableType(AccAccount.class.getCanonicalName());
policyAccount.setEvaluator(ReadAccountByIdentityEvaluator.class);
authorizationPolicyService.save(policyAccount);
helper.createIdentityRole(identity, role);
helper.createIdentityRole(identity, defaultRole);
} finally {
logout();
}
// check
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
AccIdentityAccountDto read = identityAccountService.get(accountIdentityOne.getId(), IdmBasePermission.READ);
Assert.assertEquals(accountIdentityOne, read);
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleDto in project CzechIdMng by bcvsolutions.
the class RoleAccountByRoleEvaluatorIntegrationTest method testReadRoleWithEvaluator.
@Test
public void testReadRoleWithEvaluator() {
IdmIdentityDto identity = createIdentityWithRole(true);
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
IdmRoleDto role = roleService.get(TEST_ROLE_ID, IdmBasePermission.READ);
assertEquals(TEST_ROLE_ID, role.getId());
assertEquals(1, roleService.find(null, IdmBasePermission.READ).getTotalElements());
assertEquals(3, authorizationPolicyService.find(null, IdmBasePermission.READ).getTotalElements());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleDto in project CzechIdMng by bcvsolutions.
the class AccountProtectionSystemTest method accountWithProtectionAndIntervalTest.
@Test
public void accountWithProtectionAndIntervalTest() {
IdmIdentityDto identity = helper.createIdentity();
SysSystemDto system = initSystem();
IdmRoleDto roleOne = roleService.getByCode(ROLE_ONE);
int intervalInDays = 10;
// Set system to protected mode
SysSystemMappingDto mapping = systemMappingService.findBySystem(system, SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY).get(0);
mapping.setProtectionEnabled(Boolean.TRUE);
mapping.setProtectionInterval(intervalInDays);
mapping = systemMappingService.save(mapping);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, roleOne);
AccAccountDto account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertFalse(account.isInProtection());
TestResource createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
// Remove role from identity
identityRoleService.deleteById(identityRole.getId());
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertTrue(account.isInProtection());
Assert.assertNotNull(account.getEndOfProtection());
Assert.assertTrue(account.getEndOfProtection().toLocalDate().isEqual(LocalDate.now().plusDays(intervalInDays)));
createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
}
Aggregations