DefaultAccUniformPasswordService extends AbstractEventableDtoService<AccUniformPasswordDto, AccUniformPassword, AccUniformPasswordFilter> implements AccUniformPasswordService { @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(); Map<AccUniformPasswordDto, List<AccAccountDto>> accountsForUniformPassword = Maps.newHashMap(); AccAccountFilter accountFilter = new AccAccountFilter(); accountFilter.setOwnership(Boolean.TRUE); accountFilter.setSupportChangePassword(Boolean.TRUE); accountFilter.setIdentityId(identity.getId()); accountFilter.setInProtection(Boolean.FALSE); List<AccAccountDto> accounts = accountService.find(accountFilter, null, permissions).getContent(); for (AccAccountDto account : accounts) { List<AccUniformPasswordSystemDto> uniformBySystem = uniformPasswordSystems.stream().filter(pfs -> { return pfs.getSystem().equals(account.getSystem()); }).collect(Collectors.toList()); if (CollectionUtils.isEmpty(uniformBySystem)) { 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)); } } } if (!accountsForUniformPassword.isEmpty()) { for (Entry<AccUniformPasswordDto, List<AccAccountDto>> entry : accountsForUniformPassword.entrySet()) { AccUniformPasswordDto uniformPasswordDto = entry.getKey(); AccPasswordChangeOptionDto optionDto = new AccPasswordChangeOptionDto(uniformPasswordDto, entry.getValue()); optionDto.setNiceLabel(getNiceLabelForOption(uniformPasswordDto)); optionDto.setChangeInIdm(uniformPasswordDto.isChangeInIdm()); result.add(optionDto); } } return result; } @Autowired  DefaultAccUniformPasswordService(AccUniformPasswordRepository repository,
			EntityEventManager entityEventManager); @Override AuthorizableType getAuthorizableType(); @Override AccUniformPasswordDto getByCode(String code); @Override List<AccPasswordChangeOptionDto> findOptionsForPasswordChange(IdmIdentityDto identity, BasePermission ...permissions);  }
@Test public void testFindOptionsForIdentityOneWithoutUniform() { SysSystemDto system = createSystem(false); IdmIdentityDto identity = createIdentity(system); List<AccPasswordChangeOptionDto> options = uniformPasswordService.findOptionsForPasswordChange(identity); assertEquals(1, options.size()); AccPasswordChangeOptionDto option = options.get(0); assertEquals(1, option.getAccounts().size()); String string = option.getAccounts().get(0); AccAccountDto account = getAccount(identity, system); assertEquals(account.getId().toString(), string); }
@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(); } }); }
@Test public void testFindOptionsForIdentityMoreWithUniform() { 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); List<AccPasswordChangeOptionDto> options = uniformPasswordService.findOptionsForPasswordChange(identity); assertEquals(1, options.size()); AccAccountDto account = getAccount(identity, system); AccAccountDto accountTwo = getAccount(identity, systemTwo); AccAccountDto accountThree = getAccount(identity, systemThree); AccPasswordChangeOptionDto option = options.get(0); assertFalse(option.isChangeInIdm()); assertEquals(3, option.getAccounts().size()); option.getAccounts().forEach(acc -> { UUID uuid = UUID.fromString(acc); if (!(uuid.equals(account.getId()) || uuid.equals(accountTwo.getId()) || uuid.equals(accountThree.getId()))) { fail(); } }); }
@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()); }
@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()); }