use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxCore by GluuFederation.
the class LdapSampleBatchJob method main.
public static void main(String[] args) {
// Prepare sample connection details
LdapSampleEntryManager ldapSampleEntryManager = new LdapSampleEntryManager();
// Create LDAP entry manager
final LdapEntryManager ldapEntryManager = ldapSampleEntryManager.createLdapEntryManager();
BatchOperation<SimpleTokenLdap> tokenLdapBatchOperation = new ProcessBatchOperation<SimpleTokenLdap>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleTokenLdap> objects) {
for (SimpleTokenLdap simpleTokenLdap : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, "oxAuthExpiration", simpleTokenLdap.getAttribute("oxAuthExpiration"));
simpleTokenLdap.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
ldapEntryManager.merge(simpleTokenLdap);
processedCount++;
} catch (EntryPersistenceException ex) {
LOG.error("Failed to update entry", ex);
}
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter1 = Filter.createPresenceFilter("oxAuthExpiration");
ldapEntryManager.findEntries("o=gluu", SimpleTokenLdap.class, filter1, SearchScope.SUB, new String[] { "oxAuthExpiration" }, tokenLdapBatchOperation, 0, 0, 100);
BatchOperation<SimpleSession> sessionBatchOperation = new ProcessBatchOperation<SimpleSession>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleSession> objects) {
for (SimpleSession simpleSession : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute(ldapEntryManager, "oxLastAccessTime", simpleSession.getAttribute("oxLastAccessTime"));
simpleSession.setCustomAttributes(Arrays.asList(new CustomAttribute[] { customAttribute }));
ldapEntryManager.merge(simpleSession);
processedCount++;
} catch (EntryPersistenceException ex) {
LOG.error("Failed to update entry", ex);
}
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter2 = Filter.createPresenceFilter("oxLastAccessTime");
ldapEntryManager.findEntries("o=gluu", SimpleSession.class, filter2, SearchScope.SUB, new String[] { "oxLastAccessTime" }, sessionBatchOperation, 0, 0, 100);
BatchOperation<SimpleClient> clientBatchOperation = new ProcessBatchOperation<SimpleClient>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleClient> objects) {
for (SimpleClient simpleClient : objects) {
processedCount++;
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter3 = Filter.createPresenceFilter("oxAuthClientSecretExpiresAt");
List<SimpleClient> result3 = ldapEntryManager.findEntries("o=gluu", SimpleClient.class, filter3, SearchScope.SUB, new String[] { "oxAuthClientSecretExpiresAt" }, clientBatchOperation, 0, 0, 1000);
LOG.info("Result count (without collecting results): " + result3.size());
BatchOperation<SimpleClient> clientBatchOperation2 = new DefaultBatchOperation<SimpleClient>() {
private int processedCount = 0;
@Override
public void performAction(List<SimpleClient> objects) {
for (SimpleClient simpleClient : objects) {
processedCount++;
}
LOG.info("Total processed: " + processedCount);
}
};
final Filter filter4 = Filter.createPresenceFilter("oxAuthClientSecretExpiresAt");
List<SimpleClient> result4 = ldapEntryManager.findEntries("o=gluu", SimpleClient.class, filter4, SearchScope.SUB, new String[] { "oxAuthClientSecretExpiresAt" }, clientBatchOperation2, 0, 0, 1000);
LOG.info("Result count (with collecting results): " + result4.size());
}
use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxCore by GluuFederation.
the class LdapSampleSimpleSessionSample method main.
public static void main(String[] args) throws InterruptedException {
// Prepare sample connection details
LdapSampleEntryManager ldapSampleEntryManager = new LdapSampleEntryManager();
final LdapEntryManager ldapEntryManager = ldapSampleEntryManager.createLdapEntryManager();
try {
// Create LDAP entry manager
String sessionId = "xyzcyzxy-a41a-45ad-8a83-61485dbad561";
final String sessionDn = "uniqueIdentifier=" + sessionId + ",ou=session,o=@!E8F2.853B.1E7B.ACE2!0001!39A4.C163,o=gluu";
final String userDn = "inum=@!E8F2.853B.1E7B.ACE2!0001!39A4.C163!0000!A8F2.DE1E.D7FB,ou=people,o=@!E8F2.853B.1E7B.ACE2!0001!39A4.C163,o=gluu";
final SimpleSessionState simpleSessionState = new SimpleSessionState();
simpleSessionState.setDn(sessionDn);
simpleSessionState.setId(sessionId);
simpleSessionState.setLastUsedAt(new Date());
ldapEntryManager.persist(simpleSessionState);
System.out.println("Persisted");
int threadCount = 500;
ExecutorService executorService = Executors.newFixedThreadPool(threadCount, daemonThreadFactory());
for (int i = 0; i < threadCount; i++) {
final int count = i;
executorService.execute(new Runnable() {
@Override
public void run() {
final SimpleSessionState simpleSessionStateFromLdap = ldapEntryManager.find(SimpleSessionState.class, sessionDn);
String beforeUserDn = simpleSessionStateFromLdap.getUserDn();
String randomUserDn = count % 2 == 0 ? userDn : "";
try {
simpleSessionStateFromLdap.setUserDn(randomUserDn);
simpleSessionStateFromLdap.setLastUsedAt(new Date());
ldapEntryManager.merge(simpleSessionStateFromLdap);
System.out.println("Merged thread: " + count + ", userDn: " + randomUserDn + ", before userDn: " + beforeUserDn);
} catch (Throwable e) {
System.out.println("ERROR !!!, thread: " + count + ", userDn: " + randomUserDn + ", before userDn: " + beforeUserDn + ", error:" + e.getMessage());
// e.printStackTrace();
}
}
});
}
Thread.sleep(5000L);
} finally {
ldapEntryManager.getOperationService().getConnectionPool().close();
}
}
use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxTrust by GluuFederation.
the class ConfigurationFactory method loadConfigurationFromLdap.
public 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 (BaseMappingException ex) {
log.error("Failed to load configuration from LDAP", ex);
}
return null;
}
use of org.gluu.persist.ldap.impl.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, SearchScope.SUB, null, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
result.add(changedInum);
log.debug("Updated entry with inum {}", changedInum);
} catch (BaseMappingException ex) {
log.error("Failed to update entry with inum '{}' using baseDN {}", changedInum, baseDn, ex);
}
}
return result;
}
use of org.gluu.persist.ldap.impl.LdapEntryManager in project oxTrust by GluuFederation.
the class CacheRefreshTimer method loadSourceServerEntriesWithoutLimits.
private List<GluuSimplePerson> loadSourceServerEntriesWithoutLimits(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections) {
Filter customFilter = cacheRefreshService.createFilter(cacheRefreshConfiguration.getCustomLdapFilter());
String[] keyAttributes = getCompoundKeyAttributes(cacheRefreshConfiguration);
String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
String[] keyObjectClasses = getCompoundKeyObjectClasses(cacheRefreshConfiguration);
String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
Set<String> addedDns = new HashSet<String>();
List<GluuSimplePerson> sourcePersons = new ArrayList<GluuSimplePerson>();
for (LdapServerConnection sourceServerConnection : sourceServerConnections) {
String sourceServerName = sourceServerConnection.getSourceServerName();
LdapEntryManager sourceLdapEntryManager = sourceServerConnection.getLdapEntryManager();
String[] baseDns = sourceServerConnection.getBaseDns();
Filter filter = cacheRefreshService.createFilter(keyAttributes, keyObjectClasses, "", customFilter);
if (log.isTraceEnabled()) {
log.trace("Using next filter to load entris from source server: {}", filter);
}
for (String baseDn : baseDns) {
List<GluuSimplePerson> currentSourcePersons = sourceLdapEntryManager.findEntries(baseDn, GluuSimplePerson.class, filter, SearchScope.SUB, returnAttributes, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
// Add to result and ignore root entry if needed
for (GluuSimplePerson currentSourcePerson : currentSourcePersons) {
currentSourcePerson.setSourceServerName(sourceServerName);
// if (!StringHelper.equalsIgnoreCase(baseDn,
// currentSourcePerson.getDn())) {
String currentSourcePersonDn = currentSourcePerson.getDn().toLowerCase();
if (!addedDns.contains(currentSourcePersonDn)) {
sourcePersons.add(currentSourcePerson);
addedDns.add(currentSourcePersonDn);
}
// }
}
}
}
return sourcePersons;
}
Aggregations