Search in sources :

Example 11 with AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.

the class AnySearchTest method groupOrderBy.

@Test
public void groupOrderBy() {
    AnyCond idLeafCond = new AnyCond(AnyCond.Type.LIKE);
    idLeafCond.setSchema("name");
    idLeafCond.setExpression("%r");
    SearchCond searchCondition = SearchCond.getLeafCond(idLeafCond);
    assertTrue(searchCondition.isValid());
    OrderByClause orderByClause = new OrderByClause();
    orderByClause.setField("name");
    List<Group> groups = searchDAO.search(searchCondition, Collections.singletonList(orderByClause), AnyTypeKind.GROUP);
    assertEquals(searchDAO.count(SyncopeConstants.FULL_ADMIN_REALMS, searchCondition, AnyTypeKind.GROUP), groups.size());
}
Also used : 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) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 12 with AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.

the class AnySearchTest method searchByGroupNameAndKey.

@Test
public void searchByGroupNameAndKey() {
    AnyCond groupNameLeafCond = new AnyCond(AnyCond.Type.EQ);
    groupNameLeafCond.setSchema("name");
    groupNameLeafCond.setExpression("root");
    AnyCond idRightCond = new AnyCond(AnyCond.Type.EQ);
    idRightCond.setSchema("id");
    idRightCond.setExpression("37d15e4c-cdc1-460b-a591-8505c8133806");
    SearchCond searchCondition = SearchCond.getAndCond(SearchCond.getLeafCond(groupNameLeafCond), SearchCond.getLeafCond(idRightCond));
    assertTrue(searchCondition.isValid());
    List<Group> matching = searchDAO.search(searchCondition, AnyTypeKind.GROUP);
    assertNotNull(matching);
    assertEquals(1, matching.size());
    assertEquals("root", matching.iterator().next().getName());
    assertEquals("37d15e4c-cdc1-460b-a591-8505c8133806", matching.iterator().next().getKey());
}
Also used : Group(org.apache.syncope.core.persistence.api.entity.group.Group) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) Test(org.junit.jupiter.api.Test) AbstractTest(org.apache.syncope.core.persistence.jpa.AbstractTest)

Example 13 with AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.

the class DefaultRealmPullResultHandler method delete.

