use of eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto in project CzechIdMng by bcvsolutions.
the class DefaultAccUniformPasswordServiceTest method testFindOptionsForIdentityMoreWithoutUniform.
@Test
public void testFindOptionsForIdentityMoreWithoutUniform() {
SysSystemDto system = createSystem(false);
SysSystemDto systemTwo = createSystem(false);
SysSystemDto systemThree = createSystem(false);
IdmIdentityDto identity = createIdentity(system);
assignSystem(identity, systemTwo);
assignSystem(identity, systemThree);
List<AccPasswordChangeOptionDto> options = uniformPasswordService.findOptionsForPasswordChange(identity);
assertEquals(3, options.size());
AccAccountDto account = getAccount(identity, system);
AccAccountDto accountTwo = getAccount(identity, systemTwo);
AccAccountDto accountThree = getAccount(identity, systemThree);
options.forEach(option -> {
assertEquals(1, option.getAccounts().size());
UUID uuid = UUID.fromString(option.getAccounts().get(0));
assertFalse(option.isChangeInIdm());
if (!(uuid.equals(account.getId()) || uuid.equals(accountTwo.getId()) || uuid.equals(accountThree.getId()))) {
fail();
}
});
}
use of eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto in project CzechIdMng by bcvsolutions.
the class DefaultAccUniformPasswordServiceTest method testFindOptionsSystemSameUniformDefinition.
@Test
public void testFindOptionsSystemSameUniformDefinition() {
SysSystemDto system = createSystem(false);
SysSystemDto systemTwo = createSystem(false);
SysSystemDto systemThree = createSystem(false);
IdmIdentityDto identity = createIdentity(system);
assignSystem(identity, systemTwo);
assignSystem(identity, systemThree);
assignSystem(createUniformDefinition(true), system, systemTwo, systemThree);
assignSystem(createUniformDefinition(true), systemTwo);
assignSystem(createUniformDefinition(true), system);
List<AccPasswordChangeOptionDto> options = uniformPasswordService.findOptionsForPasswordChange(identity);
assertEquals(3, options.size());
}
use of eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto in project CzechIdMng by bcvsolutions.
the class DefaultAccUniformPasswordServiceTest method testFindOptionsSameSystemInTwoDefinition.
@Test
public void testFindOptionsSameSystemInTwoDefinition() {
SysSystemDto system = createSystem(false);
SysSystemDto systemTwo = createSystem(false);
SysSystemDto systemThree = createSystem(false);
IdmIdentityDto identity = createIdentity(system);
assignSystem(identity, systemTwo);
assignSystem(identity, systemThree);
assignSystem(createUniformDefinition(false), system, systemTwo, systemThree);
assignSystem(createUniformDefinition(true), systemTwo);
List<AccPasswordChangeOptionDto> options = uniformPasswordService.findOptionsForPasswordChange(identity);
assertEquals(2, options.size());
}
use of eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto in project CzechIdMng by bcvsolutions.
the class IdentityUniformPasswordProcessor method process.
@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
PasswordChangeDto passwordChangeDto = (PasswordChangeDto) event.getProperties().get(IdentityPasswordProcessor.PROPERTY_PASSWORD_CHANGE_DTO);
UUID excludedSystem = (UUID) event.getProperties().get(PasswordFilterManager.EXCLUDED_SYSTEM);
IdmIdentityDto identity = event.getContent();
// If password change contains all get all accounts - for these account must be setup echo!
if (passwordChangeDto.isAll()) {
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setSupportChangePassword(Boolean.TRUE);
accountFilter.setIdentityId(identity.getId());
List<AccAccountDto> accounts = accountService.find(accountFilter, null).getContent();
passwordChangeDto.setAccounts(//
accounts.stream().map(//
AccAccountDto::getId).map(//
UUID::toString).collect(//
Collectors.toList()));
}
List<String> accounts = passwordChangeDto.getAccounts();
if (!CollectionUtils.isEmpty(accounts)) {
List<AccPasswordChangeOptionDto> findOptionsForPasswordChange = uniformPasswordService.findOptionsForPasswordChange(identity);
Set<String> finalAccounts = Sets.newHashSet();
for (String account : accounts) {
findOptionsForPasswordChange.forEach(option -> {
List<String> accountOptions = option.getAccounts();
if (accountOptions.contains(account)) {
finalAccounts.addAll(accountOptions);
// At least one option with change in IdM and password must be changed even trought IdM
if (option.isChangeInIdm()) {
passwordChangeDto.setIdm(true);
}
}
});
}
if (excludedSystem != null) {
finalAccounts.removeIf(account -> {
AccAccountFilter filter = new AccAccountFilter();
filter.setId(UUID.fromString(account));
filter.setSystemId(excludedSystem);
return accountService.count(filter) > 0;
});
}
passwordChangeDto.setAccounts(Lists.newArrayList(finalAccounts));
event.getProperties().put(IdentityPasswordProcessor.PROPERTY_PASSWORD_CHANGE_DTO, passwordChangeDto);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto 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;
}
Aggregations