Skip to content
Snippets Groups Projects
Commit 30211c30 authored by Teodor Caras's avatar Teodor Caras
Browse files

[Misc] Initialize the LDAP configuration with the SSL settings coming from the...

[Misc] Initialize the LDAP configuration with the SSL settings coming from the Active Directory application
parent 9b61bf07
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
*/ */
package com.xwiki.ldapuserimport.internal; package com.xwiki.ldapuserimport.internal;
import java.util.Arrays;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Provider; import javax.inject.Provider;
...@@ -31,7 +33,14 @@ import org.xwiki.component.manager.ComponentLookupException; ...@@ -31,7 +33,14 @@ import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager; import org.xwiki.component.manager.ComponentManager;
import org.xwiki.configuration.ConfigurationSource; import org.xwiki.configuration.ConfigurationSource;
import org.xwiki.contrib.ldap.XWikiLDAPConfig; import org.xwiki.contrib.ldap.XWikiLDAPConfig;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.model.reference.SpaceReference;
import com.xpn.xwiki.XWiki;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.XWikiException;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.BaseObject;
import com.xwiki.ldapuserimport.LDAPUserImportConfiguration; import com.xwiki.ldapuserimport.LDAPUserImportConfiguration;
/** /**
...@@ -56,6 +65,18 @@ public class XWikiLDAPConfigProvider implements Provider<XWikiLDAPConfig> ...@@ -56,6 +65,18 @@ public class XWikiLDAPConfigProvider implements Provider<XWikiLDAPConfig>
private static final String DEFAULT_LDAP_FIELDS_MAPPING = "first_name=givenName,last_name=sn,email=mail"; private static final String DEFAULT_LDAP_FIELDS_MAPPING = "first_name=givenName,last_name=sn,email=mail";
private static final String LDAP_SSL = "ldap_ssl";
private static final String LDAP_SSL_KEYSTORE = "ldap_ssl.keystore";
private static final String LDAP_SSL_SECURE_PROVIDER = "ldap_ssl.secure_provider";
private static final SpaceReference AD_CODE_SPACE_REFERENCE =
new SpaceReference("xwiki", Arrays.asList("ActiveDirectory", "Code"));
@Inject
private Provider<XWikiContext> contextProvider;
@Inject @Inject
private ConfigurationSource configurationSource; private ConfigurationSource configurationSource;
...@@ -75,9 +96,34 @@ public class XWikiLDAPConfigProvider implements Provider<XWikiLDAPConfig> ...@@ -75,9 +96,34 @@ public class XWikiLDAPConfigProvider implements Provider<XWikiLDAPConfig>
XWikiLDAPConfig configuration = new XWikiLDAPConfig(null, getConfigurationSource()); XWikiLDAPConfig configuration = new XWikiLDAPConfig(null, getConfigurationSource());
setPageNameFormatter(configuration); setPageNameFormatter(configuration);
setFieldMapping(configuration); setFieldMapping(configuration);
try {
setSSLProperties(configuration);
} catch (XWikiException e) {
logger.warn("Could not retrieve the SSL related configuration of the Active Directory application.");
}
return configuration; return configuration;
} }
private void setSSLProperties(XWikiLDAPConfig configuration) throws XWikiException
{
DocumentReference adConfigClassRef =
new DocumentReference("ActiveDirectoryConfigClass", AD_CODE_SPACE_REFERENCE);
DocumentReference adConfigRef = new DocumentReference("ActiveDirectoryConfig", AD_CODE_SPACE_REFERENCE);
XWikiContext context = this.contextProvider.get();
XWiki xwiki = context.getWiki();
XWikiDocument adConfigDoc = xwiki.getDocument(adConfigRef, context);
BaseObject adConfigObj = adConfigDoc.getXObject(adConfigClassRef);
if (adConfigObj != null) {
configuration.setFinalProperty(LDAP_SSL, adConfigObj.getStringValue(LDAP_SSL));
configuration.setFinalProperty(LDAP_SSL_KEYSTORE, adConfigObj.getStringValue(LDAP_SSL_KEYSTORE));
String provider = adConfigObj.getStringValue(LDAP_SSL_SECURE_PROVIDER);
configuration.setFinalProperty(LDAP_SSL_SECURE_PROVIDER,
StringUtils.isNoneBlank(provider) ? provider : null);
}
}
private ConfigurationSource getConfigurationSource() private ConfigurationSource getConfigurationSource()
{ {
if (componentManagerProvider.get().hasComponent(ConfigurationSource.class, ACTIVE_DIRECTORY_HINT)) { if (componentManagerProvider.get().hasComponent(ConfigurationSource.class, ACTIVE_DIRECTORY_HINT)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.