JAAS authentication doesn't work in Tomcat

Viewed 233

I'm trying to configure a sample configuration case in a Tomcat server. These are my settings:

web.xml file

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
                      http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
  version="3.1"
  metadata-complete="true">

    <description>
    ID webapp
    </description>
    <display-name>ID webapp</display-name>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <security-constraint>
    <web-resource-collection>
        <web-resource-name>Admin</web-resource-name>
        <url-pattern>/secure/menu.jsp</url-pattern>
    </web-resource-collection>
    <auth-constraint>
         <role-name>tomcat</role-name>
         <role-name>role1</role-name>
    </auth-constraint>
    </security-constraint>

    <security-role>
         <role-name>tomcat</role-name>
    </security-role>
    <security-role>
         <role-name>role1</role-name>
    </security-role>

    <login-config>
      <auth-method>FORM</auth-method>
      <realm-name>Example Form-Based Authentication Area</realm-name>
      <form-login-config>
        <form-login-page>/secure/login.jsp</form-login-page>
        <form-error-page>/secure/error.jsp</form-error-page>
      </form-login-config>
    </login-config>
</web-app>

login.jsp file

<html>
<head>
<title>Login Page for Examples</title>
<body bgcolor="white">
<form method="POST" action='<%= response.encodeURL("j_security_check") %>' >
  <table border="0" cellspacing="5">
    <tr>
      <th align="right">Username:</th>
      <td align="left"><input type="text" name="j_username"></td>
    </tr>
    <tr>
      <th align="right">Password:</th>
      <td align="left"><input type="password" name="j_password"></td>
    </tr>
    <tr>
      <td align="right"><input type="submit" value="Log In"></td>
      <td align="left"><input type="reset"></td>
    </tr>
  </table>
</form>
</body>
</html>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<html>
  <head>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title>Home Page</title>
  </head>
<body>
<div id="content">
<h1>Sistema de Gestión</h1>

<p>
<a href="secure/menu.jsp">Acceso al Sistema</a></p>
</div>
</body>
</html>

The main issue is that even the form is not shown. Only a 403-Forbidden error in web browser when I click the href link in index.jsp . This is my directory tree.

enter image description here

I don't know how to proceed to get the credentials form in the web browser. What I'm missing?

0 Answers
Related