Search in sources :

Example 86 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class CouchbaseFilterConverterTest method checkOrJoinFilters.

@Test
public void checkOrJoinFilters() throws SearchException {
    // And with join
    Filter filterEq1 = Filter.createEqualityFilter("uid", "test");
    Filter filterEq2 = Filter.createEqualityFilter("uid", "test2");
    Filter filterEq3 = Filter.createEqualityFilter("uid", "test3");
    Filter filterOr1 = Filter.createORFilter(filterEq1, filterEq2, filterEq3).multiValued(false);
    ConvertedExpression expressionOr1 = simpleConverter.convertToCouchbaseFilter(filterOr1, null, null);
    String queryOr1 = toSelectSQL(expressionOr1);
    assertEquals(queryOr1, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ( uid IN [\"test\",\"test2\",\"test3\"] )");
    Filter filterOr2 = Filter.createORFilter(filterEq1, filterEq2, filterEq3);
    ConvertedExpression expressionOr2 = simpleConverter.convertToCouchbaseFilter(filterOr2, null, null);
    String queryOr2 = toSelectSQL(expressionOr2);
    assertEquals(queryOr2, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ( ( ( uid = \"test\" ) OR ( \"test\" IN uid ) ) OR ( ( uid = \"test2\" ) OR ( \"test2\" IN uid ) ) OR ( ( uid = \"test3\" ) OR ( \"test3\" IN uid ) ) )");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.couchbase.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 87 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class CouchbaseFilterConverterTest method checkSinglevaluedEqFilters.

@Test
public void checkSinglevaluedEqFilters() throws SearchException {
    // EQ -- String
    Filter filterEq1 = Filter.createEqualityFilter("uid", "test").multiValued(false);
    ConvertedExpression expressionEq1 = simpleConverter.convertToCouchbaseFilter(filterEq1, null, null);
    String queryEq1 = toSelectSQL(expressionEq1);
    assertEquals(queryEq1, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE uid = \"test\"");
    // EQ -- Integer
    Filter filterEq2 = Filter.createEqualityFilter("age", 23).multiValued(false);
    ConvertedExpression expressionEq2 = simpleConverter.convertToCouchbaseFilter(filterEq2, null, null);
    String queryEq2 = toSelectSQL(expressionEq2);
    assertEquals(queryEq2, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE age = 23");
    // EQ -- Long
    Filter filterEq3 = Filter.createEqualityFilter("age", 23L).multiValued(false);
    ConvertedExpression expressionEq3 = simpleConverter.convertToCouchbaseFilter(filterEq3, null, null);
    String queryEq3 = toSelectSQL(expressionEq3);
    assertEquals(queryEq3, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE age = 23");
    // EQ -- Date
    Filter filterEq4 = Filter.createEqualityFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued(false);
    ConvertedExpression expressionEq4 = simpleConverter.convertToCouchbaseFilter(filterEq4, null, null);
    String queryEq4 = toSelectSQL(expressionEq4);
    assertEquals(queryEq4, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE added = \"Wed Dec 16 14:58:18 UTC 2020\"");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.couchbase.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 88 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class CouchbaseFilterConverterTest method checkMultivaluedEqFilters.

@Test
public void checkMultivaluedEqFilters() throws SearchException {
    // EQ -- String
    Filter filterEq1 = Filter.createEqualityFilter("uid", "test").multiValued();
    ConvertedExpression expressionEq1 = simpleConverter.convertToCouchbaseFilter(filterEq1, null, null);
    String queryEq1 = toSelectSQL(expressionEq1);
    assertEquals(queryEq1, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ANY uid_ IN uid SATISFIES uid_ = \"test\" END");
    // EQ -- Integer
    Filter filterEq2 = Filter.createEqualityFilter("age", 23).multiValued();
    ConvertedExpression expressionEq2 = simpleConverter.convertToCouchbaseFilter(filterEq2, null, null);
    String queryEq2 = toSelectSQL(expressionEq2);
    assertEquals(queryEq2, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ANY age_ IN age SATISFIES age_ = 23 END");
    // EQ -- Long
    Filter filterEq3 = Filter.createEqualityFilter("age", 23L).multiValued();
    ConvertedExpression expressionEq3 = simpleConverter.convertToCouchbaseFilter(filterEq3, null, null);
    String queryEq3 = toSelectSQL(expressionEq3);
    assertEquals(queryEq3, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ANY age_ IN age SATISFIES age_ = 23 END");
    // EQ -- Date
    Filter filterEq4 = Filter.createEqualityFilter("added", getUtcDateFromMillis(1608130698398L)).multiValued();
    ConvertedExpression expressionEq4 = simpleConverter.convertToCouchbaseFilter(filterEq4, null, null);
    String queryEq4 = toSelectSQL(expressionEq4);
    assertEquals(queryEq4, "SELECT jans_doc.* FROM `jans` AS jans_doc WHERE ANY added_ IN added SATISFIES added_ = \"Wed Dec 16 14:58:18 UTC 2020\" END");
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.couchbase.model.ConvertedExpression) Test(org.testng.annotations.Test)

Example 89 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class LdapBatchJobSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    LdapEntryManagerSample ldapEntryManagerSample = new LdapEntryManagerSample();
    // Create LDAP entry manager
    final LdapEntryManager ldapEntryManager = ldapEntryManagerSample.createLdapEntryManager();
    BatchOperation<SimpleTokenLdap> tokenLdapBatchOperation = new ProcessBatchOperation<SimpleTokenLdap>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleTokenLdap> objects) {
            for (SimpleTokenLdap simpleTokenLdap : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, simpleTokenLdap.getDn(), "exp", simpleTokenLdap.getAttribute("exp"));
                    simpleTokenLdap.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    ldapEntryManager.merge(simpleTokenLdap);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter1 = Filter.createPresenceFilter("exp");
    ldapEntryManager.findEntries("o=jans", SimpleTokenLdap.class, filter1, SearchScope.SUB, new String[] { "exp" }, tokenLdapBatchOperation, 0, 0, 100);
    BatchOperation<SimpleSession> sessionBatchOperation = new ProcessBatchOperation<SimpleSession>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleSession> objects) {
            for (SimpleSession simpleSession : objects) {
                try {
                    CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, simpleSession.getDn(), "jansLastAccessTime", simpleSession.getAttribute("jansLastAccessTime"));
                    simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
                    ldapEntryManager.merge(simpleSession);
                    processedCount++;
                } catch (EntryPersistenceException ex) {
                    LOG.error("Failed to update entry", ex);
                }
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter2 = Filter.createPresenceFilter("jansLastAccessTime");
    ldapEntryManager.findEntries("o=jans", SimpleSession.class, filter2, SearchScope.SUB, new String[] { "jansLastAccessTime" }, sessionBatchOperation, 0, 0, 100);
    BatchOperation<SimpleClient> clientBatchOperation = new ProcessBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter3 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result3 = ldapEntryManager.findEntries("o=jans", SimpleClient.class, filter3, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation, 0, 0, 1000);
    LOG.info("Result count (without collecting results): " + result3.size());
    BatchOperation<SimpleClient> clientBatchOperation2 = new DefaultBatchOperation<SimpleClient>() {

        private int processedCount = 0;

        @Override
        public void performAction(List<SimpleClient> objects) {
            for (SimpleClient simpleClient : objects) {
                processedCount++;
            }
            LOG.info("Total processed: " + processedCount);
        }
    };
    final Filter filter4 = Filter.createPresenceFilter("exp");
    List<SimpleClient> result4 = ldapEntryManager.findEntries("o=jans", SimpleClient.class, filter4, SearchScope.SUB, new String[] { "exp" }, clientBatchOperation2, 0, 0, 1000);
    LOG.info("Result count (with collecting results): " + result4.size());
}
Also used : SimpleTokenLdap(io.jans.orm.ldap.model.SimpleTokenLdap) CustomAttribute(io.jans.orm.model.base.CustomAttribute) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) DefaultBatchOperation(io.jans.orm.model.DefaultBatchOperation) LdapEntryManager(io.jans.orm.ldap.impl.LdapEntryManager) Filter(io.jans.orm.search.filter.Filter) ProcessBatchOperation(io.jans.orm.model.ProcessBatchOperation) List(java.util.List) SimpleClient(io.jans.orm.ldap.model.SimpleClient) SimpleSession(io.jans.orm.ldap.model.SimpleSession)

Example 90 with Filter

use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.

the class LdapUserFieldRemove method main.

public static void main(String[] args) {
    // Prepare sample connection details
    LdapEntryManagerSample ldapSampleEntryManager = new LdapEntryManagerSample();
    // Create LDAP entry manager
    LdapEntryManager ldapEntryManager = ldapSampleEntryManager.createLdapEntryManager();
    // Find all users which have specified object classes defined in SimpleUser
    Filter filter = Filter.createEqualityFilter("uid", "admin");
    List<SimpleUser> users = ldapEntryManager.findEntries("o=gluu", SimpleUser.class, filter);
    if (users.size() == 0) {
        LOG.error("Failed to find user by filter: " + filter);
        return;
    }
    LOG.debug("Find user by filter: " + filter);
    // Add dummy oxEnrollmentCode attribute
    SimpleUser user = users.get(0);
    user.setAttribute("oxEnrollmentCode", "test-enrollment-code", false);
    ldapEntryManager.merge(user);
    // Reload user by DN
    SimpleUser userWithEnrollment = ldapEntryManager.find(SimpleUser.class, user.getDn());
    if (users.size() == 0) {
        LOG.error("Failed to find user by DN: " + user.getDn());
        return;
    }
    // Clean dummy oxEnrollmentCode attribute
    userWithEnrollment.setAttribute("oxEnrollmentCode", "", false);
    ldapEntryManager.merge(userWithEnrollment);
    // Reload user by DN
    SimpleUser userWithoutEnrollment = ldapEntryManager.find(SimpleUser.class, user.getDn());
    if (users.size() == 0) {
        LOG.error("Failed to find user by DN: " + user.getDn());
        return;
    }
    String enrollmentCode = userWithoutEnrollment.getAttribute("oxEnrollmentCode");
    LOG.debug("oxEnrollmentCode: " + enrollmentCode);
}
Also used : SimpleUser(io.jans.orm.ldap.model.SimpleUser) LdapEntryManager(io.jans.orm.ldap.impl.LdapEntryManager) Filter(io.jans.orm.search.filter.Filter)

Aggregations

Filter (io.jans.orm.search.filter.Filter)188 Test (org.testng.annotations.Test)50 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)32 ConvertedExpression (io.jans.orm.couchbase.model.ConvertedExpression)28 SearchException (io.jans.orm.exception.operation.SearchException)25 ConvertedExpression (io.jans.orm.sql.model.ConvertedExpression)24 MappingException (io.jans.orm.exception.MappingException)22 ArrayList (java.util.ArrayList)21 AuthenticationException (io.jans.orm.exception.AuthenticationException)20 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)19 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)18 Date (java.util.Date)14 List (java.util.List)14 SqlEntryManager (io.jans.orm.sql.impl.SqlEntryManager)11 SqlEntryManagerSample (io.jans.orm.sql.persistence.SqlEntryManagerSample)11 CustomAttribute (io.jans.orm.model.base.CustomAttribute)9 CustomObjectAttribute (io.jans.orm.model.base.CustomObjectAttribute)9 DateTimeParseException (java.time.format.DateTimeParseException)9 SpannerEntryManager (io.jans.orm.cloud.spanner.impl.SpannerEntryManager)8 SpannerEntryManagerSample (io.jans.orm.cloud.spanner.persistence.SpannerEntryManagerSample)8