Search in sources :

Example 36 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class SyncopeLogic method searchAssignableGroups.

@PreAuthorize("isAuthenticated()")
public Pair<Integer, List<GroupTO>> searchAssignableGroups(final String realm, final String term, final int page, final int size) {
    AssignableCond assignableCond = new AssignableCond();
    assignableCond.setRealmFullPath(realm);
    SearchCond searchCond;
    if (StringUtils.isNotBlank(term)) {
        AnyCond termCond = new AnyCond(AttributeCond.Type.ILIKE);
        termCond.setSchema("name");
        String termSearchableValue = (term.startsWith("*") && !term.endsWith("*")) ? term + "%" : (!term.startsWith("*") && term.endsWith("*")) ? "%" + term : (term.startsWith("*") && term.endsWith("*") ? term : "%" + term + "%");
        termCond.setExpression(termSearchableValue);
        searchCond = SearchCond.getAndCond(SearchCond.getLeafCond(assignableCond), SearchCond.getLeafCond(termCond));
    } else {
        searchCond = SearchCond.getLeafCond(assignableCond);
    }
    int count = searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, AnyTypeKind.GROUP);
    OrderByClause orderByClause = new OrderByClause();
    orderByClause.setField("name");
    orderByClause.setDirection(OrderByClause.Direction.ASC);
    List<Group> matching = searchDAO.search(SyncopeConstants.FULL_ADMIN_REALMS, searchCond, page, size, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
    List<GroupTO> result = matching.stream().map(group -> groupDataBinder.getGroupTO(group, false)).collect(Collectors.toList());
    return Pair.of(count, result);
}
Also used : Arrays(java.util.Arrays) SecurityQuestionDAO(org.apache.syncope.core.persistence.api.dao.SecurityQuestionDAO) AopUtils(org.springframework.aop.support.AopUtils) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) AnyType(org.apache.syncope.core.persistence.api.entity.AnyType) Autowired(org.springframework.beans.factory.annotation.Autowired) Entity(org.apache.syncope.core.persistence.api.entity.Entity) GroupProvisioningManager(org.apache.syncope.core.provisioning.api.GroupProvisioningManager) PlatformInfo(org.apache.syncope.common.lib.info.PlatformInfo) StringUtils(org.apache.commons.lang3.StringUtils) RoleDAO(org.apache.syncope.core.persistence.api.dao.RoleDAO) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) InetAddress(java.net.InetAddress) AnyTypeKind(org.apache.syncope.common.lib.types.AnyTypeKind) AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) GroupDAO(org.apache.syncope.core.persistence.api.dao.GroupDAO) Pair(org.apache.commons.lang3.tuple.Pair) AnyObjectDAO(org.apache.syncope.core.persistence.api.dao.AnyObjectDAO) Map(java.util.Map) URI(java.net.URI) AuthContextUtils(org.apache.syncope.core.spring.security.AuthContextUtils) Method(java.lang.reflect.Method) PayloadApplicationEvent(org.springframework.context.PayloadApplicationEvent) RuntimeMXBean(java.lang.management.RuntimeMXBean) TypeExtension(org.apache.syncope.core.persistence.api.entity.group.TypeExtension) GroupWorkflowAdapter(org.apache.syncope.core.workflow.api.GroupWorkflowAdapter) UserDAO(org.apache.syncope.core.persistence.api.dao.UserDAO) NotificationDAO(org.apache.syncope.core.persistence.api.dao.NotificationDAO) EntitlementsHolder(org.apache.syncope.core.provisioning.api.EntitlementsHolder) Resource(javax.annotation.Resource) EventListener(org.springframework.context.event.EventListener) GroupTO(org.apache.syncope.common.lib.to.GroupTO) Collectors(java.util.stream.Collectors) AnyTypeDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeDAO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) SystemInfo(org.apache.syncope.common.lib.info.SystemInfo) List(java.util.List) AccountPolicy(org.apache.syncope.core.persistence.api.entity.policy.AccountPolicy) TypeExtensionTO(org.apache.syncope.common.lib.to.TypeExtensionTO) PolicyDAO(org.apache.syncope.core.persistence.api.dao.PolicyDAO) ConnIdBundleManager(org.apache.syncope.core.provisioning.api.ConnIdBundleManager) PropagationTaskExecutor(org.apache.syncope.core.provisioning.api.propagation.PropagationTaskExecutor) Group(org.apache.syncope.core.persistence.api.entity.group.Group) Optional(java.util.Optional) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) ConfDAO(org.apache.syncope.core.persistence.api.dao.ConfDAO) ExternalResourceDAO(org.apache.syncope.core.persistence.api.dao.ExternalResourceDAO) VirAttrCache(org.apache.syncope.core.provisioning.api.cache.VirAttrCache) AbstractBaseBean(org.apache.syncope.common.lib.AbstractBaseBean) NumbersInfo(org.apache.syncope.common.lib.info.NumbersInfo) AnySearchDAO(org.apache.syncope.core.persistence.api.dao.AnySearchDAO) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) PasswordGenerator(org.apache.syncope.core.spring.security.PasswordGenerator) GroupDataBinder(org.apache.syncope.core.provisioning.api.data.GroupDataBinder) UserWorkflowAdapter(org.apache.syncope.core.workflow.api.UserWorkflowAdapter) TaskDAO(org.apache.syncope.core.persistence.api.dao.TaskDAO) PasswordPolicy(org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy) ImplementationType(org.apache.syncope.common.lib.types.ImplementationType) ManagementFactory(java.lang.management.ManagementFactory) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) AnyObjectProvisioningManager(org.apache.syncope.core.provisioning.api.AnyObjectProvisioningManager) SyncopeConstants(org.apache.syncope.common.lib.SyncopeConstants) Iterator(java.util.Iterator) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) UnknownHostException(java.net.UnknownHostException) ImplementationLookup(org.apache.syncope.core.persistence.api.ImplementationLookup) Component(org.springframework.stereotype.Component) UserProvisioningManager(org.apache.syncope.core.provisioning.api.UserProvisioningManager) JavaImplInfo(org.apache.syncope.common.lib.info.JavaImplInfo) VirSchemaDAO(org.apache.syncope.core.persistence.api.dao.VirSchemaDAO) Collections(java.util.Collections) AnyTypeClassDAO(org.apache.syncope.core.persistence.api.dao.AnyTypeClassDAO) AnyObjectWorkflowAdapter(org.apache.syncope.core.workflow.api.AnyObjectWorkflowAdapter) TaskType(org.apache.syncope.common.lib.types.TaskType) Transactional(org.springframework.transaction.annotation.Transactional) AssignableCond(org.apache.syncope.core.persistence.api.dao.search.AssignableCond) Group(org.apache.syncope.core.persistence.api.entity.group.Group) OrderByClause(org.apache.syncope.core.persistence.api.dao.search.OrderByClause) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) GroupTO(org.apache.syncope.common.lib.to.GroupTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 37 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class RemediationLogic method remedy.

@PreAuthorize("hasRole('" + StandardEntitlement.REMEDIATION_REMEDY + "')")
public ProvisioningResult<?> remedy(final String key, final AnyTO anyTO, final boolean nullPriorityAsync) {
    Remediation remediation = remediationDAO.find(key);
    if (remediation == null) {
        LOG.error("Could not find remediation '" + key + "'");
        throw new NotFoundException(key);
    }
    ProvisioningResult<?> result;
    switch(remediation.getAnyType().getKind()) {
        case USER:
        default:
            result = userLogic.create((UserTO) anyTO, true, nullPriorityAsync);
            break;
        case GROUP:
            result = groupLogic.create((GroupTO) anyTO, nullPriorityAsync);
            break;
        case ANY_OBJECT:
            result = anyObjectLogic.create((AnyObjectTO) anyTO, nullPriorityAsync);
    }
    remediationDAO.delete(remediation);
    return result;
}
Also used : AnyObjectTO(org.apache.syncope.common.lib.to.AnyObjectTO) UserTO(org.apache.syncope.common.lib.to.UserTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) Remediation(org.apache.syncope.core.persistence.api.entity.Remediation) GroupTO(org.apache.syncope.common.lib.to.GroupTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 38 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupLogic method update.

@PreAuthorize("hasRole('" + StandardEntitlement.GROUP_UPDATE + "')")
@Override
public ProvisioningResult<GroupTO> update(final GroupPatch groupPatch, final boolean nullPriorityAsync) {
    GroupTO groupTO = binder.getGroupTO(groupPatch.getKey());
    Set<String> dynRealmsBefore = new HashSet<>(groupTO.getDynRealms());
    Pair<GroupPatch, List<LogicActions>> before = beforeUpdate(groupPatch, groupTO.getRealm());
    String realm = before.getLeft().getRealm() != null && StringUtils.isNotBlank(before.getLeft().getRealm().getValue()) ? before.getLeft().getRealm().getValue() : groupTO.getRealm();
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.GROUP_UPDATE), realm);
    boolean authDynRealms = securityChecks(effectiveRealms, realm, before.getLeft().getKey());
    Pair<GroupPatch, List<PropagationStatus>> updated = provisioningManager.update(groupPatch, nullPriorityAsync);
    return afterUpdate(binder.getGroupTO(updated.getLeft().getKey()), updated.getRight(), before.getRight(), authDynRealms, dynRealmsBefore);
}
Also used : List(java.util.List) GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) HashSet(java.util.HashSet) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 39 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupLogic method provision.

