use of org.gluu.model.custom.script.model.bind.BindCredentials 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));
}
PersistenceEntryManagerFactory entryManagerFactory = applicationFactory.getPersistenceEntryManagerFactory(LdapEntryManagerFactory.class);
String persistenceType = entryManagerFactory.getPersistenceType();
Properties ldapProperties = toLdapProperties(entryManagerFactory, ldapConfiguration);
Properties ldapDecryptedProperties = encryptionService.decryptAllProperties(ldapProperties);
// Try to get updated password via script
BindCredentials bindCredentials = externalCacheRefreshService.executeExternalGetBindCredentialsMethods(ldapConfig);
String bindPasswordPropertyKey = persistenceType + "#" + PropertiesDecrypter.BIND_PASSWORD;
if (bindCredentials != null) {
log.error("Using updated password which got from getBindCredentials method");
ldapDecryptedProperties.setProperty(persistenceType + ".bindDN", bindCredentials.getBindDn());
ldapDecryptedProperties.setProperty(bindPasswordPropertyKey, bindCredentials.getBindPassword());
}
if (log.isTraceEnabled()) {
Properties clonedLdapDecryptedProperties = (Properties) ldapDecryptedProperties.clone();
if (clonedLdapDecryptedProperties.getProperty(bindPasswordPropertyKey) != null) {
clonedLdapDecryptedProperties.setProperty(bindPasswordPropertyKey, "REDACTED");
}
log.trace("Attempting to create PersistenceEntryManager with properties: {}", clonedLdapDecryptedProperties);
}
PersistenceEntryManager customPersistenceEntryManager = entryManagerFactory.createEntryManager(ldapDecryptedProperties);
log.info("Created Cache Refresh PersistenceEntryManager: {}", customPersistenceEntryManager);
if (!customPersistenceEntryManager.getOperationService().isConnected()) {
log.error("Failed to connect to LDAP server using configuration {}", ldapConfig);
return null;
}
return new LdapServerConnection(ldapConfig, customPersistenceEntryManager, getBaseDNs(ldapConfiguration));
}
Aggregations