private List<ProvisioningReport> delete(final SyncDelta delta, final List<String> keys) throws JobExecutionException {
    if (!profile.getTask().isPerformDelete()) {
        LOG.debug("PullTask not configured for delete");
        finalize(ResourceOperation.DELETE.name().toLowerCase(), Result.SUCCESS, null, null, delta);
        return Collections.<ProvisioningReport>emptyList();
    }
    LOG.debug("About to delete {}", keys);
    List<ProvisioningReport> results = new ArrayList<>();
    for (String key : keys) {
        Object output;
        Result resultStatus = Result.FAILURE;
        ProvisioningReport result = new ProvisioningReport();
        try {
            result.setKey(key);
            result.setOperation(ResourceOperation.DELETE);
            result.setAnyType(REALM_TYPE);
            result.setStatus(ProvisioningReport.Status.SUCCESS);
            Realm realm = realmDAO.find(key);
            RealmTO before = binder.getRealmTO(realm, true);
            if (before == null) {
                result.setStatus(ProvisioningReport.Status.FAILURE);
                result.setMessage(String.format("Realm '%s' not found", key));
            } else {
                result.setName(before.getFullPath());
            }
            if (!profile.isDryRun()) {
                for (PullActions action : profile.getActions()) {
                    action.beforeDelete(profile, delta, before);
                }
                try {
                    if (!realmDAO.findChildren(realm).isEmpty()) {
                        throw SyncopeClientException.build(ClientExceptionType.HasChildren);
                    }
                    Set<String> adminRealms = Collections.singleton(realm.getFullPath());
                    AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
                    keyCond.setSchema("key");
                    SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
                    int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
                    int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
                    int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
                    if (users + groups + anyObjects > 0) {
                        SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
                        containedAnys.getElements().add(users + " user(s)");
                        containedAnys.getElements().add(groups + " group(s)");
                        containedAnys.getElements().add(anyObjects + " anyObject(s)");
                        throw containedAnys;
                    }
                    PropagationByResource propByRes = new PropagationByResource();
                    for (String resource : realm.getResourceKeys()) {
                        propByRes.add(ResourceOperation.DELETE, resource);
                    }
                    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
                    taskExecutor.execute(tasks, false);
                    realmDAO.delete(realm);
                    output = null;
                    resultStatus = Result.SUCCESS;
                    for (PullActions action : profile.getActions()) {
                        action.after(profile, delta, before, result);
                    }
                } catch (Exception e) {
                    throwIgnoreProvisionException(delta, e);
                    result.setStatus(ProvisioningReport.Status.FAILURE);
                    result.setMessage(ExceptionUtils.getRootCauseMessage(e));
                    LOG.error("Could not delete {}", realm, e);
                    output = e;
                }
                finalize(ResourceOperation.DELETE.name().toLowerCase(), resultStatus, before, output, delta);
            }
            results.add(result);
        } catch (DelegatedAdministrationException e) {
            LOG.error("Not allowed to read Realm {}", key, e);
        } catch (Exception e) {
            LOG.error("Could not delete Realm {}", key, e);
        }
    }
    return results;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) PullActions(org.apache.syncope.core.provisioning.api.pushpull.PullActions) ArrayList(java.util.ArrayList) RealmTO(org.apache.syncope.common.lib.to.RealmTO) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) ProvisioningReport(org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) DelegatedAdministrationException(org.apache.syncope.core.spring.security.DelegatedAdministrationException) IgnoreProvisionException(org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException) PropagationException(org.apache.syncope.core.provisioning.api.propagation.PropagationException) JobExecutionException(org.quartz.JobExecutionException) Result(org.apache.syncope.common.lib.types.AuditElements.Result) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond)

Example 14 with AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.

the class SearchCondVisitor method createAttributeCond.

public AttributeCond createAttributeCond(final String schema) {
    AttributeCond attributeCond = null;
    if (schemaEquals(Resource.User, "userName", schema)) {
        attributeCond = new AnyCond();
        attributeCond.setSchema("username");
    } else if (resource == Resource.Group && schemaEquals(Resource.Group, "displayName", schema)) {
        attributeCond = new AnyCond();
        attributeCond.setSchema("name");
    } else if (schemaEquals(null, "meta.created", schema)) {
        attributeCond = new AnyCond();
        attributeCond.setSchema("creationDate");
    } else if (schemaEquals(null, "meta.lastModified", schema)) {
        attributeCond = new AnyCond();
        attributeCond.setSchema("lastChangeDate");
    }
    if (resource == Resource.User) {
        if (conf.getUserConf() != null) {
            if (conf.getUserConf().getName() != null) {
                for (Map.Entry<String, String> entry : conf.getUserConf().getName().asMap().entrySet()) {
                    if (schemaEquals(Resource.User, "name." + entry.getKey(), schema)) {
                        attributeCond = new AttributeCond();
                        attributeCond.setSchema(entry.getValue());
                    }
                }
            }
            for (Map.Entry<String, String> entry : conf.getUserConf().asMap().entrySet()) {
                if (schemaEquals(Resource.User, entry.getKey(), schema)) {
                    attributeCond = new AttributeCond();
                    attributeCond.setSchema(entry.getValue());
                }
            }
            for (SCIMUserAddressConf address : conf.getUserConf().getAddresses()) {
                for (Map.Entry<String, String> entry : address.asMap().entrySet()) {
                    if (schemaEquals(Resource.User, "addresses." + entry.getKey(), schema)) {
                        attributeCond = new AttributeCond();
                        attributeCond.setSchema(entry.getValue());
                    }
                }
            }
        }
        if (conf.getEnterpriseUserConf() != null) {
            for (Map.Entry<String, String> entry : conf.getEnterpriseUserConf().asMap().entrySet()) {
                if (schemaEquals(Resource.EnterpriseUser, entry.getKey(), schema)) {
                    attributeCond = new AttributeCond();
                    attributeCond.setSchema(entry.getValue());
                }
            }
            if (conf.getEnterpriseUserConf().getManager() != null && conf.getEnterpriseUserConf().getManager().getKey() != null) {
                attributeCond = new AttributeCond();
                attributeCond.setSchema(conf.getEnterpriseUserConf().getManager().getKey());
            }
        }
    }
    if (attributeCond == null) {
        throw new IllegalArgumentException("Could not match " + schema + " for " + resource);
    }
    return attributeCond;
}
Also used : AttributeCond(org.apache.syncope.core.persistence.api.dao.search.AttributeCond) SCIMUserAddressConf(org.apache.syncope.common.lib.scim.SCIMUserAddressConf) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) Map(java.util.Map)

