Spring Security configuration
salut ,
je travaille avec Spring security , et je trouve beaucoup de probleme :?
j`ai construit la page jsp : Authentification.jsp comme ca :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<%@ taglib prefix='c' uri='http://java.sun.com/jstl/core_rt' %>
<%@ page import="org.springframework.security.ui.AbstractProcessingFilter" %>
<%@ page import="org.springframework.security.ui.webapp.AuthenticationProcessingFilter" %>
<%@ page import="org.springframework.security.AuthenticationException" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Autehentification</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<body>
<c:if test="${not empty param.login_error}">
<font color="red">
Your login attempt was not successful, try again.<br/><br/>
Reason: <c:out value="${SPRING_SECURITY_LAST_EXCEPTION.message}"/>.
</font>
</c:if>
<form name="f" action="<c:url value='j_spring_security_check'/>" method="post">
<table width="350px" align="center" style="border: 1px solid #000000; background-color: #efefef;">
<tr>
<td colspan=2></td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
Please identify yourself with a username and password:
<tr> </tr>
<br> </br>
<tr><td>User or mail:</td><td><input type='text' name='j_username' value='<c:if test="${not empty param.login_error}"><c:out value="${SPRING_SECURITY_LAST_USERNAME}"/></c:if>'/></td></tr>
<tr><td>Password:</td><td><input type='password' name='j_password'></td></tr>
<tr><td><input type="checkbox" name="_spring_security_remember_me"></td><td>Don't ask for my password for two weeks</td></tr>
<tr>
<td></td>
<td><input type="submit" name="Submit" value="Login"> <input name="reset" type="reset" value="Reset"></td>
</tr>
<tr>
<td colspan=2> </td>
</tr>
</table>
</form>
</body>
</html> |
et j`ai configuré le springseurity comme ca
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
<?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:util="http://www.springframework.org/schema/util"
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/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd">
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/proxym_data_base" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<security:http>
<security:form-login login-page="/Authentification.htm" authentication-failure-url="/accessDenied.htm?login_error=true" />
<security:intercept-url pattern="/acceuil.htm" access="ROLE_ADMIN"/>
<security:intercept-url pattern="/acceuil.htm" access="ROLE_ADMIN"/>
<security:intercept-url pattern="/acceuil.htm" access="IS_AUTHENTICATED_FULLY" />
<security:logout/>
</security:http>
<security:authentication-provider>
<security:password-encoder hash="md5" >
<security:salt-source system-wide="MySalt"/>
</security:password-encoder>
<security:jdbc-user-service data-source-ref="dataSource" authorities-by-username-query="select firstame,password from employees where firstame =?"/>
</security:authentication-provider>
<security:global-method-security secured-annotations="enabled">
<security:protect-pointcut
expression="execution(* com.springsource..*Service.*(..))"
access="ROLE_USER" />
</security:global-method-security>
</beans> |
et pour le web.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
<?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>GRH_LIGHT_Proxymit</display-name>
<!--
- Filtre springSecurityFilterChain
-->
<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>
<!--
- ContextLoaderListener : chargement fichiers de définition de beans
-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
- Fichiers XML de configuration, à charger par le ContextLoaderListener
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/security-applicationContext.xml,
/WEB-INF/dispatcher-servlet.xml
</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app> |
le problème :
- si je lance mon programme il faut que je vois la page d`authentification et ce n`est pas le cas ?? donc je la lance moi même pour vérifier
-la requete sql que j`ai ecrit dans le springsecurity.xml ne marche pas pourtant j`ai fait un bean pour le data source comme deja mentionné et toujours il m`affiche un message :
Code:
1 2 3 4
|
Your login attempt was not successful, try again.
Reason: PreparedStatementCallback; bad SQL grammar [SELECT username,password,enabled FROM users WHERE username = ?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: La table 'proxym_data_base.users' n'existe pas; nested exception is org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT username,password,enabled FROM users WHERE username = ?]; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: La table 'proxym_data_base.users' n'existe pas |
et j`ai pas une table users et je ne sais pas d`ou elle arrive parsque je n`est pas mentionné cette base dans ma requête ??
qlq 1 peut m`aider :?:?