Search in sources :

Example 21 with LdapEntryManager

use of org.gluu.site.ldap.persistence.LdapEntryManager 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 {
        VirtualListViewResponse virtualListViewResponse = new VirtualListViewResponse();
        SearchResult searchResult = ldapEntryManager.getLdapOperationService().searchSearchResult("o=gluu", Filter.createEqualityFilter("objectClass", "gluuPerson"), SearchScope.SUB, 10, 100, 100000, "displayName", null, virtualListViewResponse, "uid", "displayName", "gluuStatus");
        log.debug("Found persons: " + virtualListViewResponse.getTotalResults());
        System.out.println(searchResult.getSearchEntries());
    } catch (Exception ex) {
        log.error("Failed to search", ex);
    }
}
Also used : CustomAttribute(org.xdi.ldap.model.CustomAttribute) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) SearchResult(com.unboundid.ldap.sdk.SearchResult) LdapEntryManager(org.gluu.site.ldap.persistence.LdapEntryManager) Filter(com.unboundid.ldap.sdk.Filter)

Example 22 with LdapEntryManager

use of org.gluu.site.ldap.persistence.LdapEntryManager in project oxCore by GluuFederation.

the class LdapSampleEntryManager method createLdapEntryManager.

public LdapEntryManager createLdapEntryManager() {
    Properties connectionProperties = getSampleConnectionProperties();
    LDAPConnectionProvider connectionProvider = createConnectionProvider(connectionProperties);
    Properties bindConnectionProperties = prepareBindConnectionProperties(connectionProperties);
    LDAPConnectionProvider bindConnectionProvider = createBindConnectionProvider(bindConnectionProperties, connectionProperties);
    LdapEntryManager ldapEntryManager = new LdapEntryManager(new OperationsFacade(connectionProvider, bindConnectionProvider));
    log.debug("Created LdapEntryManager: " + ldapEntryManager);
    return ldapEntryManager;
}
Also used : LdapEntryManager(org.gluu.site.ldap.persistence.LdapEntryManager) OperationsFacade(org.gluu.site.ldap.OperationsFacade) Properties(java.util.Properties) LDAPConnectionProvider(org.gluu.site.ldap.LDAPConnectionProvider)

Example 23 with LdapEntryManager

use of org.gluu.site.ldap.persistence.LdapEntryManager in project oxAuth by GluuFederation.

the class LdapStatusTimer method processInt.

private void processInt() {
    logConnectionProviderStatistic(ldapEntryManager, "connectionProvider", "bindConnectionProvider");
    for (int i = 0; i < ldapAuthEntryManagers.size(); i++) {
        LdapEntryManager ldapAuthEntryManager = ldapAuthEntryManagers.get(i);
        logConnectionProviderStatistic(ldapAuthEntryManager, "authConnectionProvider#" + i, "bindAuthConnectionProvider#" + i);
    }
}
Also used : LdapEntryManager(org.gluu.site.ldap.persistence.LdapEntryManager)

Example 24 with LdapEntryManager

use of org.gluu.site.ldap.persistence.LdapEntryManager in project oxTrust by GluuFederation.

the class ConfigurationFactory method loadConfigurationFromLdap.

private LdapOxTrustConfiguration loadConfigurationFromLdap(String... returnAttributes) {
    final LdapEntryManager ldapEntryManager = ldapEntryManagerInstance.get();
    final String configurationDn = getConfigurationDn();
    try {
        final LdapOxTrustConfiguration conf = ldapEntryManager.find(LdapOxTrustConfiguration.class, configurationDn, returnAttributes);
        return conf;
    } catch (LdapMappingException ex) {
        log.error("Failed to load configuration from LDAP", ex);
    }
    return null;
}
Also used : LdapOxTrustConfiguration(org.xdi.config.oxtrust.LdapOxTrustConfiguration) LdapEntryManager(org.gluu.site.ldap.persistence.LdapEntryManager) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException)

Example 25 with LdapEntryManager

use of org.gluu.site.ldap.persistence.LdapEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method updateTargetEntriesViaVDS.

private List<String> updateTargetEntriesViaVDS(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection targetServerConnection, Set<String> changedInums) {
    List<String> result = new ArrayList<String>();
    LdapEntryManager targetLdapEntryManager = targetServerConnection.getLdapEntryManager();
    Filter filter = cacheRefreshService.createObjectClassPresenceFilter();
    for (String changedInum : changedInums) {
        String baseDn = "action=synchronizecache," + personService.getDnForPerson(changedInum);
        try {
            targetLdapEntryManager.findEntries(baseDn, GluuDummyEntry.class, filter, null, cacheRefreshConfiguration.getLdapSearchSizeLimit());
            result.add(changedInum);
            log.debug("Updated entry with inum {}", changedInum);
        } catch (LdapMappingException ex) {
            log.error("Failed to update entry with inum '{}' using baseDN {}", ex, changedInum, baseDn);
        }
    }
    return result;
}
Also used : LdapEntryManager(org.gluu.site.ldap.persistence.LdapEntryManager) Filter(com.unboundid.ldap.sdk.Filter) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) ArrayList(java.util.ArrayList)

Aggregations

LdapEntryManager (org.gluu.site.ldap.persistence.LdapEntryManager)33 OperationsFacade (org.gluu.site.ldap.OperationsFacade)8 Filter (com.unboundid.ldap.sdk.Filter)6 ArrayList (java.util.ArrayList)6 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)5 ApplicationScoped (javax.enterprise.context.ApplicationScoped)4 Produces (javax.enterprise.inject.Produces)4 Named (javax.inject.Named)4 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)4 GluuLdapConfiguration (org.xdi.model.ldap.GluuLdapConfiguration)4 Properties (java.util.Properties)3 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)3 LDAPConnectionProvider (org.gluu.site.ldap.LDAPConnectionProvider)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 CacheCompoundKey (org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)2 CustomAttribute (org.xdi.ldap.model.CustomAttribute)2