Results 1 to 7 of 7

Thread: how to configure ACEGI in spring with struts?

  1. #1
    Join Date
    Jan 2007
    Posts
    6

    Default how to configure ACEGI in spring with struts?

    hi,
    I tried to configure spring with struts and ACEGI.
    Im using org.springframework.web.struts.DelegatingActionPro xy
    to use struts in spring container.This will work fine.

    But, trying to connect ACEGI filters in web.xml and spring configuration, it throws "servlet action not available" error message.

    How to acheive this?

    Thanks in Advance,

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Please post some configuration (use [ code][/ code] tags) and maybe some code which is involved.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    I'm working with Struts, Acegi and Spring so it does work. I would guess its your configuration as Marten said. It would also be useful to see the stacktrace in the log when trying to work out the problem. Could you post that as well?

  4. #4
    Join Date
    Jan 2007
    Posts
    6

    Default

    For spring and struts, i used the following code in web.xml
    <web-app>
    <!-- Standard Action Servlet Configuration (with debugging) -->
    <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
    <param-name>application</param-name>
    <param-value>ApplicationResources</param-value>
    </init-param>

    <!-- struts configs -->
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>

    <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
    </init-param>
    <init-param>
    <param-name>detail</param-name>
    <param-value>0</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
    </servlet>

    <!-- Standard Action Servlet Mapping -->
    <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <!-- Welcome File List -->
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

    and my beans.xml is

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

    <beans>
    <bean id="loginIF" class="com.sis.login.pattern.LoginImpl"/>
    <bean name="/loginSubmit"
    class="com.sis.login.handlers.LoginAction">
    <property name="loginIF">
    <ref bean="loginIF"/>
    </property>
    </bean>

    </beans>

    This will work fine. But im trying to configure acegi in the above code it gets "servlet action not available".

    using acegi in web.xml

    <web-app>
    <!-- Standard Action Servlet Configuration (with debugging) -->
    <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
    <param-name>application</param-name>
    <param-value>ApplicationResources</param-value>
    </init-param>

    <!-- struts configs -->
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>

    <init-param>
    <param-name>debug</param-name>
    <param-value>0</param-value>
    </init-param>
    <init-param>
    <param-name>detail</param-name>
    <param-value>0</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
    </servlet>

    <!-- Standard Action Servlet Mapping -->
    <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    /WEB-INF/beans.xml
    </param-value>
    </context-param>

    <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/classes/log4j.properties</param-value>
    </context-param>


    <!-- Acegi Filter Chain Proxy -->
    <filter>
    <filter-name>Acegi Filter Chain Proxy</filter-name>
    <filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
    <init-param>
    <param-name>targetClass</param-name>
    <param-value>net.sf.acegisecurity.util.FilterChainProxy</param-value>
    </init-param>
    </filter>

    <filter-mapping>
    <filter-name>Acegi Filter Chain Proxy</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>


    <!-- Setup a listener to connect spring with the web context -->
    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>


    <!-- Setup ACEGI to subscribe to http session events in the web context -->
    <listener>
    <listener-class>net.sf.acegisecurity.ui.session.HttpSessionE ventPublisher</listener-class>
    </listener>



    <!-- Welcome File List -->
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    </web-app>

    and my beans.xml has the following code

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

    <beans>


    <!-- sample code starts -->
    <bean id="loginIF" class="com.sis.login.pattern.LoginImpl"/>

    <bean name="/loginSubmit"
    class="com.sis.login.handlers.LoginAction">
    <property name="loginIF">
    <ref bean="loginIF"/>
    </property>
    </bean>

    <bean id="filterChainProxy" class="net.sf.acegisecurity.util.FilterChainProxy" >
    <property name="filterInvocationDefinitionSource">
    <value>
    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
    PATTERN_TYPE_APACHE_ANT
    /**=httpSessionContextIntegrationFilter, authenticationProcessingFilter, anonymousProcessingFilter, securityEnforcementFilter
    </value>
    </property>
    </bean>


    <!-- The first item in the Chain: httpSessionContextIntegrationFilter -->
    <bean id="httpSessionContextIntegrationFilter" class="net.sf.acegisecurity.context.HttpSessionCon textIntegrationFilter">
    <property name="context">
    <value>net.sf.acegisecurity.context.security.Secur eContextImpl</value>
    </property>
    </bean>


    <!-- the second item in the chain: authenticationProcessingFilter -->
    <bean id="authenticationProcessingFilter" class="net.sf.acegisecurity.ui.webapp.Authenticati onProcessingFilter">
    <property name="authenticationManager"><ref bean="authenticationManager"/></property>
    <property name="authenticationFailureUrl"><value>/Login.jsp</value></property>
    <property name="defaultTargetUrl"><value>/secured/</value></property>
    <property name="alwaysUseDefaultTargetUrl"><value>true</value></property>
    <property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
    </bean>

    <bean id="filterInvocationInterceptor" class="net.sf.acegisecurity.intercept.web.FilterSe curityInterceptor">
    <property name="authenticationManager"><ref bean="authenticationManager"/></property>
    <property name="accessDecisionManager"><ref local="httpRequestAccessDecisionManager"/></property>
    <property name="objectDefinitionSource">
    <value>
    CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
    PATTERN_TYPE_APACHE_ANT
    /login/Login.jsp*=ROLE_ANONYMOUS,ROLE_USER,ROLE_ADMIN
    /secured*=ROLE_ADMIN
    /**=ROLE_USER
    </value>
    </property>
    </bean>
    <!-- authenticationManager defined above -->

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

    <bean id="roleVoter" class="net.sf.acegisecurity.vote.RoleVoter"/>

    <bean id="authenticationProcessingFilterEntryPoint" class="net.sf.acegisecurity.ui.webapp.Authenticati onProcessingFilterEntryPoint">
    <property name="loginFormUrl"><value>/acegilogin.jsp</value></property>
    <property name="forceHttps"><value>false</value></property>
    </bean>

    <bean id="loggerListener" class="net.sf.acegisecurity.providers.dao.event.Lo ggerListener"/>

    </beans>

    It shows the following error messages.
    ERROR [main] (ContextLoader.java:205) - Context initialization failed
    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'authenticationProcessingFilter' defined in ServletContext resource [/WEB-INF/beans.xml]: Cannot resolve reference to bean 'authenticationManager' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'authenticationManager' is defined
    Caused by:
    org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'authenticationManager' is defined
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.getBeanDefinition(DefaultListab leBeanFactory.java:355)


    Is there anything i need to do in struts-confing.xml?
    Now, it has the following code

    <?xml version="1.0" encoding="ISO-8859-1" ?>

    <!DOCTYPE struts-config PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
    "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

    <struts-config>
    <form-beans>

    <form-bean name="LoginForm"
    type="com.sis.login.forms.LoginForm">
    </form-bean>


    </form-beans>

    <global-forwards type="org.apache.struts.action.ActionForward">
    <forward name="login" path="/login.do"/>

    </global-forwards>

    <action-mappings>
    <action path="/welcome" forward="/welcome.html"/>
    <action path="/login" forward="/login/Login.jsp"/>
    <action path="/loginSubmit"
    name="LoginForm"
    type="org.springframework.web.struts.DelegatingAct ionProxy"
    input="/login.do"
    validate="false"
    >
    <forward name="HomePage" path="/login/Home.jsp" />
    <forward name="LoginRepeat" path="/login/Login.jsp" />
    </action>

    </action-mappings>

    <message-resources parameter="ApplicationResources"/>


    <plug-in className="org.apache.struts.validator.ValidatorPl ugIn">
    <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
    </plug-in>


    <plug-in className="org.springframework.web.struts.ContextL oaderPlugIn">
    <set-property property="contextConfigLocation" value="/WEB-INF/beans.xml"/>
    </plug-in>
    </struts-config>

    Im not clear with the lines marked in orange color.
    Please give clarification.

    Thanks,

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Thats nothing to do with Struts. There is a bean missing called 'authenticationManager'. Take a look at the examples that ship with Acegi for a demo of the 'authenticationManager' bean.

  6. #6
    Join Date
    Jan 2007
    Posts
    6

    Default

    Even I include the authendicationManager bean, i get such bean not found error. While using filters in web.xml it shows some warning msg like "filter is not defined" , "filter mapping is not defined", "listener is not defined"

    <filter>
    <filter-name>Acegi Filter Chain Proxy</filter-name>
    <filter-class>net.sf.acegisecurity.util.FilterToBeanProxy</filter-class>
    <init-param>
    <param-name>targetClass</param-name>
    <param-value>net.sf.acegisecurity.util.FilterChainProxy</param-value>
    </init-param>
    </filter>

    <filter-mapping>
    <filter-name>Acegi Filter Chain Proxy</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>

    <listener>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    What does it mean? Please explain with examples. Also explain, when did we go for ACEGI? For concurrent session and url authendication we are using know?

    Thanks,

  7. #7
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you could post the web.xml and applicationContext.xml you are currently using that would be good. The stacktrace of the error would be good to. Its hard to understand what the problem is otherwise.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •