Boa tarde pessoas,
Estou tentando implementar JAAS em um sistema, e pra isso estou seguindo este tutorial pra aprender o básico sobre ele:
http://blog.hallanmedeiros.com/2009/07/21/jaas-como-utilizar-jaas-com-jsp-tomcat/
http://blog.hallanmedeiros.com/2010/05/26/jaas-como-utilizar-com-banco-de-dados/
O primeiro ensina como tudo deve ser feito para a autorização ser feita completamente via tomcat, e o segundo usando banco de dados.
No segundo link, podem ver:
A partir desta estrutura, é possível utilizar o JAAS com banco de dados, configurando o arquivo context.xml, incluindo a seguinte tag:
Onde crio esse arquivo do Realm?
Fiz o exemplo inteiro aqui, mas dá sempre acesso negado.
Seguem minhas páginas jsp:
PÁGINA DE LOGIN
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="j_security_check">
<table align="center" cellpadding="0" cellspacing="0">
<tr>
<td> LOGIN </td>
<td> <input type="text" name="j_username" /> </td>
</tr>
<tr>
<td> SENHA </td>
<td> <input type="password" name="j_password"/> </td>
</tr>
<tr>
<td> </td>
<td align="right"> <input type="submit" value="LOGAR" /> </td>
</tr>
</table>
</form>
</body>
</html>
PÁGINA DE ERRO NO LOGIN
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Erro login</title>
</head>
<body>
<h3>Acesso Negado!</h3>
</body>
</html>
PÁGINA DO ADMIN LOGADO
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
PÁGINA DE USUÁRIO LOGADO
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</body>
</html>
MEU web.xml COM AS ROLES
<?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_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>teste-jaas</display-name>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/erro.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<role-name>ADMINISTRADOR</role-name>
</security-role>
<security-role>
<role-name>USUARIO</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>secured</web-resource-name>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>ADMINISTRADOR</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<web-resource-collection>
<web-resource-name>secured</web-resource-name>
<url-pattern>/usuario/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>USUARIO</role-name>
</auth-constraint>
</security-constraint>
<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>
</web-app>
A grande dúvida é: onde crio o xml que deve informar o banco, driver, e tabelas com as roles?
Achei um site gringo aqui que dizia que dever ser add essa parte do Realm no server.xml, mas sempre que o Tomcat é reiniciado, obviamente essa configuração é perdida.
Tô deixando ele dentro da pasta WEB-INF, mas não funciona.
Quem puder dar uma luz, fico muito grato.
Muito obrigado desde já, abraços.