71 changed files with 112 additions and 230 deletions
@ -1,71 +0,0 @@ |
|||||||
package org.springframework.security.config; |
|
||||||
|
|
||||||
import org.springframework.beans.BeansException; |
|
||||||
import org.springframework.beans.factory.config.BeanDefinition; |
|
||||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor; |
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
|
||||||
import org.springframework.beans.factory.support.RootBeanDefinition; |
|
||||||
import org.springframework.core.Ordered; |
|
||||||
import org.springframework.ldap.core.support.BaseLdapPathContextSource; |
|
||||||
|
|
||||||
/** |
|
||||||
* @author Luke Taylor |
|
||||||
* @version $Id$ |
|
||||||
* @since 2.0 |
|
||||||
*/ |
|
||||||
class LdapConfigUtils { |
|
||||||
|
|
||||||
/** |
|
||||||
* Checks for the presence of a ContextSource instance. Also supplies the standard reference to any |
|
||||||
* unconfigured <ldap-authentication-provider> or <ldap-user-service> beans. This is |
|
||||||
* necessary in cases where the user has given the server a specific Id, but hasn't used |
|
||||||
* the server-ref attribute to link this to the other ldap definitions. See SEC-799. |
|
||||||
*/ |
|
||||||
private static class ContextSourceSettingPostProcessor implements BeanFactoryPostProcessor, Ordered { |
|
||||||
/** If set to true, a bean parser has indicated that the default context source name needs to be set */ |
|
||||||
private boolean defaultNameRequired; |
|
||||||
|
|
||||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory bf) throws BeansException { |
|
||||||
String[] sources = bf.getBeanNamesForType(BaseLdapPathContextSource.class); |
|
||||||
|
|
||||||
if (sources.length == 0) { |
|
||||||
throw new SecurityConfigurationException("No BaseLdapPathContextSource instances found. Have you " + |
|
||||||
"added an <" + Elements.LDAP_SERVER + " /> element to your application context?"); |
|
||||||
} |
|
||||||
|
|
||||||
if (!bf.containsBean(BeanIds.CONTEXT_SOURCE) && defaultNameRequired) { |
|
||||||
if (sources.length > 1) { |
|
||||||
throw new SecurityConfigurationException("More than one BaseLdapPathContextSource instance found. " + |
|
||||||
"Please specify a specific server id using the 'server-ref' attribute when configuring your <" + |
|
||||||
Elements.LDAP_PROVIDER + "> " + "or <" + Elements.LDAP_USER_SERVICE + ">."); |
|
||||||
} |
|
||||||
|
|
||||||
bf.registerAlias(sources[0], BeanIds.CONTEXT_SOURCE); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public void setDefaultNameRequired(boolean defaultNameRequired) { |
|
||||||
this.defaultNameRequired = defaultNameRequired; |
|
||||||
} |
|
||||||
|
|
||||||
public int getOrder() { |
|
||||||
return LOWEST_PRECEDENCE; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
static void registerPostProcessorIfNecessary(BeanDefinitionRegistry registry, boolean defaultNameRequired) { |
|
||||||
if (registry.containsBeanDefinition(BeanIds.CONTEXT_SOURCE_SETTING_POST_PROCESSOR)) { |
|
||||||
if (defaultNameRequired) { |
|
||||||
BeanDefinition bd = registry.getBeanDefinition(BeanIds.CONTEXT_SOURCE_SETTING_POST_PROCESSOR); |
|
||||||
bd.getPropertyValues().addPropertyValue("defaultNameRequired", Boolean.valueOf(defaultNameRequired)); |
|
||||||
} |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
BeanDefinition bd = new RootBeanDefinition(ContextSourceSettingPostProcessor.class); |
|
||||||
registry.registerBeanDefinition(BeanIds.CONTEXT_SOURCE_SETTING_POST_PROCESSOR, bd); |
|
||||||
bd.getPropertyValues().addPropertyValue("defaultNameRequired", Boolean.valueOf(defaultNameRequired)); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,35 +0,0 @@ |
|||||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.security.ldap; |
|
||||||
|
|
||||||
import javax.naming.NamingException; |
|
||||||
import javax.naming.directory.DirContext; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Callback object for use with SpringSecurityLdapTemplate. |
|
||||||
* |
|
||||||
* @deprecated use spring-ldap ContextExecutor instead. |
|
||||||
* @TODO: Delete before 2.0 release |
|
||||||
* |
|
||||||
* @author Ben Alex |
|
||||||
*/ |
|
||||||
public interface LdapCallback { |
|
||||||
//~ Methods ========================================================================================================
|
|
||||||
|
|
||||||
Object doInDirContext(DirContext dirContext) |
|
||||||
throws NamingException; |
|
||||||
} |
|
||||||
@ -1,35 +0,0 @@ |
|||||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited |
|
||||||
* |
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
||||||
* you may not use this file except in compliance with the License. |
|
||||||
* You may obtain a copy of the License at |
|
||||||
* |
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
* |
|
||||||
* Unless required by applicable law or agreed to in writing, software |
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, |
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
||||||
* See the License for the specific language governing permissions and |
|
||||||
* limitations under the License. |
|
||||||
*/ |
|
||||||
|
|
||||||
package org.springframework.security.ldap; |
|
||||||
|
|
||||||
import javax.naming.NamingException; |
|
||||||
import javax.naming.directory.Attributes; |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* A mapper for use with {@link SpringSecurityLdapTemplate}. Creates a customized object from |
|
||||||
* a set of attributes retrieved from a directory entry. |
|
||||||
* |
|
||||||
* @author Luke Taylor |
|
||||||
* @deprecated in favour of Spring LDAP ContextMapper |
|
||||||
* @version $Id$ |
|
||||||
*/ |
|
||||||
public interface LdapEntryMapper { |
|
||||||
//~ Methods ========================================================================================================
|
|
||||||
|
|
||||||
Object mapAttributes(String dn, Attributes attributes) |
|
||||||
throws NamingException; |
|
||||||
} |
|
||||||
@ -1,8 +1,9 @@ |
|||||||
package org.springframework.security.config; |
package org.springframework.security; |
||||||
|
|
||||||
import org.junit.After; |
import org.junit.After; |
||||||
import org.junit.Test; |
import org.junit.Test; |
||||||
import org.springframework.ldap.core.LdapTemplate; |
import org.springframework.ldap.core.LdapTemplate; |
||||||
|
import org.springframework.security.config.BeanIds; |
||||||
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; |
import org.springframework.security.ldap.DefaultSpringSecurityContextSource; |
||||||
import org.springframework.security.util.InMemoryXmlApplicationContext; |
import org.springframework.security.util.InMemoryXmlApplicationContext; |
||||||
|
|
||||||
@ -1,4 +1,4 @@ |
|||||||
package org.springframework.security.config; |
package org.springframework.security; |
||||||
|
|
||||||
import java.util.Set; |
import java.util.Set; |
||||||
|
|
||||||
@ -1,28 +1,32 @@ |
|||||||
package org.springframework.security.ldap.populator; |
package org.springframework.security.ldap.populator; |
||||||
|
|
||||||
import java.util.List; |
import static org.junit.Assert.assertEquals; |
||||||
|
import static org.mockito.Mockito.*; |
||||||
import org.springframework.security.userdetails.UserDetailsService; |
|
||||||
import org.springframework.security.userdetails.MockUserDetailsService; |
|
||||||
import org.springframework.security.GrantedAuthority; |
|
||||||
|
|
||||||
import org.springframework.ldap.core.DirContextAdapter; |
import java.util.List; |
||||||
|
|
||||||
import org.junit.Test; |
import org.junit.Test; |
||||||
import static org.junit.Assert.*; |
import org.springframework.ldap.core.DirContextAdapter; |
||||||
|
import org.springframework.security.GrantedAuthority; |
||||||
|
import org.springframework.security.userdetails.UserDetails; |
||||||
|
import org.springframework.security.userdetails.UserDetailsService; |
||||||
|
import org.springframework.security.util.AuthorityUtils; |
||||||
|
|
||||||
/** |
/** |
||||||
* @author Luke Taylor |
* @author Luke Taylor |
||||||
* @version $Id$ |
* @version $Id$ |
||||||
*/ |
*/ |
||||||
public class UserDetailsServiceLdapAuthoritiesPopulatorTests { |
public class UserDetailsServiceLdapAuthoritiesPopulatorTests { |
||||||
UserDetailsService uds = new MockUserDetailsService(); |
|
||||||
|
|
||||||
@Test |
@Test |
||||||
public void delegationToUserDetailsServiceReturnsCorrectRoles() throws Exception { |
public void delegationToUserDetailsServiceReturnsCorrectRoles() throws Exception { |
||||||
UserDetailsServiceLdapAuthoritiesPopulator populator = new UserDetailsServiceLdapAuthoritiesPopulator(uds); |
UserDetailsService uds = mock(UserDetailsService.class); |
||||||
|
UserDetails user = mock(UserDetails.class); |
||||||
|
when(uds.loadUserByUsername("joe")).thenReturn(user); |
||||||
|
when(user.getAuthorities()).thenReturn(AuthorityUtils.createAuthorityList("ROLE_USER")); |
||||||
|
|
||||||
List<GrantedAuthority> auths = populator.getGrantedAuthorities(new DirContextAdapter(), "valid"); |
UserDetailsServiceLdapAuthoritiesPopulator populator = new UserDetailsServiceLdapAuthoritiesPopulator(uds); |
||||||
|
List<GrantedAuthority> auths = populator.getGrantedAuthorities(new DirContextAdapter(), "joe"); |
||||||
|
|
||||||
assertEquals(1, auths.size()); |
assertEquals(1, auths.size()); |
||||||
assertEquals("ROLE_USER", auths.get(0).getAuthority()); |
assertEquals("ROLE_USER", auths.get(0).getAuthority()); |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
# Logging |
||||||
|
# |
||||||
|
# $Id: log4j.properties 3455 2008-12-11 17:00:13Z ltaylor $ |
||||||
|
|
||||||
|
log4j.rootLogger=INFO, stdout |
||||||
|
|
||||||
|
log4j.appender.stdout=org.apache.log4j.ConsoleAppender |
||||||
|
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout |
||||||
|
log4j.appender.stdout.layout.ConversionPattern=%p %c{1} - %m%n |
||||||
|
|
||||||
|
log4j.logger.org.springframework.security=DEBUG |
||||||
|
log4j.logger.org.springframework.ldap=DEBUG |
||||||
|
|
||||||
|
log4j.logger.org.apache.directory=ERROR |
||||||
Loading…
Reference in new issue