E ai pessoal tudo bem!!!
Estou tentando fazer um aplicação de exemplo para aprender JAAS usando GlassFish v2.
Estou utilizando um formulário e quero pegar os dados do usuário pelo Banco, usando JDBC Realm.
Sei que existem artigos aqui no GUJ sobre JAAS com TOMCAT, mas gostaria de aprender usando o
glassfish.
Fui no console Adm do GlassFish e já criei um pool Connection e o ping ocorreu com sucesso acessando o MySQL
Criei um JDBC Resources
e depois criei um Realm.
Este é o meu sun-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
<sun-web-app error-url="">
<context-root>/TesteNavegacao3</context-root>
<security-role-mapping>
<role-name>user-role</role-name>
<group-name>gerente</group-name>
<group-name>vendedor</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>admin-role</role-name>
<group-name>gerente</group-name>
</security-role-mapping>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</sun-web-app>
Este é o meu 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-constraint>
<display-name>Restrição 1</display-name>
<web-resource-collection>
<web-resource-name>paginas admnistrativas</web-resource-name>
<url-pattern>/acesso1/*</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>
<display-name>Restrição 2</display-name>
<web-resource-collection>
<web-resource-name>paginas para usuários</web-resource-name>
<url-pattern>/acesso2/*</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>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>testeRealm</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/Erro.jsp</form-error-page>
</form-login-config>
</login-config>
</web-app>
Este é o meu Banco de Dados:
DROP TABLE IF EXISTS `testenavegacao`.`grupo_usuario`;
CREATE TABLE `testenavegacao`.`grupo_usuario` (
`grupo` varchar(45) NOT NULL,
`login` varchar(45) NOT NULL,
PRIMARY KEY (`grupo`,`login`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
DROP TABLE IF EXISTS `testenavegacao`.`usuario`;
CREATE TABLE `testenavegacao`.`usuario` (
`LOGIN` varchar(45) NOT NULL,
`SENHA` varchar(45) NOT NULL,
PRIMARY KEY (`LOGIN`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Esta é minha pagina de Login.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form method="POST" name="form" action="j_security_check">
<table border="1">
<tbody>
<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><input type="submit" value="Login" /></td>
<td></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Sempre que tento acessar uma pagina dentro do diretório acesso1/* a pagina de login aparece, mesmo digitando o usuario e senha corretos
ele me direciona para a pagina de Erro.jsp, acontece o mesmo quando tento acessar as paginas dentro do diretório acesso2/*
Caso esteja faltando alguma etapa, ou algo que esteja errado me avisem por favor!!!