Search in sources :

Example 41 with IdmRoleDto

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);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)

Example 42 with IdmRoleDto

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);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSchemaAttributeFilter) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 43 with IdmRoleDto

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();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AccAccount(eu.bcvsolutions.idm.acc.entity.AccAccount) AccIdentityAccount(eu.bcvsolutions.idm.acc.entity.AccIdentityAccount) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 44 with IdmRoleDto

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();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 45 with IdmRoleDto

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)288 Test (org.junit.Test)227 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)209 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)159 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)99 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)74 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)59 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)51 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)50 ArrayList (java.util.ArrayList)50 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)45 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)44 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)44 List (java.util.List)40 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)37 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)36 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)35 UUID (java.util.UUID)35 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)32 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)32