Skip to content

add cache-ref to authenticaiton-provider, add allow-empty-authorities to java-user-service #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
*/
public class AuthenticationProviderBeanDefinitionParser implements BeanDefinitionParser {
private static final String ATT_USER_DETAILS_REF = "user-service-ref";
private static final String CACHE_REF = "cache-ref";

public BeanDefinition parse(Element element, ParserContext pc) {
RootBeanDefinition authProvider = new RootBeanDefinition(DaoAuthenticationProvider.class);
authProvider.setSource(pc.extractSource(element));

String cacheRef = element.getAttribute(CACHE_REF);
if (StringUtils.hasText(cacheRef)) {
authProvider.getPropertyValues().addPropertyValue("userCache", new RuntimeBeanReference(cacheRef));
}

Element passwordEncoderElt = DomUtils.getChildElementByTagName(element, Elements.PASSWORD_ENCODER);

if (passwordEncoderElt != null) {
Expand Down Expand Up @@ -62,10 +68,10 @@ public BeanDefinition parse(Element element, ParserContext pc) {
}

// Pinch the cache-ref from the UserDetailService element, if set.
String cacheRef = userServiceElt.getAttribute(AbstractUserDetailsServiceBeanDefinitionParser.CACHE_REF);
String userDetailsServiceCacheRef = userServiceElt.getAttribute(AbstractUserDetailsServiceBeanDefinitionParser.CACHE_REF);

if (StringUtils.hasText(cacheRef)) {
authProvider.getPropertyValues().addPropertyValue("userCache", new RuntimeBeanReference(cacheRef));
if (StringUtils.hasText(userDetailsServiceCacheRef)) {
authProvider.getPropertyValues().addPropertyValue("userCache", new RuntimeBeanReference(userDetailsServiceCacheRef));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class JdbcUserServiceBeanDefinitionParser extends AbstractUserDetailsServ
static final String ATT_AUTHORITIES_BY_USERNAME_QUERY = "authorities-by-username-query";
static final String ATT_GROUP_AUTHORITIES_QUERY = "group-authorities-by-username-query";
static final String ATT_ROLE_PREFIX = "role-prefix";
static final String ATT_ALLOW_EMPTY_AUTHORITIES = "allow-empty-authorities";

protected String getBeanClassName(Element element) {
return "org.springframework.security.provisioning.JdbcUserDetailsManager";
Expand All @@ -35,6 +36,7 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
String authoritiesQuery = element.getAttribute(ATT_AUTHORITIES_BY_USERNAME_QUERY);
String groupAuthoritiesQuery = element.getAttribute(ATT_GROUP_AUTHORITIES_QUERY);
String rolePrefix = element.getAttribute(ATT_ROLE_PREFIX);
String allowEmptyAuthorities = element.getAttribute(ATT_ALLOW_EMPTY_AUTHORITIES);

if (StringUtils.hasText(rolePrefix)) {
builder.addPropertyValue("rolePrefix", rolePrefix);
Expand All @@ -52,5 +54,9 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
builder.addPropertyValue("enableGroups", Boolean.TRUE);
builder.addPropertyValue("groupAuthoritiesByUsernameQuery", groupAuthoritiesQuery);
}

if (StringUtils.hasText(allowEmptyAuthorities)) {
builder.addPropertyValue("allowEmptyAuthorities", Boolean.parseBoolean(allowEmptyAuthorities));
}
}
}
3 changes: 2 additions & 1 deletion config/src/main/resources/META-INF/spring.schemas
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
http\://www.springframework.org/schema/security/spring-security.xsd=org/springframework/security/config/spring-security-3.1.xsd
http\://www.springframework.org/schema/security/spring-security.xsd=org/springframework/security/config/spring-security-3.1.1.xsd
http\://www.springframework.org/schema/security/spring-security-3.1.1.xsd=org/springframework/security/config/spring-security-3.1.1.xsd
http\://www.springframework.org/schema/security/spring-security-3.1.xsd=org/springframework/security/config/spring-security-3.1.xsd
http\://www.springframework.org/schema/security/spring-security-3.0.3.xsd=org/springframework/security/config/spring-security-3.0.3.xsd
http\://www.springframework.org/schema/security/spring-security-3.0.xsd=org/springframework/security/config/spring-security-3.0.xsd
Expand Down
Loading