Skip to content

Commit 39dbd24

Browse files
committed
Polish gh-14742
1 parent 33ebd54 commit 39dbd24

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

config/src/main/java/org/springframework/security/config/authentication/JdbcUserServiceBeanDefinitionParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

config/src/test/java/org/springframework/security/config/authentication/JdbcUserServiceBeanDefinitionParserTests.java

+15-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,13 @@
1616

1717
package org.springframework.security.config.authentication;
1818

19-
import org.assertj.core.api.Assertions;
2019
import org.junit.jupiter.api.AfterEach;
2120
import org.junit.jupiter.api.Test;
2221
import org.w3c.dom.Element;
22+
import org.xml.sax.SAXParseException;
2323

24-
import org.springframework.beans.factory.BeanDefinitionStoreException;
24+
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
25+
import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
2526
import org.springframework.security.authentication.AuthenticationManager;
2627
import org.springframework.security.authentication.CachingUserDetailsService;
2728
import org.springframework.security.authentication.ProviderManager;
@@ -35,6 +36,7 @@
3536
import org.springframework.security.util.FieldUtils;
3637

3738
import static org.assertj.core.api.Assertions.assertThat;
39+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3840
import static org.mockito.Mockito.mock;
3941

4042
/**
@@ -170,15 +172,11 @@ public void testEmptyDataSourceRef() {
170172
+ " <jdbc-user-service data-source-ref=''/>"
171173
+ " </authentication-provider>"
172174
+ "</authentication-manager>";
175+
assertThatExceptionOfType(BeanDefinitionParsingException.class)
176+
.isThrownBy(() -> setContext(xml))
177+
.withFailMessage("Expected exception due to empty data-source-ref")
178+
.withMessageContaining("data-source-ref is required for jdbc-user-service");
173179
// @formatter:on
174-
175-
try {
176-
setContext(xml);
177-
Assertions.fail("Expected exception due to empty data-source-ref");
178-
}
179-
catch (BeanDefinitionStoreException ex) {
180-
assertThat(ex.getMessage()).contains("data-source-ref is required");
181-
}
182180
}
183181

184182
@Test
@@ -189,15 +187,13 @@ public void testMissingDataSourceRef() {
189187
+ " <jdbc-user-service/>"
190188
+ " </authentication-provider>"
191189
+ "</authentication-manager>";
190+
assertThatExceptionOfType(XmlBeanDefinitionStoreException.class)
191+
.isThrownBy(() -> setContext(xml))
192+
.withFailMessage("Expected exception due to missing data-source-ref")
193+
.havingRootCause()
194+
.isInstanceOf(SAXParseException.class)
195+
.withMessageContaining("Attribute 'data-source-ref' must appear on element 'jdbc-user-service'");
192196
// @formatter:on
193-
194-
try {
195-
setContext(xml);
196-
Assertions.fail("Expected exception due to missing data-source-ref");
197-
}
198-
catch (BeanDefinitionStoreException ex) {
199-
assertThat(ex.getMessage()).contains("XML document from").contains("is invalid");
200-
}
201197
}
202198

203199
private void setContext(String context) {

0 commit comments

Comments
 (0)