Search in sources :

Example 16 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.

the class IdentitySetPasswordProcessorIntegrationTest method testGeneratePassword.

@Test
public void testGeneratePassword() {
    SysSystemDto system = helper.createTestResourceSystem(true);
    // 
    IdmRoleDto role = helper.createRole();
    helper.createRoleSystem(role, system);
    IdmIdentityDto identity = helper.createIdentity();
    IdmIdentityContractDto contract = helper.getPrimeContract(identity.getId());
    contract.setValidFrom(new LocalDate().plusDays(1));
    identityContractService.save(contract);
    identity = identityService.get(identity.getId());
    Assert.assertEquals(IdentityState.FUTURE_CONTRACT, identity.getState());
    helper.createIdentityRole(identity, role);
    // 
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    AccIdentityAccountDto accountIdentityOne = identityAccountService.find(filter, null).getContent().get(0);
    AccAccountDto account = accountService.get(accountIdentityOne.getAccount());
    // Create new password one
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setAccounts(ImmutableList.of(account.getId().toString()));
    passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_ONE));
    passwordChange.setIdm(true);
    // 
    // Do change of password for selected accounts
    identityService.passwordChange(identity, passwordChange);
    // 
    // Check correct password One
    TestResource resource = helper.findResource(account.getRealUid());
    Assert.assertNotNull(resource);
    Assert.assertEquals(IDENTITY_PASSWORD_ONE, resource.getPassword());
    // 
    // set contract to valid
    contract.setValidFrom(new LocalDate());
    identityContractService.save(contract);
    identity = identityService.get(identity.getId());
    Assert.assertEquals(IdentityState.VALID, identity.getState());
    // 
    // check password on target system was changed
    resource = helper.findResource(account.getRealUid());
    Assert.assertNotNull(resource);
    Assert.assertNotEquals(IDENTITY_PASSWORD_ONE, resource.getPassword());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(org.joda.time.LocalDate) 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 17 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.

the class ProvisioningBreakProcessorTest method createAccount.

/**
 * Create {@link AccAccountDto} and {@link AccIdentityAccountDto} for system
 * and identity
 *
 * @param system
 * @param identity
 * @return
 */
private AccIdentityAccountDto createAccount(SysSystemDto system, IdmIdentityDto identity) {
    AccAccountDto account = new AccAccountDto();
    account.setSystem(system.getId());
    account.setUid(identity.getUsername());
    account.setAccountType(AccountType.PERSONAL);
    account.setEntityType(SystemEntityType.IDENTITY);
    account = accountService.save(account);
    AccIdentityAccountDto accountIdentity = new AccIdentityAccountDto();
    accountIdentity.setIdentity(identity.getId());
    accountIdentity.setOwnership(true);
    accountIdentity.setAccount(account.getId());
    return identityAccoutnService.save(accountIdentity);
}
Also used : AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)

Example 18 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto 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);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AccountProtectionExpirationTaskExecutor(eu.bcvsolutions.idm.acc.scheduler.task.impl.AccountProtectionExpirationTaskExecutor) 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) DateTime(org.joda.time.DateTime) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 19 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto in project CzechIdMng by bcvsolutions.

the class AccountProtectionExpirationTaskExecutorUnitTest method testTwoPageIterations.

@Test
public void testTwoPageIterations() {
    List<AccAccountDto> accounts = new ArrayList<>();
    accounts.add(new AccAccountDto());
    accounts.add(new AccAccountDto());
    // 
    when(service.findExpired(any(DateTime.class), any(PageRequest.class))).thenReturn(new PageImpl<AccAccountDto>(accounts));
    // 
    doNothing().when(service).delete(any(AccAccountDto.class));
    // 
    when(executor.updateState()).thenReturn(true);
    // 
    Boolean result = executor.process();
    Assert.assertTrue(result);
    Assert.assertEquals(Long.valueOf(2), executor.getCount());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) ArrayList(java.util.ArrayList) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) DateTime(org.joda.time.DateTime) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 20 with AccAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccAccountDto 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)

Aggregations

AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)90 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)59 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)47 Test (org.junit.Test)45 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)44 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)33 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)29 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)25 AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)19 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)18 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)18 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)16 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)16 ArrayList (java.util.ArrayList)16 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)15 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)14 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)14 UUID (java.util.UUID)14 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)13