use of eu.bcvsolutions.idm.acc.dto.SysSystemDto in project CzechIdMng by bcvsolutions.
the class AccountManagementTest method initIdentityData.
private SysSystemDto initIdentityData() {
// create test system
SysSystemDto system = helper.createSystem(TestResource.TABLE_NAME);
Assert.assertNotNull(system);
// generate schema for system
List<SysSchemaObjectClassDto> objectClasses = systemService.generateSchema(system);
// Create mapping
SysSystemMappingDto syncSystemMapping = new SysSystemMappingDto();
syncSystemMapping.setName("default_" + System.currentTimeMillis());
syncSystemMapping.setEntityType(SystemEntityType.IDENTITY);
syncSystemMapping.setOperationType(SystemOperationType.PROVISIONING);
syncSystemMapping.setObjectClass(objectClasses.get(0).getId());
final SysSystemMappingDto syncMapping = systemMappingService.save(syncSystemMapping);
createIdentityMapping(system, syncMapping);
return system;
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemDto in project CzechIdMng by bcvsolutions.
the class AccountProtectionExpirationTaskExecutorIntegrationTest method testRemoveExpiredAccount.
@Test
public void testRemoveExpiredAccount() {
IdmIdentityDto identity = helper.createIdentity();
IdmRoleDto role = helper.createRole();
SysSystemDto system = helper.createTestResourceSystem(true);
SysSystemMappingDto mapping = helper.getDefaultMapping(system);
mapping.setProtectionInterval(1);
mapping.setProtectionEnabled(true);
systemMappingService.save(mapping);
helper.createRoleSystem(role, system);
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, role);
//
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
identityRoleService.deleteById(identityRole.getId());
//
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertTrue(account.isInProtection());
Assert.assertNotNull(account.getEndOfProtection());
createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
//
// test LRT - nothing to remove
AccountProtectionExpirationTaskExecutor taskExecutor = new AccountProtectionExpirationTaskExecutor();
longRunningTaskManager.execute(taskExecutor);
//
account = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNotNull(account);
Assert.assertTrue(account.isInProtection());
Assert.assertNotNull(account.getEndOfProtection());
createdAccount = helper.findResource(account.getUid());
Assert.assertNotNull(createdAccount);
Assert.assertEquals(identity.getFirstName(), createdAccount.getFirstname());
// change account expiration
account.setEndOfProtection(new DateTime().minusDays(1));
account = accountService.save(account);
taskExecutor = new AccountProtectionExpirationTaskExecutor();
longRunningTaskManager.execute(taskExecutor);
AccAccountDto removedAccount = accountService.getAccount(identity.getUsername(), system.getId());
Assert.assertNull(removedAccount);
createdAccount = helper.findResource(account.getUid());
Assert.assertNull(createdAccount);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemDto 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.acc.dto.SysSystemDto 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.acc.dto.SysSystemDto in project CzechIdMng by bcvsolutions.
the class AccountProtectionSystemTest method accountWithoutProtectionTest.
@Test
public void accountWithoutProtectionTest() {
IdmIdentityDto identity = helper.createIdentity();
SysSystemDto system = initSystem();
IdmIdentityRoleDto identityRole = helper.createIdentityRole(identity, roleService.getByCode(ROLE_ONE));
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.assertNull(account);
createdAccount = entityManager.find(TestResource.class, identity.getUsername());
Assert.assertNull(createdAccount);
}
Aggregations