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