|
|
|
@ -1,6 +1,7 @@ |
|
|
|
package org.springframework.security.config; |
|
|
|
package org.springframework.security.config; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.security.userdetails.jdbc.JdbcUserDetailsManager; |
|
|
|
import org.springframework.security.userdetails.jdbc.JdbcUserDetailsManager; |
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
|
|
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
|
|
|
import org.springframework.beans.factory.xml.ParserContext; |
|
|
|
import org.springframework.beans.factory.xml.ParserContext; |
|
|
|
import org.springframework.beans.factory.BeanDefinitionStoreException; |
|
|
|
import org.springframework.beans.factory.BeanDefinitionStoreException; |
|
|
|
@ -13,6 +14,9 @@ import org.w3c.dom.Element; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class JdbcUserServiceBeanDefinitionParser extends AbstractUserDetailsServiceBeanDefinitionParser { |
|
|
|
public class JdbcUserServiceBeanDefinitionParser extends AbstractUserDetailsServiceBeanDefinitionParser { |
|
|
|
static final String ATT_DATA_SOURCE = "data-source-ref"; |
|
|
|
static final String ATT_DATA_SOURCE = "data-source-ref"; |
|
|
|
|
|
|
|
static final String ATT_USERS_BY_USERNAME_QUERY = "users-by-username-query"; |
|
|
|
|
|
|
|
static final String ATT_AUTHORITIES_BY_USERNAME_QUERY = "authorities-by-username-query"; |
|
|
|
|
|
|
|
static final String ATT_GROUP_AUTHORITIES_QUERY = "group-authorities-by-username-query"; |
|
|
|
|
|
|
|
|
|
|
|
protected Class getBeanClass(Element element) { |
|
|
|
protected Class getBeanClass(Element element) { |
|
|
|
return JdbcUserDetailsManager.class; |
|
|
|
return JdbcUserDetailsManager.class; |
|
|
|
@ -29,5 +33,22 @@ public class JdbcUserServiceBeanDefinitionParser extends AbstractUserDetailsServ |
|
|
|
throw new BeanDefinitionStoreException(ATT_DATA_SOURCE + " is required for " |
|
|
|
throw new BeanDefinitionStoreException(ATT_DATA_SOURCE + " is required for " |
|
|
|
+ Elements.JDBC_USER_SERVICE ); |
|
|
|
+ Elements.JDBC_USER_SERVICE ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String usersQuery = element.getAttribute(ATT_USERS_BY_USERNAME_QUERY); |
|
|
|
|
|
|
|
String authoritiesQuery = element.getAttribute(ATT_AUTHORITIES_BY_USERNAME_QUERY); |
|
|
|
|
|
|
|
String groupAuthoritiesQuery = element.getAttribute(ATT_GROUP_AUTHORITIES_QUERY); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.hasText(usersQuery)) { |
|
|
|
|
|
|
|
builder.addPropertyValue("usersByUsernameQuery", usersQuery); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.hasText(authoritiesQuery)) { |
|
|
|
|
|
|
|
builder.addPropertyValue("authoritiesByUsernameQuery", authoritiesQuery); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (StringUtils.hasText(groupAuthoritiesQuery)) { |
|
|
|
|
|
|
|
builder.addPropertyValue("enableGroups", Boolean.TRUE); |
|
|
|
|
|
|
|
builder.addPropertyValue("authoritiesByUsernameQuery", groupAuthoritiesQuery); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|