SEC-658: Add support for ldap-user-service to AuthenticationProviderBeanDefinitionParser.

This commit is contained in:
Luke Taylor 2008-01-31 20:32:31 +00:00
parent 2c6fb3d1c9
commit ca75905c3e
3 changed files with 18 additions and 0 deletions

View File

@ -40,6 +40,7 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
String ref = element.getAttribute(ATT_USER_DETAILS_REF);
Element userServiceElt = DomUtils.getChildElementByTagName(element, Elements.USER_SERVICE);
Element jdbcUserServiceElt = DomUtils.getChildElementByTagName(element, Elements.JDBC_USER_SERVICE);
Element ldapUserServiceElt = DomUtils.getChildElementByTagName(element, Elements.LDAP_USER_SERVICE);
if (StringUtils.hasText(ref)) {
if (userServiceElt != null || jdbcUserServiceElt != null) {
@ -59,6 +60,8 @@ class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser
userDetailsService = new UserServiceBeanDefinitionParser().parse(userServiceElt, parserContext);
} else if (jdbcUserServiceElt != null) {
userDetailsService = new JdbcUserServiceBeanDefinitionParser().parse(jdbcUserServiceElt, parserContext);
} else if (ldapUserServiceElt != null) {
userDetailsService = new LdapUserServiceBeanDefinitionParser().parse(ldapUserServiceElt, parserContext);
} else {
throw new SecurityConfigurationException(Elements.AUTHENTICATION_PROVIDER
+ " requires a UserDetailsService" );

View File

@ -631,6 +631,7 @@
<xs:choice>
<xs:element ref="security:user-service"/>
<xs:element ref="security:jdbc-user-service"/>
<xs:element ref="security:ldap-user-service"/>
</xs:choice>
<xs:element ref="security:password-encoder"/>
</xs:choice>

View File

@ -71,6 +71,20 @@ public class AuthenticationProviderBeanDefinitionParserTests {
getProvider().authenticate(bob);
}
@Test
public void worksWithJdbcUserService() throws Exception {
setContext(" <authentication-provider>" +
" <password-encoder hash='{sha}'/>" +
" <user-service>" +
" <user name='bob' password='{SSHA}PpuEwfdj7M1rs0C2W4ssSM2XEN/Y6S5U' authorities='ROLE_A' />" +
" </user-service>" +
" </authentication-provider>");
getProvider().authenticate(bob);
}
@Test
public void externalUserServiceAndPasswordEncoderWork() throws Exception {
setContext(" <authentication-provider user-service-ref='customUserService'>" +