|
|
|
@ -17,9 +17,6 @@ package org.springframework.security.config.ldap; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.net.ServerSocket; |
|
|
|
import java.net.ServerSocket; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
@ -78,16 +75,6 @@ public class LdapServerBeanDefinitionParser implements BeanDefinitionParser { |
|
|
|
private static final String APACHEDS_CONTAINER_CLASSNAME = "org.springframework.security.ldap.server.ApacheDSContainer"; |
|
|
|
private static final String APACHEDS_CONTAINER_CLASSNAME = "org.springframework.security.ldap.server.ApacheDSContainer"; |
|
|
|
private static final String UNBOUNDID_CONTAINER_CLASSNAME = "org.springframework.security.ldap.server.UnboundIdContainer"; |
|
|
|
private static final String UNBOUNDID_CONTAINER_CLASSNAME = "org.springframework.security.ldap.server.UnboundIdContainer"; |
|
|
|
|
|
|
|
|
|
|
|
private Map<String, EmbeddedLdapServer> embeddedServers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public LdapServerBeanDefinitionParser() { |
|
|
|
|
|
|
|
Map<String, EmbeddedLdapServer> embeddedLdapServers = new HashMap<>(); |
|
|
|
|
|
|
|
embeddedLdapServers.put("apacheds", new EmbeddedLdapServer(BeanIds.EMBEDDED_APACHE_DS, APACHEDS_CLASSNAME, APACHEDS_CONTAINER_CLASSNAME)); |
|
|
|
|
|
|
|
embeddedLdapServers.put("unboundid", new EmbeddedLdapServer(BeanIds.EMBEDDED_UNBOUNDID, UNBOUNID_CLASSNAME, UNBOUNDID_CONTAINER_CLASSNAME)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.embeddedServers = Collections.unmodifiableMap(embeddedLdapServers); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BeanDefinition parse(Element elt, ParserContext parserContext) { |
|
|
|
public BeanDefinition parse(Element elt, ParserContext parserContext) { |
|
|
|
String url = elt.getAttribute(ATT_URL); |
|
|
|
String url = elt.getAttribute(ATT_URL); |
|
|
|
|
|
|
|
|
|
|
|
@ -189,53 +176,40 @@ public class LdapServerBeanDefinitionParser implements BeanDefinitionParser { |
|
|
|
element); |
|
|
|
element); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EmbeddedLdapServer embeddedLdapServer = resolveEmbeddedLdapServer(mode); |
|
|
|
String beanId = resolveBeanId(mode); |
|
|
|
if (embeddedLdapServer != null) { |
|
|
|
if (beanId != null) { |
|
|
|
parserContext.getRegistry().registerBeanDefinition(embeddedLdapServer.getBeanId(), |
|
|
|
parserContext.getRegistry().registerBeanDefinition(beanId, ldapContainer); |
|
|
|
ldapContainer); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return (RootBeanDefinition) contextSource.getBeanDefinition(); |
|
|
|
return (RootBeanDefinition) contextSource.getBeanDefinition(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private RootBeanDefinition getRootBeanDefinition(String mode) { |
|
|
|
private RootBeanDefinition getRootBeanDefinition(String mode) { |
|
|
|
if (StringUtils.hasLength(mode)) { |
|
|
|
if (isApacheDsEnabled(mode)) { |
|
|
|
if (isEmbeddedServerEnabled(mode)) { |
|
|
|
return new RootBeanDefinition(APACHEDS_CONTAINER_CLASSNAME, null, null); |
|
|
|
return new RootBeanDefinition(this.embeddedServers.get(mode).getContainerClass(), null, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
for (Map.Entry<String, EmbeddedLdapServer> entry : this.embeddedServers.entrySet()) { |
|
|
|
|
|
|
|
EmbeddedLdapServer ldapServer = entry.getValue(); |
|
|
|
|
|
|
|
if (ClassUtils.isPresent(ldapServer.getClassName(), getClass().getClassLoader())) { |
|
|
|
|
|
|
|
return new RootBeanDefinition(ldapServer.getContainerClass(), null, null); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (isUnboundidEnabled(mode)) { |
|
|
|
|
|
|
|
return new RootBeanDefinition(UNBOUNDID_CONTAINER_CLASSNAME, null, null); |
|
|
|
} |
|
|
|
} |
|
|
|
throw new IllegalStateException("Embedded LDAP server is not provided"); |
|
|
|
throw new IllegalStateException("Embedded LDAP server is not provided"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private boolean isEmbeddedServerEnabled(String mode) { |
|
|
|
private String resolveBeanId(String mode) { |
|
|
|
EmbeddedLdapServer server = resolveEmbeddedLdapServer(mode); |
|
|
|
if (isApacheDsEnabled(mode)) { |
|
|
|
return server != null; |
|
|
|
return BeanIds.EMBEDDED_APACHE_DS; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private EmbeddedLdapServer resolveEmbeddedLdapServer(String mode) { |
|
|
|
|
|
|
|
if (StringUtils.hasLength(mode)) { |
|
|
|
|
|
|
|
if (this.embeddedServers.containsKey(mode) || |
|
|
|
|
|
|
|
ClassUtils.isPresent(this.embeddedServers.get(mode).getClassName(), getClass().getClassLoader())) { |
|
|
|
|
|
|
|
return this.embeddedServers.get(mode); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (isUnboundidEnabled(mode)) { |
|
|
|
|
|
|
|
return BeanIds.EMBEDDED_UNBOUNDID; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
return null; |
|
|
|
for (Map.Entry<String, EmbeddedLdapServer> entry : this.embeddedServers.entrySet()) { |
|
|
|
|
|
|
|
EmbeddedLdapServer ldapServer = entry.getValue(); |
|
|
|
|
|
|
|
if (ClassUtils.isPresent(ldapServer.getClassName(), getClass().getClassLoader())) { |
|
|
|
|
|
|
|
return ldapServer; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isApacheDsEnabled(String mode) { |
|
|
|
|
|
|
|
return "apacheds".equals(mode) || ClassUtils.isPresent(APACHEDS_CLASSNAME, getClass().getClassLoader()); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
private boolean isUnboundidEnabled(String mode) { |
|
|
|
|
|
|
|
return "unboundid".equals(mode) || ClassUtils.isPresent(UNBOUNID_CLASSNAME, getClass().getClassLoader()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getDefaultPort() { |
|
|
|
private String getDefaultPort() { |
|
|
|
@ -265,30 +239,4 @@ public class LdapServerBeanDefinitionParser implements BeanDefinitionParser { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private class EmbeddedLdapServer { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String beanId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String className; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String containerClass; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public EmbeddedLdapServer(String beanId, String className, String containerClass) { |
|
|
|
|
|
|
|
this.beanId = beanId; |
|
|
|
|
|
|
|
this.className = className; |
|
|
|
|
|
|
|
this.containerClass = containerClass; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getBeanId() { |
|
|
|
|
|
|
|
return this.beanId; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getClassName() { |
|
|
|
|
|
|
|
return this.className; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getContainerClass() { |
|
|
|
|
|
|
|
return this.containerClass; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|