use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto 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.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAuthenticatorTest method logInAgainstSystem.
private void logInAgainstSystem(IdmIdentityDto identity, IdmRoleDto role, String username) {
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.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class IdentityAccountByRoleEvaluatorIntegrationTest method testCannotReadIdentityAccount.
@Test(expected = ForbiddenEntityException.class)
public void testCannotReadIdentityAccount() {
IdmIdentityDto 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);
AccIdentityAccountDto accountIdentityOne = new AccIdentityAccountDto();
accountIdentityOne.setIdentity(identity.getId());
accountIdentityOne.setOwnership(true);
accountIdentityOne.setAccount(accountOne.getId());
accountIdentityOne = identityAccountService.save(accountIdentityOne);
// check
try {
getHelper().login(identity);
identityAccountService.get(accountIdentityOne.getId(), IdmBasePermission.READ);
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class IdentityAccountManagementTest method overloadedAttributeRemoveAllRoles.
@Transactional
@Test
public void overloadedAttributeRemoveAllRoles() {
IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
Assert.assertNotNull("Account for this identity have to be found!", helper.findResource("x" + IDENTITY_USERNAME));
AccIdentityAccountFilter iaccFilter = new AccIdentityAccountFilter();
iaccFilter.setSystemId(systemService.getByCode(SYSTEM_NAME).getId());
iaccFilter.setIdentityId(identity.getId());
// Now we have to identity roles (role_overloading_first_name and
// role_overloading_last_name and role_overloading_y_account) and
// identity accounts
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(iaccFilter, null).getContent();
Assert.assertEquals("Idenitity accounts have to exists (three items - override by password from version 9.3.0 is not possiblem ) after account management was started!", 3, identityAccounts.size());
IdmIdentityRoleFilter irfilter = new IdmIdentityRoleFilter();
irfilter.setIdentityId(identity.getId());
identityRoleService.find(irfilter, null).getContent().forEach(identityRole -> {
identityRoleService.delete(identityRole);
});
Assert.assertEquals("Idenitity accounts have to not exist after accounts deleted!", 0, identityAccountService.find(iaccFilter, null).getContent().size());
}
use of eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto in project CzechIdMng by bcvsolutions.
the class PerformanceAccountManagementTest method testDeletePerformance100WithoutRequest.
@Ignore
@Test
@Transactional
public void testDeletePerformance100WithoutRequest() {
SysSystemDto system = initIdentityData();
Assert.assertNotNull(system);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
Assert.assertNotNull(mapping);
mapping = systemMappingService.save(mapping);
IdmIdentityDto identity = helper.createIdentity();
AccIdentityAccountFilter roleAccountFilter = new AccIdentityAccountFilter();
roleAccountFilter.setEntityId(identity.getId());
roleAccountFilter.setOwnership(Boolean.TRUE);
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(roleAccountFilter, null).getContent();
List<IdmRoleDto> roles = this.createRolesWithSystem(system, 100);
IdmIdentityContractDto primeContract = identityContractService.getPrimeContract(identity.getId());
Date startAcm = new Date();
IdmRoleRequestDto request = helper.createRoleRequest(primeContract, roles.toArray(new IdmRoleDto[0]));
helper.executeRequest(request, false, true);
Date endAcm = new Date();
System.out.println("testDeletePerformance100WithoutRequest - ACM duration: " + (endAcm.getTime() - startAcm.getTime()));
identityAccounts = identityAccountService.find(roleAccountFilter, null).getContent();
Assert.assertEquals(100, identityAccounts.size());
// Delete
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setIdentityContractId(primeContract.getId());
List<IdmIdentityRoleDto> identityRoles = identityRoleService.find(identityRoleFilter, null).getContent();
Date startAcmDelete = new Date();
identityRoles.forEach(identityRole -> {
identityRoleService.delete(identityRole);
if (getHibernateSession().isOpen()) {
getHibernateSession().flush();
getHibernateSession().clear();
}
});
Date endAcmDelete = new Date();
System.out.println("testDeletePerformance100WithoutRequest - Delete duration: " + (endAcmDelete.getTime() - startAcmDelete.getTime()));
}
Aggregations