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