@PreAuthorize("hasRole('" + StandardEntitlement.GROUP_UPDATE + "')")
@Override
public ProvisioningResult<GroupTO> provision(final String key, final Collection<String> resources, final boolean changePwd, final String password, final boolean nullPriorityAsync) {
    // security checks
    GroupTO group = binder.getGroupTO(key);
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.GROUP_UPDATE), group.getRealm());
    securityChecks(effectiveRealms, group.getRealm(), group.getKey());
    List<PropagationStatus> statuses = provisioningManager.provision(key, resources, nullPriorityAsync);
    ProvisioningResult<GroupTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getGroupTO(key));
    result.getPropagationStatuses().addAll(statuses);
    return result;
}
Also used : ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) PropagationStatus(org.apache.syncope.common.lib.to.PropagationStatus) GroupTO(org.apache.syncope.common.lib.to.GroupTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 40 with GroupTO

use of org.apache.syncope.common.lib.to.GroupTO in project syncope by apache.

the class GroupLogic method unassign.

@PreAuthorize("hasRole('" + StandardEntitlement.GROUP_UPDATE + "')")
@Override
public ProvisioningResult<GroupTO> unassign(final String key, final Collection<String> resources, final boolean nullPriorityAsync) {
    // security checks
    GroupTO group = binder.getGroupTO(key);
    Set<String> effectiveRealms = RealmUtils.getEffective(AuthContextUtils.getAuthorizations().get(StandardEntitlement.GROUP_UPDATE), group.getRealm());
    securityChecks(effectiveRealms, group.getRealm(), group.getKey());
    GroupPatch patch = new GroupPatch();
    patch.setKey(key);
    patch.getResources().addAll(resources.stream().map(resource -> new StringPatchItem.Builder().operation(PatchOperation.DELETE).value(resource).build()).collect(Collectors.toList()));
    patch.getADynMembershipConds().putAll(group.getADynMembershipConds());
    patch.setUDynMembershipCond(group.getUDynMembershipCond());
    return update(patch, nullPriorityAsync);
}
Also used : GroupPatch(org.apache.syncope.common.lib.patch.GroupPatch) GroupTO(org.apache.syncope.common.lib.to.GroupTO) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

GroupTO (org.apache.syncope.common.lib.to.GroupTO)90 Test (org.junit.jupiter.api.Test)47 UserTO (org.apache.syncope.common.lib.to.UserTO)34 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)27 GroupPatch (org.apache.syncope.common.lib.patch.GroupPatch)23 MembershipTO (org.apache.syncope.common.lib.to.MembershipTO)17 AnyObjectTO (org.apache.syncope.common.lib.to.AnyObjectTO)16 List (java.util.List)15 AttrTO (org.apache.syncope.common.lib.to.AttrTO)15 ConnObjectTO (org.apache.syncope.common.lib.to.ConnObjectTO)14 ProvisioningResult (org.apache.syncope.common.lib.to.ProvisioningResult)14 Response (javax.ws.rs.core.Response)13 NamingException (javax.naming.NamingException)12 PropagationStatus (org.apache.syncope.common.lib.to.PropagationStatus)12 Map (java.util.Map)11 ForbiddenException (javax.ws.rs.ForbiddenException)11 AccessControlException (java.security.AccessControlException)10 BulkActionResult (org.apache.syncope.common.lib.to.BulkActionResult)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)10 Collections (java.util.Collections)9