Search in sources :

Example 1 with SimpleUser

use of org.gluu.ldap.model.SimpleUser in project oxCore by GluuFederation.

the class LdapSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    LdapSampleEntryManager ldapSampleEntryManager = new LdapSampleEntryManager();
    // Create LDAP entry manager
    LdapEntryManager ldapEntryManager = ldapSampleEntryManager.createLdapEntryManager();
    // Find all users which have specified object classes defined in SimpleUser
    List<SimpleUser> users = ldapEntryManager.findEntries("o=gluu", 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("gluuStatus", "active");
    List<SimpleAttribute> attributes = ldapEntryManager.findEntries("o=gluu", 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=gluu", SimpleSession.class, filter, SearchScope.SUB, null, null, 10, 0, 0);
    LOG.debug("Found sessions: " + sessions.size());
    List<SimpleGrant> grants = ldapEntryManager.findEntries("o=gluu", SimpleGrant.class, null, SearchScope.SUB, new String[] { "oxAuthGrantId" }, null, 10, 0, 0);
    LOG.debug("Found grants: " + grants.size());
    try {
        ListViewResponse<SimpleUser> vlvResponse = ldapEntryManager.findListViewResponse("o=gluu", SimpleUser.class, null, 10, 100000, 1000, "displayName", SortOrder.ASCENDING, new String[] { "uid", "displayName", "gluuStatus" });
        LOG.debug("Found persons: " + vlvResponse.getTotalResults());
        System.out.println(vlvResponse.getResult().size());
    } catch (Exception ex) {
        LOG.error("Failed to search", ex);
    }
}
Also used : SimpleUser(org.gluu.ldap.model.SimpleUser) CustomAttribute(org.gluu.persist.model.base.CustomAttribute) SimpleAttribute(org.gluu.ldap.model.SimpleAttribute) SimpleGrant(org.gluu.ldap.model.SimpleGrant) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) Filter(org.gluu.search.filter.Filter) SimpleSession(org.gluu.ldap.model.SimpleSession)

Aggregations

SimpleAttribute (org.gluu.ldap.model.SimpleAttribute)1 SimpleGrant (org.gluu.ldap.model.SimpleGrant)1 SimpleSession (org.gluu.ldap.model.SimpleSession)1 SimpleUser (org.gluu.ldap.model.SimpleUser)1 LdapEntryManager (org.gluu.persist.ldap.impl.LdapEntryManager)1 CustomAttribute (org.gluu.persist.model.base.CustomAttribute)1 Filter (org.gluu.search.filter.Filter)1