ciao a tutti,
ho creato una piccola applicazione in jsp e vorrei rendere alcune pagine visibili soltanto ad alcuni utenti presenti in un db e con particolari diritti di

accesso.

Ho seguito tutte le documentazioni on line [ufficiali e non] e da diversi giorni sono bloccato su un problema che non riesco a superare:

riesco tranquillamente ad accede al db e a visualizzare tutti i record [con varie sql].
Il problema sorge quando provo a fare il login: ho un utente registrato nella tabella 'utenti' con 'username'='linea' e 'password'='linea', mentre nella tabella 'tom_roles' è registrato con 'username'='linea' ed 'u_role'='admin'.
Il mio percorso è il seguente: vado alla pagina index.jsp; clicco sul link a page.jsp; vengo reindirizzato a 'login.jsp'; inserendo nel campo 'username' la parola 'linea' e nel campo 'password' la parola 'linea', vengo mandato alla pagina error_page.jsp, come se avessi digitato la password errata oppure l'utente 'linea' non esistesse...

Qualcuno mi può dare un mano?
Vi prego, non so più dove sbattere la testa...

Ho creato un db con 2 tabelle: 'utenti' [che tra i vari campi, contiene 'username' e 'password'] e 'tom_roles' [che contiene i campi 'username' e 'role'].

vi scrivo i codici dei files utilizzati:



file: index.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>I N D E X</title>
</head>
<body>
<h1>INDEX: Pagina iniziale</h1>


<h2>benvenuto</h2>


Pagina iniziale del sito bla bla bla bla







- Link alla pgina riservata all'amministratore here!</p>
</body>
</html>



file: pagex.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>****** private area ******</title>
</head>
<body>
<h1>Paginetta PRIVATA</h1>


!"£$%&/()=!"£$%§:çé:&/()=!"£$%&/()=!"£$%&/()=é*ç§:_*é

ç°:°:^*é:_?^*==/%£())/)%£éç:é:ç*é:çé*:çéç[]#@@[{}@

[]}è##§_:;>>&"£!"%/()()(=









<input type="submit" value="Logout" name="log_out" />
</body>
</html>



file:login.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Effettua il login</title>
</head>
<body>
<h1>Login</h1>


<form name="login_form" action="j_security_check" method="POST">
username:

<input type="text" name="j_username" size="30" />




password:

<input type="password" name=j_password" size="20" />




<input type="submit" value="login" name="logger" />
</form>
</body>
</html>



file: error_page.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>pagina di errore</title>
</head>
<body>
<h1>LOGIN ERRATO</h1>
</body>
</html>



file: web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<security-role>
<role-name>admin</role-name>
</security-role>

<resource-ref>
<description>jdbc:mysql//localhost:3306/login_db</description>
<res-ref-name>jdbc/connPool</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

<security-constraint>
<display-name>admin_constraint</display-name>

<web-resource-collection>
<web-resource-name>Admin_res</web-resource-name>
<description/>
<url-pattern>/secureAdmin/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>

<auth-constraint>
<description/>
<role-name>admin</role-name>
</auth-constraint>
<user-data-constraint><transport-guarantee>NONE</transport-guarantee></user-data-constraint>
</security-constraint>

<login-config>
<auth-method>FORM</auth-method>
<realm-name>tom_realm</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error_page.jsp</form-error-page>
</form-login-config>
</login-config>
</web-app>



file: context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/auth_exp_01">
<Resource auth="Container"
name="jdbc/connPool"
driverClassName="com.mysql.jdbc.Driver"
maxActive="100" maxIdle="30" maxWait="5000"
username="root"
password="[password_del_db]"
type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/login_db"/>

<Realm className="org.apache.catalina.realm.DataSourceRea lm"
userTable="utenti"
userNameCol="username"
userCredCol="password"
userRoleTable="tom_roles"
roleNameCol="u_role"
localDataSource="true"
dataSourceName="jdbc/connPool"/>
</Context>
index.jsp index.jsp