use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class SqlCustomMultiValuedTypesSample method main.
public static void main(String[] args) {
// Prepare sample connection details
SqlEntryManagerSample sqlEntryManagerSample = new SqlEntryManagerSample();
// Create SQL entry manager
SqlEntryManager sqlEntryManager = sqlEntryManagerSample.createSqlEntryManager();
// Add dummy user
SimpleUser newUser = new SimpleUser();
newUser.setDn(String.format("inum=%s,ou=people,o=jans", System.currentTimeMillis()));
newUser.setUserId("sample_user_" + System.currentTimeMillis());
newUser.setUserPassword("test");
newUser.getCustomAttributes().add(new CustomObjectAttribute("jansOptOuts", Arrays.asList("London", "Texas", "Kiev")));
newUser.getCustomAttributes().add(new CustomObjectAttribute("jansExtUid", "test_value").multiValued());
newUser.getCustomAttributes().add(new CustomObjectAttribute("jansPPID", "test_value").multiValued());
newUser.setMemberOf(Arrays.asList("group_1", "group_2", "group_3"));
newUser.setAttributeValue("givenName", "john");
sqlEntryManager.persist(newUser);
LOG.info("Added User '{}' with uid '{}' and key '{}'", newUser, newUser.getUserId(), newUser.getDn());
LOG.info("Persisted custom attributes '{}'", newUser.getCustomAttributes());
// Find added dummy user
SimpleUser foundUser = sqlEntryManager.find(SimpleUser.class, newUser.getDn());
LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUser, foundUser.getUserId(), foundUser.getDn());
LOG.info("Custom attributes '{}'", foundUser.getCustomAttributes());
// Dump custom attributes
for (CustomObjectAttribute attr : foundUser.getCustomAttributes()) {
System.out.println(attr.getName() + " - " + attr.getValues());
}
// Update custom attributes
foundUser.setAttributeValues("jansOptOuts", Arrays.asList("London", "Texas", "Kiev", "Dublin"));
foundUser.setAttributeValues("jansExtUid", Arrays.asList("test_value_11", "test_value_22", "test_value_33", "test_value_44"));
foundUser.setAttributeValues("jansExtUid", Arrays.asList(11, 22, 33, 44));
foundUser.setAttributeValues("jansPPID", Arrays.asList("fuzzy_value_1", "fuzzy_value_2"));
foundUser.setAttributeValue("jansGuid", "simple");
CustomObjectAttribute multiValuedSingleValue = new CustomObjectAttribute("jansAssociatedClnt", "multivalued_single_valued");
multiValuedSingleValue.setMultiValued(true);
foundUser.getCustomAttributes().add(multiValuedSingleValue);
sqlEntryManager.merge(foundUser);
LOG.info("Updated custom attributes '{}'", foundUser.getCustomAttributes());
// Find updated dummy user
SimpleUser foundUpdatedUser = sqlEntryManager.find(SimpleUser.class, newUser.getDn());
LOG.info("Found User '{}' with uid '{}' and key '{}'", foundUpdatedUser, foundUpdatedUser.getUserId(), foundUpdatedUser.getDn());
LOG.info("Cusom attributes '{}'", foundUpdatedUser.getCustomAttributes());
// Dump custom attributes
for (CustomObjectAttribute attr : foundUser.getCustomAttributes()) {
System.out.println(attr.getName() + " - " + attr.getValues());
}
Filter filter = Filter.createEqualityFilter(Filter.createLowercaseFilter("givenName"), StringHelper.toLowerCase("john"));
List<SimpleUser> foundUpdatedUsers = sqlEntryManager.findEntries("o=jans", SimpleUser.class, filter);
System.out.println(foundUpdatedUsers);
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class SqlSimpleGroupSample method main.
public static void main(String[] args) {
// Prepare sample connection details
SqlEntryManagerSample sqlEntryManagerSample = new SqlEntryManagerSample();
// Create SQL entry manager
SqlEntryManager sqlEntryManager = sqlEntryManagerSample.createSqlEntryManager();
String personDN = "inum=ae8c7ff9-def7-4b42-8147-de8380617a37,ou=people,o=gluu";
Filter ownerFilter = Filter.createEqualityFilter("owner", personDN);
Filter memberFilter = Filter.createEqualityFilter("member", personDN);
Filter searchFilter = Filter.createORFilter(ownerFilter, memberFilter);
List<SimpleGroup> result = sqlEntryManager.findEntries("ou=groups,o=gluu", SimpleGroup.class, searchFilter, 1);
System.out.println(result);
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class SpannerEntryManager method removeImpl.
protected <T> int removeImpl(String dn, Class<T> entryClass, Filter filter, int count) {
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
Filter searchFilter;
if (objectClasses.length > 0) {
LOG.trace("Filter: {}", filter);
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
throw new EntryDeleteException(String.format("Failed to delete entries with DN: '%s', filter: '%s' because objectClass is not specified", dn, filter));
}
// Find entries
LOG.trace("-------------------------------------------------------");
LOG.trace("Filter: {}", filter);
LOG.trace("objectClasses count: {} ", objectClasses.length);
LOG.trace("objectClasses: {}", objectClasses.toString());
LOG.trace("Search filter: {}", searchFilter);
// Prepare properties types to allow build filter properly
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
String key = toSQLKey(dn).getKey();
ConvertedExpression convertedExpression;
try {
convertedExpression = toSqlFilterWithEmptyAlias(key, objectClasses[0], searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryDeleteException(String.format("Failed to convert filter '%s' to expression", searchFilter));
}
try {
int processed = (int) getOperationService().delete(key, objectClasses[0], convertedExpression, count);
return processed;
} catch (Exception ex) {
throw new EntryDeleteException(String.format("Failed to delete entries with key: '%s', expression: '%s'", key, convertedExpression), ex);
}
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class FidoDeviceWebService method searchDevices.
private PagedResult<BaseScimResource> searchDevices(String userId, String filter, String sortBy, SortOrder sortOrder, int startIndex, int count) throws Exception {
Filter ldapFilter = scimFilterParserService.createFilter(filter, Filter.createPresenceFilter("jansId"), FidoDeviceResource.class);
log.info("Executing search for fido devices using: ldapfilter '{}', sortBy '{}', sortOrder '{}', startIndex '{}', count '{}', userId '{}'", ldapFilter.toString(), sortBy, sortOrder.getValue(), startIndex, count, userId);
// Currently, searching with SUB scope in Couchbase requires some help (beyond use of baseDN)
if (StringUtils.isNotEmpty(userId)) {
ldapFilter = Filter.createANDFilter(ldapFilter, Filter.createEqualityFilter("personInum", userId));
}
PagedResult<GluuCustomFidoDevice> list;
try {
list = entryManager.findPagedEntries(fidoDeviceService.getDnForFidoDevice(userId, null), GluuCustomFidoDevice.class, ldapFilter, null, sortBy, sortOrder, startIndex - 1, count, getMaxCount());
} catch (Exception e) {
log.info("Returning an empty listViewReponse");
log.error(e.getMessage(), e);
list = new PagedResult<>();
list.setEntries(new ArrayList<>());
}
List<BaseScimResource> resources = new ArrayList<>();
for (GluuCustomFidoDevice device : list.getEntries()) {
FidoDeviceResource scimDev = new FidoDeviceResource();
transferAttributesToFidoResource(device, scimDev, endpointUrl, userPersistenceHelper.getUserInumFromDN(device.getDn()));
resources.add(scimDev);
}
log.info("Found {} matching entries - returning {}", list.getTotalEntriesCount(), list.getEntries().size());
PagedResult<BaseScimResource> result = new PagedResult<>();
result.setEntries(resources);
result.setTotalEntriesCount(list.getTotalEntriesCount());
return result;
}
use of io.jans.orm.search.filter.Filter in project jans by JanssenProject.
the class Scim2GroupService method restoreMembersDisplay.
/**
* Takes two GroupResource objects and attempts to fill the members' display names
* in the second object when missing based on the data existing in the first object.
* In practice the first object represents an already stored group while the
* second is the result of modifications applied upon the first. In the course
* of modifications some display names may have removed. This method tries to
* recover some of this lost data
* @param trusted Object containing valid group data
* @param altered Modified object
*/
public void restoreMembersDisplay(GroupResource trusted, GroupResource altered) {
int aSize = membersCount(altered);
int tSize = membersCount(trusted);
if (aSize > 0 && tSize > 0) {
Map<String, String> map = trusted.getMembers().stream().filter(m -> m.getDisplay() != null).collect(Collectors.toMap(Member::getValue, Member::getDisplay));
for (Member member : altered.getMembers()) {
String inum = member.getValue();
if (member.getDisplay() == null) {
member.setDisplay(map.get(inum));
}
}
}
}
Aggregations