Olá,
estou usando windows 7 (64bits),java 6,tomcat 7,eclipse helios.
ao rodar executa a pagina index.jsp clico no item admin e solicita usuario e senha
digito mais aparece a mensagem :
não sei mais o que fazer me parece que não acessa o banco …como verificar se está acessando o banco…
help…help…help
HTTP Status 403 - Access to the requested resource has been denied
type Status report
message Access to the requested resource has been denied
description Access to the specified resource (Access to the requested resource has been denied) has been forbidden.
Apache Tomcat/7.0.4
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/learn-jaas-jdbc" docBase="learn-jaas-jdbc"
>
<!--configuracao de conexao com banco de dados-->
<Resource name="jdbc/learn-jaas-jdbc"
auth="Container"
type="javax.sql.DataSource"
username="root"
password="paulo"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/learn_jaas?autoReconnect=true"
maxActive="8"
maxIdle="4"/>
<!--configuracao para login-->
<Realm className="org.apache.catalina.realm.DataSourceRealm"
debug="99"
dataSourceName="jdbc/learn-jaas-jdbc"
localDataSource="true"
userTable="usertable"
userNameCol="userid"
userCredCol="password"
userRoleTable="grouptable"
roleNameCol="groupid"/>
</Context>
web.xml
<display-name>project-to-learn-jaas</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>learn-jaas-realm</realm-name>
</login-config>
<security-constraint>
<web-resource-collection>
<web-resource-name>paginas admnistrativas</web-resource-name>
<url-pattern>/admin/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin-role</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>paginas para usuários</web-resource-name>
<url-pattern>/users/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>user-role</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>paginas para visitantes</web-resource-name>
<url-pattern>/public/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>guest-role</role-name>
</auth-constraint>
</security-constraint>
<!-- Configuração do DataSource. -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<resource-ref>
<description>Web Database</description>
<res-ref-name>jdbc/learn-jaas-jdbc</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
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>Project to learn JAAS</title>
</head>
<body>
<h1>Acessar páginas administrativas <a >>>></a></h1>
<h1>Acessar páginas para usuários <a >>>></a></h1>
<h1>Acessar páginas para visitantes <a >>>></a></h1>
</body>
</html>
CREATE DATABASE learn_jaas;
USE learn_jaas;
CREATE TABLE usertable(userid VARCHAR(10) PRIMARY KEY, password VARCHAR(32) NOT NULL);
CREATE TABLE grouptable(userid VARCHAR(10), groupid VARCHAR(20) NOT NULL, PRIMARY KEY (userid, groupid));
ALTER TABLE grouptable ADD CONSTRAINT FK_USERID FOREIGN KEY(userid) REFERENCES usertable(userid);
COMMIT;
INSERT INTO usertable VALUES ('user', 'user');
INSERT INTO grouptable VALUES ('user', 'users');
INSERT INTO usertable VALUES ('guest', 'guest');
INSERT INTO grouptable VALUES ('guest', 'users');
INSERT INTO usertable VALUES ('admin', 'admin');
INSERT INTO grouptable VALUES ('admin', 'admins');
\admin\index.jsp
<h1>Olá Administrador!</h1>