Search in sources :

Example 6 with AccUniformPasswordSystemFilter

use of eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordSystemFilter 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;
}
Also used : AccUniformPassword(eu.bcvsolutions.idm.acc.entity.AccUniformPassword) AccUniformPasswordDto(eu.bcvsolutions.idm.acc.dto.AccUniformPasswordDto) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) AccUniformPasswordRepository(eu.bcvsolutions.idm.acc.repository.AccUniformPasswordRepository) AccUniformPasswordService(eu.bcvsolutions.idm.acc.service.api.AccUniformPasswordService) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AccUniformPassword_(eu.bcvsolutions.idm.acc.entity.AccUniformPassword_) StringUtils(org.apache.commons.lang3.StringUtils) AccUniformPasswordFilter(eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordFilter) MessageFormat(java.text.MessageFormat) Lists(com.google.common.collect.Lists) Predicate(javax.persistence.criteria.Predicate) CollectionUtils(org.apache.commons.collections.CollectionUtils) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) Service(org.springframework.stereotype.Service) Map(java.util.Map) AccUniformPasswordSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordSystemFilter) AccUniformPasswordSystem_(eu.bcvsolutions.idm.acc.entity.AccUniformPasswordSystem_) BasePermission(eu.bcvsolutions.idm.core.security.api.domain.BasePermission) CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) AccGroupPermission(eu.bcvsolutions.idm.acc.domain.AccGroupPermission) Root(javax.persistence.criteria.Root) CriteriaQuery(javax.persistence.criteria.CriteriaQuery) AccUniformPasswordSystemDto(eu.bcvsolutions.idm.acc.dto.AccUniformPasswordSystemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractEventableDtoService(eu.bcvsolutions.idm.core.api.service.AbstractEventableDtoService) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) AccUniformPasswordSystemService(eu.bcvsolutions.idm.acc.service.api.AccUniformPasswordSystemService) List(java.util.List) AccAccount_(eu.bcvsolutions.idm.acc.entity.AccAccount_) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) Entry(java.util.Map.Entry) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) AccPasswordChangeOptionDto(eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) AuthorizableType(eu.bcvsolutions.idm.core.security.api.dto.AuthorizableType) AccUniformPasswordSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordSystemFilter) AccUniformPasswordDto(eu.bcvsolutions.idm.acc.dto.AccUniformPasswordDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccPasswordChangeOptionDto(eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) AccUniformPasswordSystemDto(eu.bcvsolutions.idm.acc.dto.AccUniformPasswordSystemDto) List(java.util.List)

Example 7 with AccUniformPasswordSystemFilter

use of eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordSystemFilter in project CzechIdMng by bcvsolutions.

the class DefaultAccUniformPasswordServiceTest method testFilterByDisabledWithTrue.

@Test
public void testFilterByDisabledWithTrue() {
    SysSystemDto system = createSystem(false);
    SysSystemDto systemTwo = createSystem(false);
    SysSystemDto systemThree = createSystem(false);
    IdmIdentityDto identity = createIdentity(system);
    assignSystem(identity, systemTwo);
    assignSystem(identity, systemThree);
    AccUniformPasswordDto createUniformDefinition = createUniformDefinition(true);
    createUniformDefinition.setDisabled(true);
    createUniformDefinition = uniformPasswordService.save(createUniformDefinition);
    assignSystem(createUniformDefinition(true), system, systemTwo, systemThree);
    assignSystem(createUniformDefinition, systemTwo);
    assignSystem(createUniformDefinition(true), system);
    AccUniformPasswordSystemFilter filter = new AccUniformPasswordSystemFilter();
    filter.setSystemId(systemTwo.getId());
    filter.setUniformPasswordDisabled(true);
    List<AccUniformPasswordSystemDto> content = uniformPasswordSystemService.find(filter, null).getContent();
    assertEquals(1, content.size());
    AccUniformPasswordSystemDto accUniformPasswordSystemDto = content.get(0);
    assertEquals(createUniformDefinition.getId(), accUniformPasswordSystemDto.getUniformPassword());
}
Also used : AccUniformPasswordSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordSystemFilter) AccUniformPasswordDto(eu.bcvsolutions.idm.acc.dto.AccUniformPasswordDto) AccUniformPasswordSystemDto(eu.bcvsolutions.idm.acc.dto.AccUniformPasswordSystemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractPasswordFilterIntegrationTest(eu.bcvsolutions.idm.acc.AbstractPasswordFilterIntegrationTest)

Aggregations

AccUniformPasswordSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordSystemFilter)7 AccUniformPasswordDto (eu.bcvsolutions.idm.acc.dto.AccUniformPasswordDto)6 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)6 AccUniformPasswordSystemDto (eu.bcvsolutions.idm.acc.dto.AccUniformPasswordSystemDto)5 AbstractPasswordFilterIntegrationTest (eu.bcvsolutions.idm.acc.AbstractPasswordFilterIntegrationTest)4 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 Test (org.junit.Test)3 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 AccGroupPermission (eu.bcvsolutions.idm.acc.domain.AccGroupPermission)1 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)1 AccPasswordChangeOptionDto (eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto)1 AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)1 AccUniformPasswordFilter (eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordFilter)1 SysProvisioningOperationFilter (eu.bcvsolutions.idm.acc.dto.filter.SysProvisioningOperationFilter)1 SysSchemaObjectClassFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSchemaObjectClassFilter)1 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)1 SysSystemEntityFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter)1 SysSystemGroupSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemGroupSystemFilter)1