Search in sources :

Example 41 with AccAccountFilter

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;
}
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 42 with AccAccountFilter

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

Example 43 with AccAccountFilter

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());
}
Also used : AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 44 with AccAccountFilter

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());
}
Also used : AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 45 with AccAccountFilter

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;
}
Also used : DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) SysRoleSystem_(eu.bcvsolutions.idm.acc.entity.SysRoleSystem_) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmIdentityRoleRepository(eu.bcvsolutions.idm.core.model.repository.IdmIdentityRoleRepository) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) AccAccountManagementService(eu.bcvsolutions.idm.acc.service.api.AccAccountManagementService) SysRoleSystemFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemFilter) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) Service(org.springframework.stereotype.Service) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) ImmutableMap(com.google.common.collect.ImmutableMap) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) List(java.util.List) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SysRoleSystemAttributeFilter(eu.bcvsolutions.idm.acc.dto.filter.SysRoleSystemAttributeFilter) CollectionUtils(org.springframework.util.CollectionUtils) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) Optional(java.util.Optional) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) Assert(org.springframework.util.Assert) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) UUID(java.util.UUID) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Aggregations

AccAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter)45 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)33 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)25 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)21 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)18 Test (org.junit.Test)18 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)12 UUID (java.util.UUID)11 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 SysRoleSystemDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto)6 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)6 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)6 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)6 SysRoleSystemAttributeDto (eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto)5 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)5 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)4 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)4 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)4 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)4