Search in sources :

Example 36 with PageRequest

use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.

the class DefaultIdmIdentityService method findAllManagers.

/**
 * Method finds all identity's managers by identity contract (guarantee or by assigned tree structure).
 *
 * @param forIdentity
 * @param byTreeType If optional tree type is given, then only managers defined with this type is returned
 * @return
 */
@Override
@Transactional(readOnly = true)
public List<IdmIdentityDto> findAllManagers(UUID forIdentity, UUID byTreeType) {
    Assert.notNull(forIdentity, "Identity id is required.");
    // 
    IdmIdentityFilter filter = new IdmIdentityFilter();
    filter.setManagersFor(forIdentity);
    filter.setManagersByTreeType(byTreeType);
    // 
    List<IdmIdentityDto> results = new ArrayList<>();
    Page<IdmIdentityDto> managers = find(filter, new PageRequest(0, 50, Sort.Direction.ASC, IdmIdentity_.username.getName()));
    results.addAll(managers.getContent());
    while (managers.hasNext()) {
        managers = find(filter, managers.nextPageable());
        results.addAll(managers.getContent());
    }
    // 
    if (!results.isEmpty()) {
        return results;
    }
    // return all valid identities with admin role
    return this.findValidByRole(roleConfiguration.getAdminRoleId());
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) ArrayList(java.util.ArrayList) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with PageRequest

use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.

the class DefaultIdmRoleCatalogueService method deleteInternal.

@Override
@Transactional
public void deleteInternal(IdmRoleCatalogueDto roleCatalogue) {
    Page<IdmRoleCatalogue> nodes = repository.findChildren(roleCatalogue.getId(), new PageRequest(0, 1));
    if (nodes.getTotalElements() != 0) {
        throw new ResultCodeException(CoreResultCode.ROLE_CATALOGUE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("roleCatalogue", roleCatalogue.getCode()));
    }
    // remove row from intersection table
    roleCatalogueRoleRepository.deleteAllByRoleCatalogue_Id(roleCatalogue.getId());
    // 
    forestContentService.deleteIndex(roleCatalogue.getId());
    super.deleteInternal(roleCatalogue);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRoleCatalogue(eu.bcvsolutions.idm.core.model.entity.IdmRoleCatalogue) Transactional(org.springframework.transaction.annotation.Transactional)

Example 38 with PageRequest

use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.

the class DefaultIdmTreeNodeService method deleteInternal.

/**
 * Publish {@link TreeNodeEvent} only.
 *
 * @see {@link TreeNodeDeleteProcessor}
 */
@Override
@Transactional
public void deleteInternal(IdmTreeNodeDto treeNode) {
    Assert.notNull(treeNode);
    Assert.notNull(treeNode.getTreeType());
    LOG.debug("Deleting tree node [{}] - [{}]", treeNode.getTreeType(), treeNode.getCode());
    // 
    // if index rebuild is in progress, then throw exception
    checkTreeType(treeNode.getTreeType());
    // 
    Page<IdmTreeNode> nodes = repository.findChildren(null, treeNode.getId(), new PageRequest(0, 1));
    if (nodes.getTotalElements() > 0) {
        throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CHILDREN, ImmutableMap.of("treeNode", treeNode.getName()));
    }
    if (this.identityContractRepository.countByWorkPosition_Id(treeNode.getId()) > 0) {
        throw new TreeNodeException(CoreResultCode.TREE_NODE_DELETE_FAILED_HAS_CONTRACTS, ImmutableMap.of("treeNode", treeNode.getName()));
    }
    // 
    forestContentService.deleteIndex(treeNode.getId());
    super.deleteInternal(treeNode);
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) TreeNodeException(eu.bcvsolutions.idm.core.exception.TreeNodeException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 39 with PageRequest

use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.

the class IdentityAccountManagementTest method overloadedAttributeChangePassword.

@Test
public void overloadedAttributeChangePassword() {
    IdmIdentityDto identity = identityService.getByUsername(IDENTITY_USERNAME);
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    filter.setSystemId(systemService.getByCode(SYSTEM_NAME).getId());
    List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(filter, new PageRequest(0, 1, new Sort(Sort.Direction.ASC, AccIdentityAccount_.created.getName()))).getContent();
    TestResource resourceAccount = helper.findResource("x" + IDENTITY_USERNAME);
    // Create new password two
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setAccounts(ImmutableList.of(identityAccounts.get(0).getAccount().toString()));
    passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_TWO));
    passwordChange.setIdm(true);
    // Do change of password for selected accounts
    identityService.passwordChange(identity, passwordChange);
    // Check correct password two
    resourceAccount = helper.findResource("x" + IDENTITY_USERNAME);
    Assert.assertEquals("Check same password on target system", IDENTITY_PASSWORD_TWO, resourceAccount.getPassword());
    // Add overloaded password attribute
    IdmRoleDto rolePassword = roleService.getByCode(ROLE_OVERLOADING_PASSWORD);
    IdmIdentityRoleDto irdto = new IdmIdentityRoleDto();
    irdto.setIdentityContract(identityContractService.findAllByIdentity(identity.getId()).get(0).getId());
    irdto.setRole(rolePassword.getId());
    // This evokes IdentityRole SAVE event. On this event will be start
    // account management and provisioning
    identityRoleService.save(irdto);
    // Do change of password for selected accounts
    passwordChange.setNewPassword(new GuardedString(IDENTITY_PASSWORD_THREE));
    identityService.passwordChange(identity, passwordChange);
    // Check correct overloaded password two
    resourceAccount = helper.findResource("x" + IDENTITY_USERNAME);
    Assert.assertEquals("Check overloaded password (added x) on target system", "x" + IDENTITY_PASSWORD_THREE, resourceAccount.getPassword());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PageRequest(org.springframework.data.domain.PageRequest) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) Sort(org.springframework.data.domain.Sort) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 40 with PageRequest

use of org.springframework.data.domain.PageRequest in project CzechIdMng by bcvsolutions.

the class AccountProtectionExpirationTaskExecutor method process.

@Override
public Boolean process() {
    this.counter = 0L;
    boolean canContinue = true;
    while (canContinue) {
        Page<AccAccountDto> expiredAccounts = service.findExpired(expiration, new PageRequest(0, 100));
        // init count
        if (count == null) {
            count = expiredAccounts.getTotalElements();
        }
        // 
        for (AccAccountDto account : expiredAccounts) {
            service.delete(account);
            counter++;
            canContinue = updateState();
            if (!canContinue) {
                break;
            }
        }
        if (!expiredAccounts.hasNext()) {
            break;
        }
    }
    LOG.info("End: Remove accounts with expired protection for expiration less than [{}]", expiration);
    return Boolean.TRUE;
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto)

Aggregations

PageRequest (org.springframework.data.domain.PageRequest)106 Sort (org.springframework.data.domain.Sort)29 Pageable (org.springframework.data.domain.Pageable)25 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 Transactional (org.springframework.transaction.annotation.Transactional)9 UUID (java.util.UUID)8 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)7 ApiOperation (io.swagger.annotations.ApiOperation)7 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)6 IdmTreeNode (eu.bcvsolutions.idm.core.model.entity.IdmTreeNode)6 List (java.util.List)6 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)5 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)5 IdmIdentityFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter)5 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)5 PageImpl (org.springframework.data.domain.PageImpl)5