Definition of spring http security element in two different files?

Is it possible to define security:intercept-url and security:custom-filter elements for one security:http in two different Spring configuration files?

Thus, we can fully use the definitions of security:custom-filter , which will be common in many applications with interception rules that will not.


I can't just duplicate the <security:http> element because I get a BeanDefinitionParsingException: Configuration problem: Duplicate <http> element detected . I know well how to split a regular bean file into import

+4
source share
3 answers

As stated in the comment:

Spring Security versions prior to 3.1.x do not allow multiple http element definitions.

3.1, however.

Here is the Jira problem for this feature.

This article about changes 3.1 may also be useful.


You can specify a different context file in the web.xml file:

 <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring-contexts/context1.xml /WEB-INF/spring-contexts/context2.xml </param-value> </context-param> 

Or you can specify the directory in which your contexts will be indicated, and name them in any way, without specifying each context file separately:

 <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring-contexts/* </param-value> </context-param> 

Regarding Ayusman's answer, you can import security contexts into bean contexts:

 <beans> <import resource="classpath*:/security-context-*.xml"/> <bean><!-- blah blah --></bean> </beans> 
+4
source

use import in the application context file.

 custom-filter.appcontext.xml . . <import resource="interceptor-url-file.xml"/> 

Note that both files must have the correct spring xml schema details and MUST be valid XML files.

0
source

I have been working on this error for 5 hours. Really stupid problem.

This error is a parsing error, which when you comment out some lines in applicationContext-security.xml, the files are not generated correctly.

Let me clarify the sample code.

 <port-mappings> <port-mapping http="7001" https="7002" /> </port-mappings> <!-- <port-mappings> <port-mapping http="7015" https="7515" /> </port-mappings> --> 

these lines are generated as:

 <port-mappings> <port-mapping http="7001" https="7002" /> </port-mappings> <port-mappings> <port-mapping http="7015" https="7515" /> </port-mappings> --> 

so that the compiler informs you about the detection of a "repeating element". Because the generated file contains duplicate elements.

I hope to help you.

0
source

All Articles