Search in sources :

Example 46 with AccIdentityAccountFilter

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

the class DefaultAccAuthenticatorTest method loginAgainstTwoAccount.

@Test
public void loginAgainstTwoAccount() {
    IdmIdentityDto identity = identityService.getByUsername(USERNAME);
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(filter, null).getContent();
    // get account distinct for identityAccounts
    List<String> accountIds = new ArrayList<>();
    for (AccIdentityAccountDto identityAccount : identityAccounts) {
        if (!accountIds.contains(identityAccount.getAccount().toString())) {
            accountIds.add(identityAccount.getAccount().toString());
        }
    }
    assertEquals(1, accountIds.size());
    assertEquals(1, identityAccounts.size());
    IdmRoleDto role2 = roleService.getByCode(ROLE_NAME + "2");
    IdmIdentityRoleDto irdto = new IdmIdentityRoleDto();
    irdto.setIdentityContract(identityContractService.findAllByIdentity(identity.getId()).get(0).getId());
    irdto.setRole(role2.getId());
    irdto = identityRoleService.save(irdto);
    identityAccounts = identityAccountService.find(filter, null).getContent();
    // get account distinct for identityAccounts
    accountIds = new ArrayList<>();
    for (AccIdentityAccountDto identityAccount : identityAccounts) {
        if (!accountIds.contains(identityAccount.getAccount().toString())) {
            accountIds.add(identityAccount.getAccount().toString());
        }
    }
    assertEquals(2, accountIds.size());
    assertEquals(2, identityAccounts.size());
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    List<String> accs = new ArrayList<>();
    accs.add(accountIds.get(0));
    passwordChangeDto.setAccounts(accs);
    passwordChangeDto.setAll(false);
    passwordChangeDto.setNewPassword(new GuardedString("1234"));
    // change password for system
    provisioningService.changePassword(identity, passwordChangeDto);
    passwordChangeDto = new PasswordChangeDto();
    accs = new ArrayList<>();
    accs.add(accountIds.get(1));
    passwordChangeDto.setAccounts(accs);
    passwordChangeDto.setAll(false);
    passwordChangeDto.setNewPassword(new GuardedString("4321"));
    // change password for system
    provisioningService.changePassword(identity, passwordChangeDto);
    // bough password are right
    LoginDto loginDto1 = new LoginDto();
    loginDto1.setUsername(USERNAME);
    loginDto1.setPassword(new GuardedString("1234"));
    loginDto1 = authenticationManager.authenticate(loginDto1);
    LoginDto loginDto2 = new LoginDto();
    loginDto2.setUsername(USERNAME);
    loginDto2.setPassword(new GuardedString("4321"));
    loginDto2 = authenticationManager.authenticate(loginDto2);
    assertNotNull(loginDto2);
    assertNotNull(loginDto2.getAuthentication());
    assertEquals("acc", loginDto2.getAuthenticationModule());
    assertNotNull(loginDto1);
    assertNotNull(loginDto1.getAuthentication());
    assertEquals("acc", loginDto1.getAuthenticationModule());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 47 with AccIdentityAccountFilter

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

the class DefaultAccAuthenticatorTest method A_loginAgainstSystem.

@Test
public void A_loginAgainstSystem() {
    initData();
    IdmIdentityDto identity = identityService.getByUsername(USERNAME);
    IdmRoleDto role = roleService.getByCode(ROLE_NAME);
    IdmIdentityRoleDto irdto = new IdmIdentityRoleDto();
    irdto.setIdentityContract(identityContractService.findAllByIdentity(identity.getId()).get(0).getId());
    irdto.setRole(role.getId());
    // This evokes IdentityRole SAVE event. On this event will be start
    // account management and provisioning
    irdto = identityRoleService.save(irdto);
    // 
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    List<AccIdentityAccountDto> accounts = identityAccountService.find(filter, null).getContent();
    assertEquals(1, accounts.size());
    List<String> accs = new ArrayList<>();
    accs.add(accounts.get(0).getId().toString());
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setAccounts(accs);
    passwordChangeDto.setAll(true);
    passwordChangeDto.setNewPassword(new GuardedString("test"));
    // change password for system
    provisioningService.changePassword(identity, passwordChangeDto);
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(USERNAME);
    loginDto.setPassword(new GuardedString("test"));
    loginDto = authenticationManager.authenticate(loginDto);
    // 
    assertNotNull(loginDto);
    assertNotNull(loginDto.getAuthentication());
    assertEquals("acc", loginDto.getAuthenticationModule());
}
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) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 48 with AccIdentityAccountFilter

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

the class AccountProtectionSystemTest method protectedIdentityAccountDeleteTest.

/**
 * When is account in protection mode, then cannot be identity account deleted.
 */
