use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultAccUniformPasswordService method findOptionsForPasswordChange.
@Override
public List<AccPasswordChangeOptionDto> findOptionsForPasswordChange(IdmIdentityDto identity, BasePermission... permissions) {
List<AccPasswordChangeOptionDto> result = Lists.newArrayList();
AccUniformPasswordSystemFilter filter = new AccUniformPasswordSystemFilter();
filter.setIdentityId(identity.getId());
filter.setUniformPasswordDisabled(Boolean.FALSE);
List<AccUniformPasswordSystemDto> uniformPasswordSystems = this.uniformPasswordSystemService.find(filter, null).getContent();
// Group uniform password system by uniform password definition
Map<AccUniformPasswordDto, List<AccAccountDto>> accountsForUniformPassword = Maps.newHashMap();
// Same behavior as previous versions
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setOwnership(Boolean.TRUE);
accountFilter.setSupportChangePassword(Boolean.TRUE);
accountFilter.setIdentityId(identity.getId());
accountFilter.setInProtection(Boolean.FALSE);
// Include given permissions
List<AccAccountDto> accounts = accountService.find(accountFilter, null, permissions).getContent();
for (AccAccountDto account : accounts) {
// One system can be place more than one in uniform password systems
List<AccUniformPasswordSystemDto> uniformBySystem = uniformPasswordSystems.stream().filter(pfs -> {
return pfs.getSystem().equals(account.getSystem());
}).collect(Collectors.toList());
if (CollectionUtils.isEmpty(uniformBySystem)) {
// Simple account as option
AccPasswordChangeOptionDto optionDto = new AccPasswordChangeOptionDto(account);
optionDto.setNiceLabel(getNiceLabelForOption(account));
result.add(optionDto);
continue;
}
for (AccUniformPasswordSystemDto uniformPasswordSystemDto : uniformBySystem) {
AccUniformPasswordDto definition = DtoUtils.getEmbedded(uniformPasswordSystemDto, AccUniformPasswordSystem_.uniformPassword, AccUniformPasswordDto.class, null);
if (accountsForUniformPassword.containsKey(definition)) {
accountsForUniformPassword.get(definition).add(account);
} else {
accountsForUniformPassword.put(definition, Lists.newArrayList(account));
}
}
}
// Check if exists account for uniform password and process options for them
if (!accountsForUniformPassword.isEmpty()) {
for (Entry<AccUniformPasswordDto, List<AccAccountDto>> entry : accountsForUniformPassword.entrySet()) {
// There is also needed
AccUniformPasswordDto uniformPasswordDto = entry.getKey();
AccPasswordChangeOptionDto optionDto = new AccPasswordChangeOptionDto(uniformPasswordDto, entry.getValue());
optionDto.setNiceLabel(getNiceLabelForOption(uniformPasswordDto));
optionDto.setChangeInIdm(uniformPasswordDto.isChangeInIdm());
result.add(optionDto);
}
}
return result;
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultPasswordFilterManager method getAccountForSystemWithPasswordFilter.
/**
* Return account for given system and identity. Only one may exists.
*
* @param system
* @param identity
* @return
*/
private List<AccAccountDto> getAccountForSystemWithPasswordFilter(SysSystemDto system, IdmIdentityDto identity) {
AccAccountFilter filter = new AccAccountFilter();
filter.setSystemId(system.getId());
filter.setIdentityId(identity.getId());
filter.setSupportPasswordFilter(Boolean.TRUE);
return accountService.find(filter, null).getContent();
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountServiceFilterTest method testSystemId.
@Test
public void testSystemId() {
IdmIdentityDto identity = helper.createIdentity("test-" + System.currentTimeMillis());
SysSystemDto system = helper.createTestResourceSystem(true);
AccAccountDto account = createAccount(system.getId(), identity.getId(), identity.getUsername(), AccountType.PERSONAL, false);
IdmIdentityDto identity2 = helper.createIdentity("test-" + System.currentTimeMillis());
SysSystemDto system2 = helper.createTestResourceSystem(true);
createAccount(system2.getId(), identity2.getId(), identity2.getUsername(), AccountType.PERSONAL, false);
AccAccountFilter testFilter = new AccAccountFilter();
testFilter.setSystemId(system.getId());
Page<AccAccountDto> pages = accAccountService.find(testFilter, null);
assertEquals(1, pages.getTotalElements());
assertEquals(account.getId(), pages.getContent().get(0).getId());
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountServiceFilterTest method testUid.
@Test
public void testUid() {
IdmIdentityDto identity = helper.createIdentity("test-" + System.currentTimeMillis());
SysSystemDto system = helper.createTestResourceSystem(true);
AccAccountDto account = createAccount(system.getId(), identity.getId(), identity.getUsername(), AccountType.PERSONAL, false);
IdmIdentityDto identity2 = helper.createIdentity("test-" + System.currentTimeMillis());
SysSystemDto system2 = helper.createTestResourceSystem(true);
createAccount(system2.getId(), identity2.getId(), identity2.getUsername(), AccountType.PERSONAL, false);
AccAccountFilter testFilter = new AccAccountFilter();
testFilter.setUid(account.getUid());
Page<AccAccountDto> pages = accAccountService.find(testFilter, null);
assertEquals(1, pages.getTotalElements());
assertEquals(account.getId(), pages.getContent().get(0).getId());
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountManagementService method createAccountByRoleSystem.
/**
* Create Account by given roleSystem
*
* @param identity
* @param roleSystem
* @param identityAccountsToCreate
* @return
*/
private UUID createAccountByRoleSystem(IdmIdentityDto identity, SysRoleSystemDto roleSystem, List<AccIdentityAccountDto> identityAccountsToCreate) {
String uid = generateUID(identity, roleSystem);
// We try find account for same uid on same system
// First we try search same account in list for create new accounts
Optional<AccIdentityAccountDto> sameAccountOptional = identityAccountsToCreate.stream().filter(ia -> {
AccAccountDto account = accountService.get(ia.getAccount());
return account.getUid().equals(uid) && roleSystem.getId().equals(ia.getRoleSystem());
}).findFirst();
if (sameAccountOptional.isPresent()) {
return sameAccountOptional.get().getAccount();
}
UUID accountId = null;
// If account is not in the list accounts to create, then we will search in
// database
// Account management - can be the account created? - execute the script on the
// system mapping
SysSystemDto system = DtoUtils.getEmbedded(roleSystem, SysRoleSystem_.system, SysSystemDto.class);
SysSystemMappingDto mapping = systemMappingService.findProvisioningMapping(system.getId(), SystemEntityType.IDENTITY);
if (mapping == null) {
return null;
}
if (!this.canBeAccountCreated(uid, identity, mapping, system)) {
LOG.info(MessageFormat.format("For entity [{0}] and entity type [{1}] cannot be created the account (on system [{2}])," + " because script \"Can be account created\" on the mapping returned \"false\"!", identity.getCode(), SystemEntityType.IDENTITY, system.getName()));
return null;
}
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setUid(uid);
accountFilter.setSystemId(roleSystem.getSystem());
List<AccAccountDto> sameAccounts = accountService.find(accountFilter, null).getContent();
if (CollectionUtils.isEmpty(sameAccounts)) {
// Create and persist new account
accountId = createAccount(uid, roleSystem);
} else {
// We use existed account
accountId = sameAccounts.get(0).getId();
}
return accountId;
}
Aggregations