瀏覽代碼

SEC-648: Added custom-authentication-provider support.

Luke Taylor 17 年之前
父節點
當前提交
82940db6c8

+ 23 - 0
core/src/main/java/org/springframework/security/config/CustomAuthenticationProviderBeanDefinitionDecorator.java

@@ -0,0 +1,23 @@
+package org.springframework.security.config;
+
+import org.springframework.beans.factory.xml.BeanDefinitionDecorator;
+import org.springframework.beans.factory.xml.ParserContext;
+import org.springframework.beans.factory.config.BeanDefinitionHolder;
+
+import org.w3c.dom.Node;
+
+
+/**
+ * Adds the decorated {@link org.springframework.security.providers.AuthenticationProvider} to the ProviderManager's
+ * list.
+ *
+ * @author Luke Taylor
+ * @version $Id$
+ */
+public class CustomAuthenticationProviderBeanDefinitionDecorator implements BeanDefinitionDecorator {
+    public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder holder, ParserContext parserContext) {
+        ConfigUtils.getRegisteredProviders(parserContext).add(holder.getBeanDefinition());
+
+        return holder;
+    }
+}

+ 2 - 1
core/src/main/java/org/springframework/security/config/Elements.java

@@ -29,5 +29,6 @@ abstract class Elements {
 	public static final String SALT_SOURCE = "salt-source";
 	public static final String PORT_MAPPINGS = "port-mappings";
     public static final String PORT_MAPPING = "port-mapping";
-    public static final String CUSTOM_FILTER = "custom-filter";    
+    public static final String CUSTOM_FILTER = "custom-filter";
+    public static final String CUSTOM_AUTH_RPOVIDER = "custom-authentication-provider";
 }

+ 1 - 0
core/src/main/java/org/springframework/security/config/SecurityNamespaceHandler.java

@@ -25,5 +25,6 @@ public class SecurityNamespaceHandler extends NamespaceHandlerSupport {
         registerBeanDefinitionDecorator(Elements.INTERCEPT_METHODS, new InterceptMethodsBeanDefinitionDecorator());
         registerBeanDefinitionDecorator(Elements.FILTER_CHAIN_MAP, new FilterChainMapBeanDefinitionDecorator());
         registerBeanDefinitionDecorator(Elements.CUSTOM_FILTER, new OrderedFilterBeanDefinitionDecorator());
+        registerBeanDefinitionDecorator(Elements.CUSTOM_AUTH_RPOVIDER, new CustomAuthenticationProviderBeanDefinitionDecorator());
     }
 }

+ 10 - 0
samples/tutorial/src/main/webapp/WEB-INF/applicationContext-security-ns.xml

@@ -34,6 +34,16 @@
 
     </http>
 
+    <beans:bean id="x509Filter" class="org.springframework.security.ui.preauth.x509.X509PreAuthenticatedProcessingFilter" autowire="byType">
+        <custom-filter after="X509_FILTER"/>
+    </beans:bean>
+
+    <beans:bean id="preauthProvider" class="org.springframework.security.providers.preauth.PreAuthenticatedAuthenticationProvider" >
+        <custom-authentication-provider />
+        <beans:property name="preAuthenticatedUserDetailsService">
+            <beans:bean class="org.springframework.security.providers.preauth.UserDetailsByNameServiceWrapper" autowire="byType"/>
+        </beans:property>
+    </beans:bean>
 
     <!--
     Usernames/Passwords are