Search in sources :

Example 36 with SearchCond

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

the class SCIMFilterTest method sw.

@Test
public void sw() {
    SearchCond cond = SearchCondConverter.convert(VISITOR, "userName sw \"J\"");
    assertNotNull(cond);
    assertNotNull(cond.getAnyCond());
    assertEquals("username", cond.getAnyCond().getSchema());
    assertEquals(AttributeCond.Type.ILIKE, cond.getAnyCond().getType());
    assertEquals("J%", cond.getAnyCond().getExpression());
    SearchCond fqn = SearchCondConverter.convert(VISITOR, "urn:ietf:params:scim:schemas:core:2.0:User:userName sw \"J\"");
    assertEquals(cond, fqn);
}
Also used : SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 37 with SearchCond

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

the class SCIMFilterTest method not.

@Test
public void not() {
    SearchCond cond = SearchCondConverter.convert(VISITOR, "not (title pr)");
    assertNotNull(cond);
    assertNotNull(cond.getAttributeCond());
    assertEquals("title", cond.getAttributeCond().getSchema());
    assertEquals(AttributeCond.Type.ISNULL, cond.getAttributeCond().getType());
    assertNull(cond.getAttributeCond().getExpression());
}
Also used : SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 38 with SearchCond

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

the class SCIMFilterTest method or.

@Test
public void or() {
    SearchCond cond = SearchCondConverter.convert(VISITOR, "title pr or displayName eq \"Other\"");
    assertNotNull(cond);
    assertEquals(SearchCond.Type.OR, cond.getType());
    SearchCond left = cond.getLeftSearchCond();
    assertNotNull(left);
    assertNotNull(left.getAttributeCond());
    assertEquals("title", left.getAttributeCond().getSchema());
    assertEquals(AttributeCond.Type.ISNOTNULL, left.getAttributeCond().getType());
    assertNull(left.getAttributeCond().getExpression());
    SearchCond right = cond.getRightSearchCond();
    assertNotNull(right);
    assertNotNull(right.getAttributeCond());
    assertEquals("cn", right.getAttributeCond().getSchema());
    assertEquals(AttributeCond.Type.IEQ, right.getAttributeCond().getType());
    assertEquals("Other", right.getAttributeCond().getExpression());
}
Also used : SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) Test(org.junit.jupiter.api.Test)

Example 39 with SearchCond

use of org.apache.syncope.core.persistence.api.dao.search.SearchCond 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 40 with SearchCond

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

the class RoleDataBinderImpl method setDynMembership.

private void setDynMembership(final Role role, final String dynMembershipFIQL) {
    SearchCond dynMembershipCond = SearchCondConverter.convert(dynMembershipFIQL);
    if (!dynMembershipCond.isValid()) {
        SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidSearchExpression);
        sce.getElements().add(dynMembershipFIQL);
        throw sce;
    }
    DynRoleMembership dynMembership;
    if (role.getDynMembership() == null) {
        dynMembership = entityFactory.newEntity(DynRoleMembership.class);
        dynMembership.setRole(role);
        role.setDynMembership(dynMembership);
    } else {
        dynMembership = role.getDynMembership();
    }
    dynMembership.setFIQLCond(dynMembershipFIQL);
}
Also used : SyncopeClientException(org.apache.syncope.common.lib.SyncopeClientException) SearchCond(org.apache.syncope.core.persistence.api.dao.search.SearchCond) DynRoleMembership(org.apache.syncope.core.persistence.api.entity.user.DynRoleMembership)

Aggregations

SearchCond (org.apache.syncope.core.persistence.api.dao.search.SearchCond)74 Test (org.junit.jupiter.api.Test)55 AttributeCond (org.apache.syncope.core.persistence.api.dao.search.AttributeCond)30 AnyCond (org.apache.syncope.core.persistence.api.dao.search.AnyCond)26 AbstractTest (org.apache.syncope.core.persistence.jpa.AbstractTest)25 User (org.apache.syncope.core.persistence.api.entity.user.User)20 UserFiqlSearchConditionBuilder (org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder)17 MembershipCond (org.apache.syncope.core.persistence.api.dao.search.MembershipCond)12 OrderByClause (org.apache.syncope.core.persistence.api.dao.search.OrderByClause)11 ArrayList (java.util.ArrayList)10 Group (org.apache.syncope.core.persistence.api.entity.group.Group)10 List (java.util.List)8 AnyTypeCond (org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond)8 AssignableCond (org.apache.syncope.core.persistence.api.dao.search.AssignableCond)7 MemberCond (org.apache.syncope.core.persistence.api.dao.search.MemberCond)7 Collections (java.util.Collections)6 Collectors (java.util.stream.Collectors)6 SyncopeConstants (org.apache.syncope.common.lib.SyncopeConstants)6 RelationshipCond (org.apache.syncope.core.persistence.api.dao.search.RelationshipCond)6 ResourceCond (org.apache.syncope.core.persistence.api.dao.search.ResourceCond)6