Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Final Commit
Browse files Browse the repository at this point in the history
sheriumair committed Mar 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 1106fc0 commit c45d309
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -42,7 +42,14 @@ protected String getBeanClassName(Element element) {
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String dataSource = element.getAttribute(ATT_DATA_SOURCE);
builder.addPropertyReference("dataSource", dataSource);
if (StringUtils.hasText(dataSource)) {
builder.addPropertyReference("dataSource", dataSource);
}
else {
parserContext.getReaderContext()
.error(ATT_DATA_SOURCE + " is required for " + Elements.JDBC_USER_SERVICE,
parserContext.extractSource(element));
}
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);
Original file line number Diff line number Diff line change
@@ -16,10 +16,12 @@

package org.springframework.security.config.authentication;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Element;

import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.CachingUserDetailsService;
import org.springframework.security.authentication.ProviderManager;
@@ -160,6 +162,44 @@ public void rolePrefixIsUsedWhenSet() {
assertThat(AuthorityUtils.authorityListToSet(rod.getAuthorities())).contains("PREFIX_ROLE_SUPERVISOR");
}

@Test
public void testEmptyDataSourceRef() {
// @formatter:off
String xml = "<authentication-manager>"
+ " <authentication-provider>"
+ " <jdbc-user-service data-source-ref=''/>"
+ " </authentication-provider>"
+ "</authentication-manager>";
// @formatter:on

try {
setContext(xml);
Assertions.fail("Expected exception due to empty data-source-ref");
}
catch (BeanDefinitionStoreException ex) {
assertThat(ex.getMessage()).contains("data-source-ref is required");
}
}

@Test
public void testMissingDataSourceRef() {
// @formatter:off
String xml = "<authentication-manager>"
+ " <authentication-provider>"
+ " <jdbc-user-service/>"
+ " </authentication-provider>"
+ "</authentication-manager>";
// @formatter:on

try {
setContext(xml);
Assertions.fail("Expected exception due to missing data-source-ref");
}
catch (BeanDefinitionStoreException ex) {
assertThat(ex.getMessage()).contains("XML document from").contains("is invalid");
}
}

private void setContext(String context) {
this.appContext = new InMemoryXmlApplicationContext(context);
}

0 comments on commit c45d309

Please sign in to comment.