@Test(expected = ResultCodeException.class)
public void protectedIdentityAccountDeleteTest() {
    IdmIdentityDto identity = helper.createIdentity();
    SysSystemDto system = initSystem();
    IdmRoleDto roleOne = roleService.getByCode(ROLE_ONE);
    // Set system to protected mode
    SysSystemMappingDto mapping = systemMappingService.findBySystem(system, SystemOperationType.PROVISIONING, SystemEntityType.IDENTITY).get(0);
    mapping.setProtectionEnabled(Boolean.TRUE);
    mapping.setProtectionInterval(null);
    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);
    // Remove role from identity
    identityRoleService.deleteById(identityRole.getId());
    AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
    identityAccountFilter.setAccountId(account.getId());
    List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(identityAccountFilter, null).getContent();
    Assert.assertEquals(1, identityAccounts.size());
    // Remove identity account again. Now must end on the exception (account is
    // already in protection)
    identityAccountService.delete(identityAccounts.get(0));
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) 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) 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 49 with AccIdentityAccountFilter

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

the class DefaultSynchronizationServiceTest method doStartSyncB_Linked_doUnLinked.

@Test
public void doStartSyncB_Linked_doUnLinked() {
    SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
    configFilter.setName(SYNC_CONFIG_NAME);
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
    Assert.assertEquals(1, syncConfigs.size());
    AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
    Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
    // Set sync config
    syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UNLINK);
    syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
    syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
    syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
    syncConfigCustom.setReconciliation(true);
    syncConfigService.save(syncConfigCustom);
    // Check state before sync
    AccIdentityAccountFilter identityAccountFilterOne = new AccIdentityAccountFilter();
    identityAccountFilterOne.setIdentityId(identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getId());
    Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements());
    AccIdentityAccountFilter identityAccountFilterTwo = new AccIdentityAccountFilter();
    identityAccountFilterTwo.setIdentityId(identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getId());
    Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements());
    // Start synchronization
    synchornizationService.setSynchronizationConfigId(syncConfigCustom.getId());
    synchornizationService.process();
    // 
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
    List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    SysSyncLogDto log = logs.get(0);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
    Assert.assertEquals(1, actions.size());
    SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
        return SynchronizationActionType.UNLINK == action.getSyncAction();
    }).findFirst().get();
    SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
    itemLogFilter.setSyncActionLogId(actionLog.getId());
    List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
    Assert.assertEquals(2, items.size());
    // Check state after sync
    Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements());
    Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements());
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) SysSyncItemLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 50 with AccIdentityAccountFilter

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

the class DefaultSynchronizationServiceTest method doStartSyncC_Unlinked_doLinkAndUpdateAccount.

@Test
public void doStartSyncC_Unlinked_doLinkAndUpdateAccount() {
    // We have to do unlink first
    this.doStartSyncB_Linked_doUnLinked();
    SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
    configFilter.setName(SYNC_CONFIG_NAME);
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
    Assert.assertEquals(1, syncConfigs.size());
    AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
    Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
    // Set sync config
    syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
    syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ACCOUNT);
    syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
    syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
    syncConfigCustom.setReconciliation(true);
    syncConfigService.save(syncConfigCustom);
    IdmIdentityDto identityOne = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE);
    IdmIdentityDto identityTwo = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO);
    identityOne.setFirstName(IDENTITY_USERNAME_ONE);
    identityTwo.setLastName(IDENTITY_USERNAME_TWO);
    identityService.save(identityOne);
    identityService.save(identityTwo);
    // Change account on resource
    getBean().changeResourceData();
    // Check state before sync
    AccIdentityAccountFilter identityAccountFilterOne = new AccIdentityAccountFilter();
    identityAccountFilterOne.setIdentityId(identityOne.getId());
    Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements());
    AccIdentityAccountFilter identityAccountFilterTwo = new AccIdentityAccountFilter();
    identityAccountFilterTwo.setIdentityId(identityTwo.getId());
    Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements());
    Assert.assertEquals(IDENTITY_USERNAME_ONE, identityOne.getFirstName());
    Assert.assertEquals(IDENTITY_USERNAME_TWO, identityTwo.getLastName());
    Assert.assertNotEquals(IDENTITY_USERNAME_ONE, entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_ONE).getFirstname());
    Assert.assertNotEquals(IDENTITY_USERNAME_TWO, entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_TWO).getLastname());
    // Start synchronization
    synchornizationService.setSynchronizationConfigId(syncConfigCustom.getId());
    synchornizationService.process();
    // 
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
    List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    SysSyncLogDto log = logs.get(0);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
    Assert.assertEquals(1, actions.size());
    SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
        return SynchronizationActionType.LINK_AND_UPDATE_ACCOUNT == action.getSyncAction();
    }).findFirst().get();
    SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
    itemLogFilter.setSyncActionLogId(actionLog.getId());
    List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
    Assert.assertEquals(2, items.size());
    // Check state after sync
    Assert.assertEquals(IDENTITY_USERNAME_ONE, entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_ONE).getFirstname());
    Assert.assertEquals(IDENTITY_USERNAME_TWO, entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_TWO).getLastname());
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) SysSyncItemLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)59 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)48 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)47 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)43 Test (org.junit.Test)43 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)25 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)22 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)13 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)13 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)12 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)11 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)10 ArrayList (java.util.ArrayList)10 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)9 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)8 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)7 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)6 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)6 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)5 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)5