Authentication is not working, spring-security, spring mvc, hibernate, stringTemplate
Hi, I am a newbie in spring,
Authentication is not working, what is going on, i don`t know where is the problem. Help me :) I`m using spring mvc 2.5 spring-security 2.0, Hibernate 3.0 and stringTemplate.
Here is my code:
web.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/jshop-servlet.xml,
/WEB-INF/applicationContext-security.xml
</param-value>
</context-param>
<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>
<filter>
<filter-name>encoding-filter</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>
</filter>
<filter-mapping>
<filter-name>encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>jshop</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jshop</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
applicationContext-security.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
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-2.5.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-2.0.2.xsd">
<global-method-security secured-annotations="enabled"></global-method-security>
<http auto-config="true">
<intercept-url pattern="/logged*" access="ROLE_USER,ROLE_ADMIN" />
<intercept-url pattern="/**" access="ROLE_ANONYMOUS" />
<!-- <intercept-url pattern="/add_product.html" access="ROLE_ADMIN" />-->
<logout logout-success-url="/login.html" />
<form-login authentication-failure-url="/login.html?login_error=1"
login-page="/login.html" default-target-url="/logged.html" />
</http>
<authentication-provider>
<jdbc-user-service data-source-ref="myDataSource"
users-by-username-query="select username, password, enabled from users where username=?" />
</authentication-provider>
</beans:beans>
login.st
Code:
Log in:
<form action="j_spring_security_check">
$if(login_error)$
<br />
<b>Wrong login or password!</b><br />
$endif$
<table>
<tr>
<td> <label for="j_username">Username: </label> </td>
<td> <input type="text" name="j_username" id="j_username" /> </td>
</tr>
<tr>
<td> <label for="j_password">Password: </label> </td>
<td> <input type="password" name="j_password" id="j_password"/> </td>
</tr>
<!--<tr> <td> <input type='checkbox' name='_spring_security_remember_me'/> </td><td> Remember me on this computer. </td></tr>-->
<tr>
<td> <input class="button" type="submit" value="Login"/> </td>
</tr>
</table>
</form>
logged.st
Code:
<div id="posts">
[ <a href="j_spring_security_logout"><b>logout</b></a> ]
<br /><br /> You are logged! :)
<sec:authorize ifAllGranted="ROLE_ADMIN">
<p>Administrator</p>
</sec:authorize>
<sec:authorize ifAllGranted="ROLE_USER">
<p>User</p>
</sec:authorize>
</div>
please help me!!