16
16
17
17
package org .springframework .security .config .util ;
18
18
19
+ import java .io .IOException ;
20
+ import java .io .InputStream ;
21
+ import java .util .Properties ;
22
+
19
23
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
20
24
import org .springframework .context .ApplicationContext ;
21
25
import org .springframework .context .support .AbstractXmlApplicationContext ;
22
26
import org .springframework .core .io .Resource ;
27
+ import org .springframework .security .core .SpringSecurityCoreVersion ;
23
28
import org .springframework .security .util .InMemoryResource ;
24
29
25
30
/**
26
31
* @author Luke Taylor
27
32
* @author Eddú Meléndez
33
+ * @author Emil Sierżęga
28
34
*/
29
35
public class InMemoryXmlApplicationContext extends AbstractXmlApplicationContext {
30
36
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
+
31
55
static final String BEANS_OPENING = "<b:beans xmlns='http://www.springframework.org/schema/security'\n "
32
56
+ " xmlns:context='http://www.springframework.org/schema/context'\n "
33
57
+ " xmlns:b='http://www.springframework.org/schema/beans'\n "
@@ -42,7 +66,7 @@ public class InMemoryXmlApplicationContext extends AbstractXmlApplicationContext
42
66
+ "http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context-2.5.xsd\n "
43
67
+ "http://www.springframework.org/schema/security https://www.springframework.org/schema/security/spring-security-" ;
44
68
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 () ;
46
70
47
71
Resource inMemoryXml ;
48
72
0 commit comments