Browse Source

Update minimum required schema to 3.1.

Luke Taylor 15 years ago
parent
commit
6abfa2e887

+ 11 - 9
config/src/main/java/org/springframework/security/config/SecurityNamespaceHandler.java

@@ -40,8 +40,8 @@ public final class SecurityNamespaceHandler implements NamespaceHandler {
 
     public BeanDefinition parse(Element element, ParserContext pc) {
         if (!namespaceMatchesVersion(element)) {
-            pc.getReaderContext().fatal("You cannot use a spring-security-2.0.xsd schema with Spring Security 3." +
-                    " Please update your schema declarations to the 3.1 schema.", element);
+            pc.getReaderContext().fatal("You cannot use a spring-security-2.0.xsd or spring-security-3.0.xsd schema " +
+                    "with Spring Security 3.1. Please update your schema declarations to the 3.1 schema.", element);
         }
         String name = pc.getDelegate().getLocalName(element);
         BeanDefinitionParser parser = parsers.get(name);
@@ -58,13 +58,14 @@ public final class SecurityNamespaceHandler implements NamespaceHandler {
             } else {
                 reportUnsupportedNodeType(name, pc, element);
             }
+
+            return null;
         }
 
         return parser.parse(element, pc);
     }
 
     public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext pc) {
-        BeanDefinitionDecorator decorator = null;
         String name = pc.getDelegate().getLocalName(node);
 
         // We only handle elements
@@ -84,9 +85,7 @@ public final class SecurityNamespaceHandler implements NamespaceHandler {
             }
         }
 
-        if (decorator == null) {
-            reportUnsupportedNodeType(name, pc, node);
-        }
+        reportUnsupportedNodeType(name, pc, node);
 
         return null;
     }
@@ -129,8 +128,11 @@ public final class SecurityNamespaceHandler implements NamespaceHandler {
 
     /**
      * Check that the schema location declared in the source file being parsed matches the Spring Security version.
-     * The old 2.0 schema is not compatible with the new 3.0 parser, so it is an error to explicitly use
-     * 3.0. It might be an error to declare spring-security.xsd as an alias, but you are only going to find that out
+     * The old 2.0 schema is not compatible with the 3.1 parser, so it is an error to explicitly use
+     * 2.0.
+     * <p>
+     * There are also differences between 3.0 and 3.1 which are sufficient that we report using 3.0 as an error too.
+     * It might be an error to declare spring-security.xsd as an alias, but you are only going to find that out
      * when one of the sub parsers breaks.
      *
      * @param element the element that is to be parsed next
@@ -142,7 +144,7 @@ public final class SecurityNamespaceHandler implements NamespaceHandler {
 
     private boolean matchesVersionInternal(Element element) {
         String schemaLocation = element.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "schemaLocation");
-        return schemaLocation.matches("(?m).*spring-security-3.*.xsd.*")
+        return schemaLocation.matches("(?m).*spring-security-3\\.1.*.xsd.*")
                  || schemaLocation.matches("(?m).*spring-security.xsd.*")
                  || !schemaLocation.matches("(?m).*spring-security.*");
     }

+ 8 - 4
config/src/test/java/org/springframework/security/config/SecurityNamespacehandlerTests.java

@@ -11,19 +11,23 @@ import org.springframework.security.config.util.InMemoryXmlApplicationContext;
  * @author Luke Taylor
  * @since 3.0
  */
-public class SecurityNamespacehandlerTests {
+public class SecurityNamespaceHandlerTests {
+    @Test
+    public void constructionSucceeds() {
+        new SecurityNamespaceHandler();
+    }
 
     @Test
-    public void pre3SchemaAreNotSupported() throws Exception {
+    public void pre31SchemaAreNotSupported() throws Exception {
         try {
             new InMemoryXmlApplicationContext(
                     "<user-service id='us'>" +
                     "  <user name='bob' password='bobspassword' authorities='ROLE_A' />" +
-                    "</user-service>", "2.0.4", null
+                    "</user-service>", "3.0.3", null
             );
             fail("Expected BeanDefinitionParsingException");
         } catch (BeanDefinitionParsingException expected) {
-            assertTrue(expected.getMessage().contains("You cannot use a spring-security-2.0.xsd schema"));
+            assertTrue(expected.getMessage().contains("You cannot use a spring-security-2.0.xsd or"));
         }
     }
 }

+ 2 - 2
config/src/test/java/org/springframework/security/config/authentication/AuthenticationManagerBeanDefinitionParserTests.java

@@ -34,13 +34,13 @@ public class AuthenticationManagerBeanDefinitionParserTests {
     @Test
     // SEC-1225
     public void providersAreRegisteredAsTopLevelBeans() throws Exception {
-        setContext(CONTEXT, "3.0");
+        setContext(CONTEXT, "3.1");
         assertEquals(1, appContext.getBeansOfType(AuthenticationProvider.class).size());
     }
 
     @Test
     public void eventsArePublishedByDefault() throws Exception {
-        setContext(CONTEXT, "3.0");
+        setContext(CONTEXT, "3.1");
         AuthListener listener = new AuthListener();
         appContext.addApplicationListener(listener);
 

+ 1 - 1
config/src/test/resources/org/springframework/security/config/method-security.xml

@@ -4,7 +4,7 @@
     xmlns:b="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
+http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
 
     <b:bean id="target" class="org.springframework.security.config.TestBusinessBeanImpl">
         <!-- This will add a security interceptor to the bean -->

+ 2 - 2
config/src/test/resources/org/springframework/security/util/filtertest-valid.xml

@@ -21,7 +21,7 @@
     xmlns:sec="http://www.springframework.org/schema/security"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
+http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
 
     <bean id="mockFilter" class="org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter"/>
 
@@ -42,7 +42,7 @@ http://www.springframework.org/schema/security http://www.springframework.org/sc
         </sec:authentication-provider>
     </sec:authentication-manager>
 
-    <bean id="mockNotAFilter" class="org.springframework.security.web.util.AntUrlPathMatcher"/>
+    <bean id="mockNotAFilter" class="org.springframework.security.web.util.AnyRequestMatcher"/>
 
     <bean id="filterChain" class="org.springframework.security.web.FilterChainProxy">
         <sec:filter-chain-map path-type="ant">

+ 1 - 1
itest/context/src/test/resources/protect-pointcut-performance-app-context.xml

@@ -2,7 +2,7 @@
     xmlns:sec="http://www.springframework.org/schema/security"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
+                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
 
     <sec:global-method-security>
         <sec:protect-pointcut expression="execution(* org.springframework.security.core.session.SessionRegistry.refreshLastRequest(..))" access="ROLE_ADMIN" />

+ 1 - 1
itest/web/src/main/webapp/WEB-INF/http-security-basic.xml

@@ -4,7 +4,7 @@
     xmlns:beans="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
+                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
 
     <http>
         <intercept-url pattern="/**" access="ROLE_DEVELOPER,ROLE_USER" />

+ 1 - 1
itest/web/src/main/webapp/WEB-INF/in-memory-provider.xml

@@ -4,7 +4,7 @@
     xmlns:beans="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
+                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
 
     <authentication-manager alias="authenticationManager">
         <authentication-provider>

+ 3 - 1
samples/tutorial/src/main/webapp/WEB-INF/applicationContext-security.xml

@@ -9,7 +9,9 @@
     xmlns:beans="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
-                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
+                        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
+
+    <debug />
 
     <global-method-security pre-post-annotations="enabled">
         <!-- AspectJ pointcut expression that locates our "post" method and applies security that way