use of org.gluu.site.ldap.persistence.LdapEntryManager in project oxAuth by GluuFederation.
the class AppInitializer method recreateLdapAuthEntryManagers.
public void recreateLdapAuthEntryManagers(List<GluuLdapConfiguration> newLdapAuthConfigs) {
// Get existing application scoped instance
List<LdapEntryManager> oldLdapAuthEntryManagers = CdiUtil.getContextBean(beanManager, new ParameterizedTypeImpl(List.class, LdapEntryManager.class), LDAP_AUTH_ENTRY_MANAGER_NAME);
// Recreate components
createAuthConnectionProviders(newLdapAuthConfigs);
// Close existing connections
closeLdapAuthEntryManagers(oldLdapAuthEntryManagers);
// Destroy old Ldap auth entry managers
for (LdapEntryManager oldLdapAuthEntryManager : oldLdapAuthEntryManagers) {
log.debug("Attempting to destroy {}: {}", LDAP_AUTH_ENTRY_MANAGER_NAME, oldLdapAuthEntryManager);
oldLdapAuthEntryManager.destroy();
log.debug("Destroyed {}: {}", LDAP_AUTH_ENTRY_MANAGER_NAME, oldLdapAuthEntryManager);
}
// Force to create new bean
List<LdapEntryManager> ldapAuthEntryManagers = ldapAuthEntryManagerInstance.get();
ldapAuthEntryManagerInstance.destroy(ldapAuthEntryManagers);
log.info("Recreated instance {}: {}", LDAP_AUTH_ENTRY_MANAGER_NAME, ldapAuthEntryManagers);
}
use of org.gluu.site.ldap.persistence.LdapEntryManager in project oxAuth by GluuFederation.
the class AuthenticationService method externalAuthenticate.
private boolean externalAuthenticate(String keyValue, String password) {
for (int i = 0; i < this.ldapAuthConfigs.size(); i++) {
GluuLdapConfiguration ldapAuthConfig = this.ldapAuthConfigs.get(i);
LdapEntryManager ldapAuthEntryManager = this.ldapAuthEntryManagers.get(i);
String primaryKey = "uid";
if (StringHelper.isNotEmpty(ldapAuthConfig.getPrimaryKey())) {
primaryKey = ldapAuthConfig.getPrimaryKey();
}
String localPrimaryKey = "uid";
if (StringHelper.isNotEmpty(ldapAuthConfig.getLocalPrimaryKey())) {
localPrimaryKey = ldapAuthConfig.getLocalPrimaryKey();
}
boolean authenticated = authenticate(ldapAuthConfig, ldapAuthEntryManager, keyValue, password, primaryKey, localPrimaryKey);
if (authenticated) {
return authenticated;
}
}
return false;
}
use of org.gluu.site.ldap.persistence.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 BatchOperation<SimpleTokenLdap>(ldapEntryManager) {
private int processedCount = 0;
@Override
protected List<SimpleTokenLdap> getChunkOrNull(int batchSize) {
log.info("Processed: " + processedCount);
final Filter filter = Filter.createPresenceFilter("oxAuthExpiration");
return ldapEntryManager.findEntries("o=gluu", SimpleTokenLdap.class, filter, SearchScope.SUB, new String[] { "oxAuthExpiration" }, this, 0, batchSize, batchSize);
}
@Override
protected void performAction(List<SimpleTokenLdap> objects) {
for (SimpleTokenLdap simpleTokenLdap : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute("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);
}
}
}
};
tokenLdapBatchOperation.iterateAllByChunks(100);
BatchOperation<SimpleSession> sessionBatchOperation = new BatchOperation<SimpleSession>(ldapEntryManager) {
private int processedCount = 0;
@Override
protected List<SimpleSession> getChunkOrNull(int batchSize) {
log.info("Processed: " + processedCount);
final Filter filter = Filter.createPresenceFilter("oxLastAccessTime");
return ldapEntryManager.findEntries("o=gluu", SimpleSession.class, filter, SearchScope.SUB, new String[] { "oxLastAccessTime" }, this, 0, batchSize, batchSize);
}
@Override
protected void performAction(List<SimpleSession> objects) {
for (SimpleSession simpleSession : objects) {
try {
CustomAttribute customAttribute = getUpdatedAttribute("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);
}
}
}
};
sessionBatchOperation.iterateAllByChunks(100);
}
use of org.gluu.site.ldap.persistence.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.getLdapOperationService().getConnectionPool().close();
}
}
use of org.gluu.site.ldap.persistence.LdapEntryManager in project oxTrust by GluuFederation.
the class Configuration method createLdapEntryManager.
private LdapEntryManager createLdapEntryManager() {
Properties connectionProperties = (Properties) this.ldapConfiguration.getProperties();
Properties decryptedConnectionProperties = PropertiesDecrypter.decryptProperties(connectionProperties, this.cryptoConfigurationSalt);
LDAPConnectionProvider connectionProvider = new LDAPConnectionProvider(decryptedConnectionProperties);
LdapEntryManager ldapEntryManager = new LdapEntryManager(new OperationsFacade(connectionProvider, null));
logger.debug("Created LdapEntryManager: {}", ldapEntryManager);
return ldapEntryManager;
}
Aggregations