Search in sources :

Example 16 with LdapEntryManager

use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method prepareLdapServerConnection.

private LdapServerConnection prepareLdapServerConnection(CacheRefreshConfiguration cacheRefreshConfiguration, GluuLdapConfiguration ldapConfiguration, boolean useLocalConnection) {
    String ldapConfig = ldapConfiguration.getConfigId();
    if (useLocalConnection) {
        return new LdapServerConnection(ldapConfig, ldapEntryManager, getBaseDNs(ldapConfiguration));
    }
    Properties ldapProperties = toLdapProperties(ldapConfiguration);
    Properties ldapDecryptedProperties = encryptionService.decryptProperties(ldapProperties);
    LdapEntryManager customLdapEntryManager = ldapEntryManagerFactory.createEntryManager(ldapDecryptedProperties);
    if (!customLdapEntryManager.getOperationService().getConnectionProvider().isConnected()) {
        log.error("Failed to connect to LDAP server using configuration {}", ldapConfig);
        return null;
    }
    return new LdapServerConnection(ldapConfig, customLdapEntryManager, getBaseDNs(ldapConfiguration));
}
Also used : LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) Properties(java.util.Properties)

Example 17 with LdapEntryManager

use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxTrust by GluuFederation.

the class AppInitializer method destroy.

public void destroy(@Observes @BeforeDestroyed(ApplicationScoped.class) ServletContext init) {
    log.info("Closing LDAP connection at server shutdown...");
    LdapEntryManager ldapEntryManager = ldapEntryManagerInstance.get();
    closeLdapEntryManager(ldapEntryManager);
    LdapEntryManager ldapCentralEntryManager = ldapCentralEntryManagerInstance.get();
    if (ldapCentralEntryManager != null) {
        closeLdapEntryManager(ldapCentralEntryManager);
    }
}
Also used : LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager)

Example 18 with LdapEntryManager

use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxTrust by GluuFederation.

the class AppInitializer method createCentralLdapEntryManager.

@Produces
@ApplicationScoped
@Named(LDAP_CENTRAL_ENTRY_MANAGER_NAME)
@CentralLdap
public LdapEntryManager createCentralLdapEntryManager() {
    if (!((configurationFactory.getLdapCentralConfiguration() != null) && configurationFactory.getAppConfiguration().isUpdateApplianceStatus())) {
        return new LdapEntryManager();
    }
    FileConfiguration ldapCentralConfig = configurationFactory.getLdapCentralConfiguration();
    Properties centralConnectionProperties = (Properties) ldapCentralConfig.getProperties();
    EncryptionService securityService = encryptionServiceInstance.get();
    Properties decryptedCentralConnectionProperties = securityService.decryptProperties(centralConnectionProperties);
    LdapEntryManager centralLdapEntryManager = this.ldapEntryManagerFactory.createEntryManager(decryptedCentralConnectionProperties);
    log.info("Created {}: {}", new Object[] { LDAP_CENTRAL_ENTRY_MANAGER_NAME, centralLdapEntryManager.getOperationService() });
    return centralLdapEntryManager;
}
Also used : FileConfiguration(org.xdi.util.properties.FileConfiguration) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) Properties(java.util.Properties) Named(javax.inject.Named) Produces(javax.enterprise.inject.Produces) CentralLdap(org.gluu.oxtrust.service.cdi.event.CentralLdap) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 19 with LdapEntryManager

use of org.gluu.persist.ldap.impl.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 {
        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)

Example 20 with LdapEntryManager

use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxCore by GluuFederation.

the class LdapSampleEntryManager method createLdapEntryManager.

public LdapEntryManager createLdapEntryManager() {
    LdapEntryManagerFactory ldapEntryManagerFactory = new LdapEntryManagerFactory();
    Properties connectionProperties = getSampleConnectionProperties();
    LdapEntryManager ldapEntryManager = ldapEntryManagerFactory.createEntryManager(connectionProperties);
    LOG.debug("Created LdapEntryManager: " + ldapEntryManager);
    return ldapEntryManager;
}
Also used : LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) Properties(java.util.Properties) LdapEntryManagerFactory(org.gluu.persist.ldap.impl.LdapEntryManagerFactory)

Aggregations

LdapEntryManager (org.gluu.persist.ldap.impl.LdapEntryManager)20 Filter (org.gluu.search.filter.Filter)6 Properties (java.util.Properties)5 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)5 ArrayList (java.util.ArrayList)4 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)3 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Produces (javax.enterprise.inject.Produces)2 Named (javax.inject.Named)2 SimpleSession (org.gluu.ldap.model.SimpleSession)2 CacheCompoundKey (org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)2 LdapEntryManagerFactory (org.gluu.persist.ldap.impl.LdapEntryManagerFactory)2 CustomAttribute (org.gluu.persist.model.base.CustomAttribute)2 FileConfiguration (org.xdi.util.properties.FileConfiguration)2 List (java.util.List)1