Announcement Announcement Module
Collapse
No announcement yet.
Problems with WebApplicationContext Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with WebApplicationContext

    Hello,

    I'm new to acegi and spring so I'm probably doing something stupid. I hope someone reading this can point out what it is. I'm trying to use acegi to protect webservices that are provided with Apache-Axis.

    I've tried to follow the examples as close as possible but everytime I deploy my war file I get the following exception:

    java.lang.IllegalStateException: Root context attribute is not of type WebApplicationContext: org.springframework.web.context.support.XmlWebAppl icationContext:
    displayName=[Root XmlWebApplicationContext]; startup date=[Wed Nov 03 08:10:42 MST 2004]; root of ApplicationContext hierarchy; config locations=[/WEB-INF/classes/securityApplicationContext.xml];
    at org.springframework.web.context.support.WebApplica tionContextUtils.getWebApplicationContext(WebAppli cationContextUtils.java:64)

    I can tell my web.xml file is being loaded and parsed but for some reason acegi/spring is unhappy with my securityApplicationContext.xml file.

    I've attached both my web.xml and my securityApplicationContext.xml. Any help that can be provided would be appreciated.

    Craig Lindley

    Here is my web.xml file
    <?xml version="1.0" encoding="ISO-8859-1"?>

    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">

    <web-app>

    <display-name>Cassatt Collage Webservices</display-name>

    <!-- XML file that defines the root application context -->
    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/classes/securityApplicationContext.xml</param-value>
    </context-param>

    <servlet>
    <servlet-name>AxisServlet</servlet-name>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-class>
    org.apache.axis.transport.http.AxisServlet
    </servlet-class>
    <load-on-startup>2</load-on-startup>
    </servlet>

    <servlet>
    <servlet-name>AdminServlet</servlet-name>
    <display-name>Axis Admin Servlet</display-name>
    <servlet-class>
    org.apache.axis.transport.http.AdminServlet
    </servlet-class>
    <load-on-startup>100</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

    <filter>
    <filter-name>Acegi HTTP Request Security Filter</filter-name>
    <filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
    <init-param>
    <param-name>init</param-name>
    <param-value>lazy</param-value>
    <param-name>targetClass</param-name>
    <param-value>net.sf.acegisecurity.intercept.web.SecurityE nforcementFilter</param-value>
    </init-param>
    </filter>

    <filter-mapping>
    <filter-name>Acegi HTTP Request Security Filter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <mime-mapping>
    <extension>wsdl</extension>
    <mime-type>text/xml</mime-type>
    </mime-mapping>

    <mime-mapping>
    <extension>xsd</extension>
    <mime-type>text/xml</mime-type>
    </mime-mapping>

    <!-- Loads root application context of this web app at startup -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    </web-app>

    here is my securityApplicationContext.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>

    <!-- =================== SECURITY SYSTEM DEFINITIONS ================== -->
    <bean id="authenticationManager" class="net.sf.acegisecurity.providers.ProviderMana ger">
    <property name="providers">
    <list><ref bean="CassattAuthenticationProvider"/></list>
    </property>
    </bean>

    <bean id="CassattAuthenticationProvider" class="com.cassatt.blt.security.CassattAuthenticat ionProvider"/>

    <bean id="authorizationManager" class="net.sf.acegisecurity.vote.AffirmativeBased" >
    <property name="allowIfAllAbstainDecisions"><value>false</value></property>
    <property name="decisionVoters">
    <list><ref bean="CassattAuthorizationVoter"/></list>
    </property>
    </bean>

    <bean id="CassattAuthorizationVoter" class="com.cassatt.blt.security.CassattAuthorizati onVoter"/>

    <!-- ===================== HTTP REQUEST SECURITY ==================== -->
    <bean id="securityEnforcementFilter" class="net.sf.acegisecurity.intercept.web.Security EnforcementFilter">
    <property name="filterSecurityInterceptor"><ref bean="filterInvocationInterceptor"/></property>
    </bean>

    <bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSe curityInterceptor">
    <property name="authenticationManager"><ref bean="authenticationManager"/></property>
    <property name="accessDecisionManager"><ref bean="authorizationManager"/></property>
    </bean>

    </beans>

  • #2
    For my application, the context files are under /WEB-INF, not in the classes directory.

    Try moving your context files and change contextConfigLocation in web.xml.

    Code:
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/securityApplicationContext.xml</param-value> 
    </context-param>
    Best Regards, feester

    Comment


    • #3
      Actually I tried that and I tried naming the xml file applicationContext.xml, neither of which had an effect.

      What I don't understand is that when I look at the code in WebApplicationContextUtils:

      Code:
              public static WebApplicationContext getWebApplicationContext&#40;ServletContext sc&#41; &#123;
                      Object attr = sc.getAttribute&#40;WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE&#41;;
                      if &#40;attr == null&#41; &#123;
                              return null;
                      &#125;
                      if &#40;attr instanceof RuntimeException&#41; &#123;
                              throw &#40;RuntimeException&#41; attr;
                      &#125;
                      if &#40;attr instanceof Error&#41; &#123;
                              throw &#40;Error&#41; attr;
                      &#125;
                      if &#40;!&#40;attr instanceof WebApplicationContext&#41;&#41; &#123;
                              throw new IllegalStateException&#40;"Root context attribute is not of type WebApplicationContext&#58; " +
      attr&#41;;
                      &#125;
                      return &#40;WebApplicationContext&#41; attr;
              &#125;
      the exception is being thrown because it doesn't think attr is an instanceof WebApplicationContext. But XmlWebApplicationContext does indeed implement WebApplicationContext.

      So I remain confused

      Thanks,
      CL

      Comment


      • #4
        Looks like you might have a classloading issue, with multiple copies of Spring/Acegi laying around. So the class could be correct, but it's loaded by another classloader, and is considered a different class effectively.

        Can you verify that your classloading setup is ok, with only one copy of Spring and Acegi?

        Comment


        • #5
          yes that was the problem. Thanks for taking the time to consider my problem.

          Craiig Lindley

          Comment

          Working...
          X