aspose file tools*
The moose likes Spring and the fly likes Spring 3 + Spring Security 3 + Struts2 + Hibernate 3 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring 3 + Spring Security 3 + Struts2 + Hibernate 3" Watch "Spring 3 + Spring Security 3 + Struts2 + Hibernate 3" New topic
Author

Spring 3 + Spring Security 3 + Struts2 + Hibernate 3

gozi nain
Greenhorn

Joined: Feb 24, 2011
Posts: 1
Hello everybody. (Sorry for my english)
Im trying to get a architecture with Spring 3 + Spring Security 3 + Struts2 + Hibernate 3.

The app go right with Spring 3 + Struts2 + Hibernate 3 but I can not get anything with Spring Security.
None error is throwed by app.
Login.action and the following JSP load fine but when I push over submit button (j_spring_security_check), nothing happend and the default action PaginaNoEncontrada (Page not Found) is loaded

┬┐Why does it work?
Thanks in advance.

That is my configuration code:

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">

<display-name>cv</display-name>

<!--SPRING SECURITY-->
<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>
<!--SPRING SECURITY-->


<!--SPRING-->
<listener>
<listener-class >org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/applicationContext-dao.xml
/WEB-INF/spring/applicationContext-transaction.xml
/WEB-INF/spring/applicationContext-service.xml
<!--Spring Security Context-->
/WEB-INF/spring/applicationContext-security.xml
</param-value>
</context-param>
<!--SPRING-->


<!--STRUTS 2-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--STRUTS 2-->

<!--TILES-->
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>

<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles/tiles-def.xml,/WEB-INF/tiles/tiles-def-acciones.xml</param-value>
</context-param>
<!--TILES-->

<!--WEB-LISTENER-->
<listener>
<listener-class>es.cv.comun.listeners.LoadProperties</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

<error-page>
<error-code>403</error-code>
<location>/error.html</location>
</error-page>
</web-app>

struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.custom.i18n.resources" value="global.application, global.errores" />

<include file="example.xml"/>

<package name="default" namespace="/" extends="struts-default">
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>

<!--INTERCEPTORS-->
<interceptors>
<interceptor name="noAction" class="es.cv.comun.interceptor.noActionInterceptor" />
<interceptor-stack name="loggingStack">
<interceptor-ref name="noAction" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>

<default-interceptor-ref name="loggingStack"></default-interceptor-ref>

<!--DEFAULT-ACTION-->
<default-action-ref name="PaginaNoEncontrada" />

<!--GLOBAL RESULT-->
<global-results>
<result name="errorGeneral" type="tiles">errorGeneral</result>
</global-results>

<!--EXCEPTIONS-->
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error.errorGeneral"/>
<exception-mapping exception="java.lang.RuntimeException" result="error.errorGeneral"/>
<exception-mapping exception="comun.exceptions.AppException" result="error.errorGeneral"/>
<exception-mapping exception="comun.exceptions.BadArgumentException" result="error.errorGeneral"/>
<exception-mapping exception="comun.exceptions.FileException" result="error.errorGeneral"/>
<exception-mapping exception="comun.exceptions.SystemException" result="error.errorGeneral"/>
</global-exception-mappings>

<!--ACTIONS-->
<action name="PaginaNoEncontrada">
<result type="tiles">paginaNoEncontrada</result>
</action>

<action name="Login" class="es.cv.Login">
<result name="input">/jsp/pages/Login.jsp</result>
<result name="languaje">/jsp/pages/Login.jsp</result>
</action>
</package>
</struts>

applicationContext-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">

<security:http auto-config="true" use-expressions="true" access-denied-page="/cv/denied.jsp" >

<security:intercept-url pattern="/cv/*" access="permitAll"/>
<security:intercept-url pattern="/cv/css/*" access="permitAll"/>
<security:intercept-url pattern="/cv/js/*" access="permitAll"/>
<security:intercept-url pattern="/cv/img/*" access="permitAll"/>
<security:intercept-url pattern="/cv/jsp/*" access="permitAll"/>

<security:intercept-url pattern="/cv/Login.action" filters="none"/>
<security:intercept-url pattern="/cv/example/*" access="isFullyAuthenticated()"/>

<security:form-login
login-page="/cv/Login.action"
default-target-url="/cv/example/HelloWorld.action"
authentication-failure-url="/cv/Login.action?error=true"/>

<security:logout
invalidate-session="true"
logout-success-url="/cv/Login.action"
logout-url="/cv/Login.action"/>

</security:http>

<bean class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" id="passwordEncoder"/>

<bean id="customUserDetailsService" class="es.cv.business.services.impl.SpringSecurityService"/>

<security:authentication-manager>
<security:authentication-provider user-service-ref="customUserDetailsService">
<security:password-encoder ref="passwordEncoder"/>
</security:authentication-provider>
</security:authentication-manager>

</beans>

login.jsp
<%@include file="/jsp/meta/meta.jsp"%>
<html>
<head>
<title>Sign On</title>
</head>
<body>
<s:form action="j_spring_security_check" method="post">
<s:textfield key="j_username"/>
<s:password key="j_password" />
<s:submit key="entrar"/>
</s:form>

</body>
</html>
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

Please use the CODE tags to post code or xml, so that indentation remains and it is readable. The Code button above is what you use to add CODE tags.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Daniel Henry
Greenhorn

Joined: Mar 26, 2012
Posts: 1
use a regular <form> tag instead of <s:form>

<form id="LoginForm" method="POST" action="<s:url value='j_spring_security_check'/>" >

When you use <s:form> it actually posts it to j_spring_security_check.action, which obviously won't do anything.

Hope that helps.
Cheo Gomez
Greenhorn

Joined: Jan 24, 2012
Posts: 25
Hi, Im trying to do the same, could you please send me the code of your example?
thank you very much
Muhammad Abdul Arif
Greenhorn

Joined: Feb 04, 2012
Posts: 25
The url /j_spring_security_check doesnot match the pattern urls you provided below. so filters are not getting invoked.




You can do two things.
1) change the url j_spring_check_security to match below given patterns or
2)or add a new pattern for /j_spring_security_check as below
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring 3 + Spring Security 3 + Struts2 + Hibernate 3