Search in sources :

Example 1 with AccPasswordChangeOptionDto

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();
        }
    });
}
Also used : AccPasswordChangeOptionDto(eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractPasswordFilterIntegrationTest(eu.bcvsolutions.idm.acc.AbstractPasswordFilterIntegrationTest)

Example 2 with AccPasswordChangeOptionDto

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());
}
Also used : AccPasswordChangeOptionDto(eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto) 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)

Example 3 with AccPasswordChangeOptionDto

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());
}
Also used : AccPasswordChangeOptionDto(eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto) 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)

Example 4 with AccPasswordChangeOptionDto

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);
}
Also used : AccPasswordChangeOptionDto(eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 5 with AccPasswordChangeOptionDto

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;
}
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)

Aggregations

AccPasswordChangeOptionDto (eu.bcvsolutions.idm.acc.dto.AccPasswordChangeOptionDto)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)6 AbstractPasswordFilterIntegrationTest (eu.bcvsolutions.idm.acc.AbstractPasswordFilterIntegrationTest)5 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)5 Test (org.junit.Test)5 UUID (java.util.UUID)3 AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)2 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 AccGroupPermission (eu.bcvsolutions.idm.acc.domain.AccGroupPermission)1 AccUniformPasswordDto (eu.bcvsolutions.idm.acc.dto.AccUniformPasswordDto)1 AccUniformPasswordSystemDto (eu.bcvsolutions.idm.acc.dto.AccUniformPasswordSystemDto)1 AccUniformPasswordFilter (eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordFilter)1 AccUniformPasswordSystemFilter (eu.bcvsolutions.idm.acc.dto.filter.AccUniformPasswordSystemFilter)1 AccAccount_ (eu.bcvsolutions.idm.acc.entity.AccAccount_)1 AccUniformPassword (eu.bcvsolutions.idm.acc.entity.AccUniformPassword)1 AccUniformPasswordSystem_ (eu.bcvsolutions.idm.acc.entity.AccUniformPasswordSystem_)1 AccUniformPassword_ (eu.bcvsolutions.idm.acc.entity.AccUniformPassword_)1 AccUniformPasswordRepository (eu.bcvsolutions.idm.acc.repository.AccUniformPasswordRepository)1