Announcement Announcement Module
Collapse
No announcement yet.
Configuration problem: Duplicate <global-method-security> detected. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuration problem: Duplicate <global-method-security> detected.

    Hi all,

    I've configured my app to use Spring Security and since then I get this exception:

    Code:
    ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Duplicate <global-method-security> detected.
    Offending resource: ServletContext resource [/WEB-INF/classes/security-context.xml]
    	at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
    	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
    	at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:72)
    	at org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser.registerAdvisor(GlobalMethodSecurityBeanDefinitionParser.java:346)
    	at org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParser.parse(GlobalMethodSecurityBeanDefinitionParser.java:223)
    	at org.springframework.security.config.SecurityNamespaceHandler.parse(SecurityNamespaceHandler.java:88)
    	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1419)
    	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
    	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
    	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
    	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
    	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
    	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
    	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:522)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:436)
    	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:385)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:284)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205)
    etc, etc...

    My spring-security.xml looks like this:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:security="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.1.xsd
           http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
    
    
    
    <!-- preauthentication --> 
    	<security:global-method-security pre-post-annotations="enabled" />
          
        <bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy">
            <security:filter-chain-map path-type="ant">
                <security:filter-chain pattern="/**" filters="j2eePreAuthFilter"/>
            </security:filter-chain-map>
        </bean>
        
     
        <security:authentication-manager alias="authenticationManager">
            <security:authentication-provider ref='preAuthenticatedAuthenticationProvider'/>
        </security:authentication-manager>
    
        <bean id="preAuthenticatedAuthenticationProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
            <property name="preAuthenticatedUserDetailsService" ref="preAuthenticatedUserDetailsService"/>
        </bean>
    
        <bean id="preAuthenticatedUserDetailsService"
                class="org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesUserDetailsService"/>
        
        
        <bean id="j2eePreAuthFilter" class="es.myapp.security.MyUserJ2eePreAuthenticatedProcessingFilter">
        	<property name="authenticationManager" ref="authenticationManager"/>
        	<property name="authenticationDetailsSource" ref="authenticationDetailsSource"/>
        	<property name="continueFilterChainOnUnsuccessfulAuthentication" value="false"/>
        </bean>
      
      <bean id="authenticationDetailsSource" class="org.springframework.security.web.authentication.preauth.j2ee.J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource">
        <property name="mappableRolesRetriever" ref="j2eeMappableRolesRetriever"/>
        <property name="userRoles2GrantedAuthoritiesMapper" ref="j2eeUserRoles2GrantedAuthoritiesMapper"/>
      </bean>
      
      <bean id="j2eeMappableRolesRetriever" class="org.springframework.security.web.authentication.preauth.j2ee.WebXmlMappableAttributesRetriever">
      </bean>
      
       <bean id="j2eeUserRoles2GrantedAuthoritiesMapper" class="org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper">
        <property name="attributePrefix" value="test"/>
      </bean>
    
    </beans>
    And I've annotated just one of my methods as @Secure just to test if everything was OK... but it fails due to that exception... any ideas? (I've already searched through the forum but I didn't find anything that works for me). Thank you!
    Last edited by diminuta; Aug 1st, 2012, 02:26 AM.

  • #2
    What does security-context.xml look like? Based upon the error message, it appears that you may have defined global-method-security there as well as the spring-security.xml you have posted.

    Comment


    • #3
      Oooops sorry, I've mistaken names the file I posted its the security-context.xml actually (not spring-security.xml), there's no spring-security.xml file, just security-context.xml, sorry... any ideas?

      Comment


      • #4
        What does your web.xml look like? Do you have the file listed twice in your web.xml?

        Comment


        • #5
          Originally posted by Rob Winch View Post
          What does your web.xml look like? Do you have the file listed twice in your web.xml?
          I'm at home now, I don't have access to the code right now, I'll post it tomorrow but I'm sure I haven't listed the file twice, I already checked it

          Comment


          • #6
            If you can come up with a small complete sample that causes the issue I can look at it. Another thing to try is to turn on logging and see if that helps.

            Comment


            • #7
              Originally posted by Rob Winch View Post
              If you can come up with a small complete sample that causes the issue I can look at it. Another thing to try is to turn on logging and see if that helps.
              I'll do that tomorrow first thing in the morning when I get to the office... thanx!

              Comment


              • #8
                Here's my web.xml


                Code:
                <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
                
                	<display-name>Aplicación Web </display-name>
                
                	<!-- Define la localización de los ficheros de configuración de Spring -->
                	<context-param>
                		<param-name>contextConfigLocation</param-name>
                		<param-value>
                			/WEB-INF/classes/applicationContext.xml
                			/WEB-INF/classes/security-context.xml
                		</param-value>
                	</context-param>
                
                	<!-- Reads request input using UTF-8 encoding -->
                	<filter>
                		<filter-name>characterEncodingFilter</filter-name>
                		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
                		<init-param>
                			<param-name>encoding</param-name>
                			<param-value>UTF-8</param-value>
                		</init-param>
                		<init-param>
                			<param-name>forceEncoding</param-name>
                			<param-value>true</param-value>
                		</init-param>
                	</filter>
                
                	<filter-mapping>
                		<filter-name>characterEncodingFilter</filter-name>
                		<url-pattern>/*</url-pattern>
                	</filter-mapping>
                	
                 	<filter> 
                        <filter-name>springSecurityFilterChain</filter-name> 
                        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
                 	</filter> 
                 
                 	<filter-mapping> 
                         <filter-name>springSecurityFilterChain</filter-name> 
                         <url-pattern>/*</url-pattern> 
                 	</filter-mapping> 
                	
                	<listener>
                		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                	</listener>
                
                	<!-- Handles all requests into the application -->
                	<servlet>
                		<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
                		<servlet-class>es.myapp.controller.MyAppDispatcherServlet</servlet-class>
                		<init-param>
                			<param-name>contextConfigLocation</param-name>
                			<param-value>/WEB-INF/servlet-context.xml</param-value>
                		</init-param>
                		<load-on-startup>1</load-on-startup>
                	</servlet>
                
                	<servlet-mapping>
                		<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
                		<url-pattern>/</url-pattern>
                	</servlet-mapping>
                	
                	<!-- del. welcome files -->
                	<!-- useful for Servlet 3 container (Tomcat 7 and Jetty 6) -->
                	<welcome-file-list>
                		<welcome-file></welcome-file>
                	</welcome-file-list>
                
                	<!-- Referencia a recursos jndi WAS -->
                	<resource-ref id="ResourceRef_MYAPP">
                		<res-ref-name>jdbc/myapp</res-ref-name>
                		<res-type>javax.sql.DataSource</res-type>
                		<res-auth>Container</res-auth>
                		<res-sharing-scope>Shareable</res-sharing-scope>
                	</resource-ref>
                
                </web-app>

                Comment


                • #9
                  Nothing seems to jump out at me. Try enabling debug logging and see if that helps. If you can put together a simplified example that reproduces the problem I can take a look.

                  Comment


                  • #10
                    Well in the end it was just a silly problem

                    In my applicationContext.xml I have the line:
                    Code:
                    <import resource="security-context.xml" />
                    And in web.xml I have this:
                    Code:
                    <context-param>
                    		<param-name>contextConfigLocation</param-name>
                    		<param-value>
                    			/WEB-INF/classes/applicationContext.xml
                    			/WEB-INF/classes/security-context.xml
                    		</param-value>
                    	</context-param>
                    So the file was being read twice...

                    [smashing my head into the wall]

                    Comment

                    Working...
                    X