Salut tout le monde,
Je suis demandé de faire tourner un exemple d'authentification, mais rien ne fonctionne.
j'utilise tomcat8, spring-security 4.

web.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID"
    version="3.1">
    <display-name>springsec</display-name>
    <display-name>Sample Spring Maven Project</display-name>
 
    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
 
    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
 
    </servlet-mapping>
 
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>  
   /WEB-INF/mvc-dispatcher-servlet.xml,  
   /WEB-INF/security-config.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>
 
    <welcome-file-list>
        <welcome-file>/WEB-INF/login.jsp</welcome-file>
    </welcome-file-list>
 
</web-app>
mvc-dispatcher-servlet.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?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:context="http://www.springframework.org/schema/context"  
 xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"  
 xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd  
  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  
  http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd  
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">  
 
 <context:component-scan base-package="com.myqiservices.reporting.controller" />  
 <mvc:annotation-driven />  
  <mvc:default-servlet-handler/>
<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/k_qis_rct" />  
  <property name="username" value="root" />  
  <property name="password" value="root" />  
 </bean>  
 
 <bean  
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
  <property name="prefix">  
   <value>/webapp/WEB-INF/pages/</value>  
  </property>  
  <property name="suffix">  
   <value>.jsp</value>  
  </property>  
 </bean>  
 
 
</beans>
security-config.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?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-4.0.xsd  
 http://www.springframework.org/schema/security  
 http://www.springframework.org/schema/security/spring-security-4.0.xsd">  
 
 <http auto-config="true">  
  <access-denied-handler error-page="/403page" />  
  <intercept-url pattern="/user**" access="ROLE_USER" />  
  <intercept-url pattern="/admin**" access="ROLE_ADMIN" />  
  <form-login login-page='/pages/login' username-parameter="username"  
   password-parameter="password" default-target-url="/user"  
   authentication-failure-url="/login?authfailed" />  
  <logout logout-success-url="/login?logout" />  
 </http>  
 
 <!-- <authentication-manager> <authentication-provider> <user-service> <user   
  name="user" password="user@123" authorities="ROLE_ADMIN" /> </user-service>   
  </authentication-provider> </authentication-manager> -->  
 
 <authentication-manager>  
  <authentication-provider>  
   <jdbc-user-service data-source-ref="dataSource"  
    users-by-username-query="select username,password, enabled from users where username=?"  
    authorities-by-username-query="select username, role from user_roles where username =?  " />  
  </authentication-provider>  
 </authentication-manager>  
 
</beans:beans>
/WEB-INF/pages/login.jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
<html>  
<head>  
<title>Login Form</title>  
</head>  
<body>  
 <center>  
 
 
 
 
  <h2>Login Here</h2>  
 
 
  <div style="text-align: center; padding: 30px;border: 1px solid green;width: 250px;">  
   <form method="post" action="<c:url value='j_spring_security_check' />">  
 
    <table>  
     <tr>  
      <td colspan="2" style="color: red">${message}</td>  
 
     </tr>  
     <tr>  
      <td>User Name:</td>  
      <td><input type="text" name="username" />  
      </td>  
     </tr>  
     <tr>  
      <td>Password:</td>  
      <td><input type="password" name="password" />  
      </td>  
     </tr>  
     <tr>  
      <td> </td>  
      <td><input type="submit" value="Login" />  
      </td>  
 
     </tr>  
    </table>  
   </form>  
  </div>  
 </center>  
</body>  
</html>
merci de m'indiquer c'est quoi mon erreur?