Example 15 with AnyCond

use of org.apache.syncope.core.persistence.api.dao.search.AnyCond in project syncope by apache.

the class RealmLogic method delete.

@PreAuthorize("hasRole('" + StandardEntitlement.REALM_DELETE + "')")
public ProvisioningResult<RealmTO> delete(final String fullPath) {
    Realm realm = realmDAO.findByFullPath(fullPath);
    if (realm == null) {
        LOG.error("Could not find realm '" + fullPath + "'");
        throw new NotFoundException(fullPath);
    }
    if (!realmDAO.findChildren(realm).isEmpty()) {
        throw SyncopeClientException.build(ClientExceptionType.HasChildren);
    }
    Set<String> adminRealms = Collections.singleton(realm.getFullPath());
    AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
    keyCond.setSchema("key");
    SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
    int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
    int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
    int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
    if (users + groups + anyObjects > 0) {
        SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
        containedAnys.getElements().add(users + " user(s)");
        containedAnys.getElements().add(groups + " group(s)");
        containedAnys.getElements().add(anyObjects + " anyObject(s)");
        throw containedAnys;
    }
    PropagationByResource propByRes = new PropagationByResource();
    realm.getResourceKeys().forEach(resource -> {
        propByRes.add(ResourceOperation.DELETE, resource);
    });
    List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
    PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
    ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
    result.setEntity(binder.getRealmTO(realm, true));
    result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
    realmDAO.delete(realm);
    return result;
}
Also used : PropagationTaskTO(org.apache.syncope.common.lib.to.PropagationTaskTO) ProvisioningResult(org.apache.syncope.common.lib.to.ProvisioningResult) SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) RealmTO(org.apache.syncope.common.lib.to.RealmTO) NotFoundException(org.apache.syncope.core.persistence.api.dao.NotFoundException) PropagationByResource(org.apache.syncope.core.provisioning.api.PropagationByResource) PropagationReporter(org.apache.syncope.core.provisioning.api.propagation.PropagationReporter) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Realm(org.apache.syncope.core.persistence.api.entity.Realm) AnyCond(org.apache.syncope.core.persistence.api.dao.search.AnyCond) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

AnyCond (org.apache.syncope.core.persistence.api.dao.search.AnyCond)25 SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)20 Test (org.junit.jupiter.api.Test)16 AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)11 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)10 UserFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder)6 User (org.apache.syncope.core.persistence.api.entity.user.User)6 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)3 Group (org.apache.syncope.core.persistence.api.entity.group.Group)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 SyncopeClientException (org.apache.syncope.common.lib.SyncopeClientException)2 PropagationTaskTO (org.apache.syncope.common.lib.to.PropagationTaskTO)2 RealmTO (org.apache.syncope.common.lib.to.RealmTO)2 Realm (org.apache.syncope.core.persistence.api.entity.Realm)2 PropagationByResource (org.apache.syncope.core.provisioning.api.PropagationByResource)2 Annotation (java.lang.annotation.Annotation)1 ManagementFactory (java.lang.management.ManagementFactory)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1