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());
}
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());
}
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));
}
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);
}
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);
}
Aggregations