use of io.jans.orm.ldap.model.SimpleUser in project jans by JanssenProject.
the class LdapSample method main.
public static void main(String[] args) {
// Prepare sample connection details
LdapEntryManagerSample ldapEntryManagerSample = new LdapEntryManagerSample();
// Create LDAP entry manager
LdapEntryManager ldapEntryManager = ldapEntryManagerSample.createLdapEntryManager();
// Find all users which have specified object classes defined in SimpleUser
List<SimpleUser> users = ldapEntryManager.findEntries("o=jans", SimpleUser.class, null);
for (SimpleUser user : users) {
LOG.debug("User with uid: " + user.getUserId());
}
if (users.size() > 0) {
// Add attribute "streetAddress" to first user
SimpleUser user = users.get(0);
user.getCustomAttributes().add(new CustomAttribute("streetAddress", "Somewhere: " + System.currentTimeMillis()));
ldapEntryManager.merge(user);
}
Filter filter = Filter.createEqualityFilter("status", "active");
List<SimpleAttribute> attributes = ldapEntryManager.findEntries("o=jans", SimpleAttribute.class, filter, SearchScope.SUB, null, null, 10, 0, 0);
for (SimpleAttribute attribute : attributes) {
LOG.debug("Attribute with displayName: " + attribute.getCustomAttributes().get(1));
}
List<SimpleSession> sessions = ldapEntryManager.findEntries("o=jans", SimpleSession.class, filter, SearchScope.SUB, null, null, 10, 0, 0);
LOG.debug("Found sessions: " + sessions.size());
List<SimpleGrant> grants = ldapEntryManager.findEntries("o=jans", SimpleGrant.class, null, SearchScope.SUB, new String[] { "grtId" }, null, 10, 0, 0);
LOG.debug("Found grants: " + grants.size());
try {
PagedResult<SimpleUser> vlvResponse = ldapEntryManager.findPagedEntries("o=jans", SimpleUser.class, null, new String[] { "uid", "displayName", "status" }, "displayName", SortOrder.ASCENDING, 10, 100000, 1000);
LOG.debug("Found persons: " + vlvResponse.getTotalEntriesCount());
System.out.println(vlvResponse.getEntries().size());
} catch (Exception ex) {
LOG.error("Failed to search", ex);
}
}
use of io.jans.orm.ldap.model.SimpleUser 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