Skip to content

Commit e5e576e

Browse files
committed
SecurityNamespaceHandler: update schema version to 5.5
Closes gh-8974
1 parent 816e847 commit e5e576e

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

config/src/main/java/org/springframework/security/config/SecurityNamespaceHandler.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public BeanDefinition parse(Element element, ParserContext pc) {
9393
if (!namespaceMatchesVersion(element)) {
9494
pc.getReaderContext().fatal("You cannot use a spring-security-2.0.xsd or spring-security-3.0.xsd or "
9595
+ "spring-security-3.1.xsd schema or spring-security-3.2.xsd schema or spring-security-4.0.xsd schema "
96-
+ "with Spring Security 5.4. Please update your schema declarations to the 5.4 schema.", element);
96+
+ "with Spring Security 5.5. Please update your schema declarations to the 5.5 schema.", element);
9797
}
9898
String name = pc.getDelegate().getLocalName(element);
9999
BeanDefinitionParser parser = this.parsers.get(name);
@@ -213,7 +213,7 @@ private boolean namespaceMatchesVersion(Element element) {
213213

214214
private boolean matchesVersionInternal(Element element) {
215215
String schemaLocation = element.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
216-
return schemaLocation.matches("(?m).*spring-security-5\\.4.*.xsd.*")
216+
return schemaLocation.matches("(?m).*spring-security-5\\.5.*.xsd.*")
217217
|| schemaLocation.matches("(?m).*spring-security.xsd.*")
218218
|| !schemaLocation.matches("(?m).*spring-security.*");
219219
}

config/src/test/java/org/springframework/security/config/util/InMemoryXmlApplicationContext.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,42 @@
1616

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

19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
import java.util.Properties;
22+
1923
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
2024
import org.springframework.context.ApplicationContext;
2125
import org.springframework.context.support.AbstractXmlApplicationContext;
2226
import org.springframework.core.io.Resource;
27+
import org.springframework.security.core.SpringSecurityCoreVersion;
2328
import org.springframework.security.util.InMemoryResource;
2429

2530
/**
2631
* @author Luke Taylor
2732
* @author Eddú Meléndez
33+
* @author Emil Sierżęga
2834
*/
2935
public class InMemoryXmlApplicationContext extends AbstractXmlApplicationContext {
3036

37+
private static String getCurrentXSDVersionFromSpringSchemas() {
38+
Properties properties = new Properties();
39+
try (InputStream is = SpringSecurityCoreVersion.class.getClassLoader()
40+
.getResourceAsStream("META-INF/spring.schemas")) {
41+
properties.load(is);
42+
}
43+
catch (IOException ex) {
44+
throw new RuntimeException("Could not read 'META-INF/spring.schemas'", ex);
45+
}
46+
47+
String inPackageLocation = properties
48+
.getProperty("https://www.springframework.org/schema/security/spring-security.xsd");
49+
String[] parts = inPackageLocation.split("-");
50+
String currentXSD = parts[parts.length - 1];
51+
String currentVersion = currentXSD.replace(".xsd", "");
52+
return currentVersion;
53+
}
54+
3155
static final String BEANS_OPENING = "<b:beans xmlns='http://www.springframework.org/schema/security'\n"
3256
+ " xmlns:context='http://www.springframework.org/schema/context'\n"
3357
+ " xmlns:b='http://www.springframework.org/schema/beans'\n"
@@ -42,7 +66,7 @@ public class InMemoryXmlApplicationContext extends AbstractXmlApplicationContext
4266
+ "http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context-2.5.xsd\n"
4367
+ "http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security-";
4468
static final String BEANS_CLOSE = "</b:beans>\n";
45-
static final String SPRING_SECURITY_VERSION = "5.4";
69+
static final String SPRING_SECURITY_VERSION = getCurrentXSDVersionFromSpringSchemas();
4670

4771
Resource inMemoryXml;
4872

0 commit comments

Comments
 (0)