Nop, still the same error. It's so weird, I really can´t believe it.Is there a
sample appliaction of Struts + Acegi out there? I have found snippets, but not
a single complete
application.Thanks!########################web.xml#####################<?xml
version="1.0" encoding="UTF-8"?><web-app
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>ACI_AME</display-name> <context-param>
<param-name>contextConfigLocation</param-name> <param-value>
/WEB-INF/classes/applicationContextSeguridad.xml
/WEB-INF/classes/applicationContext-dao.xml </param-value>
</context-param> <filter>
<filter-name>FiltroFilterChainProxy</filter-name>
<filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
<init-param> <param-name>targetClass</param-name>
<param-value>org.acegisecurity.util.FilterChainProxy</param-value>
</init-param> </filter> <filter-mapping>
<filter-name>FiltroFilterChainProxy</filter-name>
<url-pattern>*.do</url-pattern> </filter-mapping>
<filter-mapping>
<filter-name>FiltroFilterChainProxy</filter-name>
<url-pattern>/j_acegi_security_filter</url-pattern> </filter-mapping>
<listener> <listener-class>
org.springframework.web.context.ContextLoaderListener </listener-class>
</listener> <listener> <listener-class>
com.xxx.yyy.utils.PropertiesLoader </listener-class> </listener>
<servlet> <servlet-name>action</servlet-name> <servlet-class>
org.apache.struts.action.ActionServlet </servlet-class>
<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>2</param-value> </init-param> <init-param>
<param-name>detail</param-name> <param-value>2</param-value>
</init-param> <init-param> <param-name>validate</param-name>
<param-value>true</param-value> </init-param>
<load-on-startup>2</load-on-startup> </servlet> <servlet>
<description>This is the description of my J2EE component</description>
<servlet-name>RedirigirPaginaInicio</servlet-name>
<servlet-class>com.xxx.yyy.utils.RedirigirPaginaInicio</servlet-class>
<init-param> <param-name>paginaInicio</param-name>
<param-value>/WEB-INF/login.jsp</param-value> </init-param>
</servlet> <servlet-mapping>
<servlet-name>RedirigirPaginaInicio</servlet-name>
<url-pattern>/paginainicio</url-pattern> </servlet-mapping>
<servlet-mapping> <servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list>
<welcome-file>userLogin.jsp</welcome-file>
</welcome-file-list></web-app>#####################################################struts-cofig.xml##################################################<?xml
version="1.0" encoding="UTF-8"?><!DOCTYPEstruts-config PUBLIC "-//Apache
Software Foundation//DTD StrutsConfiguration
1.1//EN""http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><struts-config>
<data-sources /> <form-beans > <form-bean name="userLoginForm"
type="com.xxx.yyy.struts.form.UserLoginForm" /> </form-beans> <!--
Global Exception Definitions --> <global-exceptions> <exception
key="errors.acegi.accesoDenegado"type="org.acegisecurity.AccessDeniedException"handler="com.xxx.yyy.struts.exceptions.AcegiExceptionHandler"
/> </global-exceptions> <!-- Global Forward Definitions -->
<global-forwards> <forward name="error" path="/WEB-INF/page/error.jsp"/>
<forward name="errorAcegi" path="/WEB-INF/page/errorAcegi.jsp" />
</global-forwards> <action-mappings > <action
attribute="userLoginForm" input="/userLogin.jsp" name="userLoginForm"
path="/userLogin" scope="request"
type="com.xxx.yyy.struts.action.UserLoginAction"> <forward name="success"
path="/WEB-INF/page/userLoginSuccess.jsp" /> <forward name="failure"
path="/userLogin.jsp" /> </action> </action-mappings> <message-resources
parameter="com.xxx.yyy.struts.ApplicationResources"
/></struts-config>################################security
context############################<?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="filterChainProxy" class="org.acegisecurity.util.FilterChainProxy">
<property name="filterInvocationDefinitionSource"> <value>
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/*.do*=httpSessionContextIntegrationFilter,authenticationProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor</value>
</property> </bean> <bean id="passwordEncoder"
class="org.acegisecurity.providers.encoding.Md5PasswordEncoder"/> <bean
id="httpSessionContextIntegrationFilter"class="org.acegisecurity.context.HttpSessionContextIntegrationFilter"/>
<bean id="authenticationProcessingFilter"
class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
<property name="authenticationManager"> <ref
local="authenticationManager" /> </property> <property
name="authenticationFailureUrl">
<value>/userLogin.jsp?login_error=errors.credenciales.novalidos</value>
</property> <property name="defaultTargetUrl">
<value>/</value> </property> <property name="filterProcessesUrl">
<value>/j_acegi_security_check</value> </property> </bean>
<bean id="authenticationManager"
class="org.acegisecurity.providers.ProviderManager"> <property
name="providers"> <list> <ref
local="daoAuthenticationProvider" /> </list> </property>
</bean> <bean id="filterInvocationInterceptor"
class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
<property name="authenticationManager"> <ref
local="authenticationManager" /> </property> <property
name="accessDecisionManager"> <ref local="accessDecisionManager" />
</property> <property name="objectDefinitionSource">
<value> CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/buscadorperfiles.do*=ROLE_ADMIN,ROLE_TODO
/*.do*=ROLE_ADMIN,ROLE_TODO </value> </property> </bean>
<bean id="authenticationEntryPoint"
class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
<property name="loginFormUrl">
<value>/userLogin.jsp?login_error=errors.credenciales.novalidos</value>
</property> <property name="forceHttps"> <value>false</value>
</property> </bean> <bean id="daoAuthenticationProvider"
class="org.acegisecurity.providers.dao.DaoAuthenticationProvider"> <!--
En memoria <property name="authenticationDao"><ref
bean="administradoresDAO"/></property> --> <!-- En bbdd -->
<property name="userDetailsService"> <ref
bean="administradoresJDBCDAO" /> </property> <!-- Cache -->
<property name="userCache"> <ref bean="userCache" />
</property> <property name="passwordEncoder"><ref
local="passwordEncoder"/></property> </bean> <bean
id="administradoresJDBCDAO"
class="org.acegisecurity.userdetails.jdbc.JdbcDaoImpl"> <property
name="dataSource"> <ref bean="basicDataSource" /> </property>
<property name="usersByUsernameQuery"> <value>select idusuario
as username, password aspassword,'1' as enabled FROM usuarios WHERE
idusuario=?</value> </property> <property
name="authoritiesByUsernameQuery"> <value>select idusuario as
username, CONCAT('ROLE_',idperfil) from usuarios where idusuario=?</value>
</property> </bean> <bean id="userCache"
class="org.acegisecurity.providers.dao.cache.EhCacheBasedUserCache">
<property name="cache"> <ref local="userCacheBackend" />
</property> </bean> <bean id="userCacheBackend"
class="org.springframework.cache.ehcache.EhCacheFactoryBean"> <property
name="cacheManager"> <ref local="cacheManager" /> </property>
<property name="cacheName"> <value>userCache</value>
</property> </bean> <bean id="cacheManager"
class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation">
<value>classpath:/ehcache-failsafe.xml</value> </property> </bean>
<bean
id="authenticationProcessingFilterEntryPoint"class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint">
<property name="loginFormUrl"> <value>/userLogin.jsp</value>
</property> <property name="forceHttps">
<value>false</value> </property> </bean> <bean
id="exceptionTranslationFilter"
class="org.acegisecurity.ui.ExceptionTranslationFilter"> <property
name="authenticationEntryPoint"> <ref
bean="authenticationProcessingFilterEntryPoint" /> </property>
<property name="accessDeniedHandler"> <bean
class="org.acegisecurity.ui.AccessDeniedHandlerImpl"> <property
name="errorPage" value="/login.jsp" /> </bean> </property>
</bean> <bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter" />
<bean id="accessDecisionManager"
class="org.acegisecurity.vote.AffirmativeBased"> <property
name="allowIfAllAbstainDecisions"> <value>false</value>
</property> <property name="decisionVoters"> <list>
<ref local="roleVoter" /> </list> </property> </bean>
</beans>#################################login.jsp############################<%@
page language="java"%><%@ taglib
uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%><%@ taglib
uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%><%@ taglib
uri="http://java.sun.com/jstl/fmt" prefix="fmt"%><%@ taglib
uri="http://java.sun.com/jstl/core" prefix="c" %> <html> <head>
<fmt:setBundle basename="com.xxx.yyy.struts.ApplicationResources" />
<title><fmt:message key="login.page.title" /> </title> </head>
<body> <html:messages id="message" message="true">
<bean:write name="message" /> <br /> </html:messages>
<html:form action="/j_acegi_security_check" name="userLoginForm">
username : <html:text property="j_username" name="j_username" />
<html:errors property="j_username" /> <br />
password : <html:password property="j_password" name="j_password" />
<html:errors property="j_password" /> <br /> <html:submit
/> </html:form>
</body></html>#################################com.xxx.yyy.struts.action.UserLoginAction
##############################package com.xxx.yyy.struts.action;import
javax.servlet.http.HttpServletRequest;import
javax.servlet.http.HttpServletResponse;import
org.acegisecurity.Authentication;import
org.acegisecurity.context.SecurityContext;import
org.apache.commons.logging.Log;import
org.apache.commons.logging.LogFactory;import
org.apache.struts.action.Action;import
org.apache.struts.action.ActionForm;import
org.apache.struts.action.ActionForward;import
org.apache.struts.action.ActionMapping;import
org.apache.struts.action.ActionMessage;import
org.apache.struts.action.ActionMessages;import
com.xxx.yyy.struts.form.UserLoginForm;import
com.xxx.yyy.utils.SpringFactory;import com.xxx.yyy.data.dao.UsuariosDao;import
com.xxx.yyy.data.dto.Usuarios;import
com.xxx.yyy.data.exceptions.UsuariosDaoException;/** * * XDoclet definition:
* @struts.action path="/userLogin" name="userLoginForm" input="/userLogin.jsp"
scope="request" validate="true" * @struts.action-forward name="success"
path="/userLoginSuccess.jsp" * @struts.action-forward name="failure"
path="/userLogin" */public class UserLoginAction extends Action { private
static Log log = LogFactory.getFactory().getInstance(UserLoginAction.class);
public ActionForward execute( ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) { log.info("...LoginAction:
execute..."); ActionMessages messages = new ActionMessages();
ActionMessage message = new ActionMessage("");
Authentication authentication
=((SecurityContext)request.getSession().getAttribute("ACEGI_SECURITY_CONTEXT")).getAuthentication();
UsuariosDao usuarios =
(UsuariosDao)SpringFactory.getBean("usuariosDaoHbn"); Usuarios usuario;
try { usuario =
usuarios.findWhereUsuarioEquals(authentication.getName()); } catch
(UsuariosDaoException e) { usuario=null; } //Se
comprueba si el usuario se ha validado correctamente if (usuario !=
null){ request.getSession().setAttribute("usuario",usuario);
log.info("LoginAction: antes del forward con el usuario validado");
return mapping.findForward("success"); }else{
message = new ActionMessage("error.validar.usuario");
messages.add("validarUsuario",message);
saveMessages(request,messages); return
mapping.findForward("failure"); } } }
_________________________________________________________________
Make every IM count. Download Windows Live Messenger and join the i’m
Initiative now. It’s free.
http://im.live.com/messenger/im/home/?source=TAGWL_June07