I post this question after having searched thoroughly in Internet with no situation alike found. I'm trying to use a JDBCRealm to authenticate users in a simple test web application deployed with Tomat 7.0.42 and MariaDB 5.5 in a development environment. I've followed all the steps explained at Tomcat's How-To and this is what I have:
My app's deployment descriptor:
<error-page>
<error-code>403</error-code>
<location>/WEB-INF/jsp/desautorizado.jsp</location>
</error-page>
<security-constraint>
<web-resource-collection>
<web-resource-name>Acciones</web-resource-name>
<url-pattern>/actions/*</url-pattern>
</web-resource-collection>
<web-resource-collection>
<web-resource-name>Paginas</web-resource-name>
<url-pattern>/sel_tipo_tabla.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>estandar</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<security-role>
<role-name>estandar</role-name>
</security-role>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/WEB-INF/jsp/login.jsp</form-login-page>
<form-error-page>/WEB-INF/jsp/desautorizado.jsp</form-error-page>
</form-login-config>
</login-config>
Tomcat's conf/server.xml:
<Engine defaultHost="localhost" name="Catalina">
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Context docBase="MyAppStruts" path="/MyAppStruts" reloadable="true" source="org.eclipse.jst.jee.server:MyAppStruts">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.mariadb.jdbc.Driver"
connectionURL="jdbc:mariadb://localhost:3306/desa"
connectionName="ruben"
connectionPassword="acceso"
userTable="usuarios"
userNameCol="usuario"
userCredCol="password"
userRoleTable="roles"
roleNameCol="rol" />
</Realm>
</Context>
</Host>
</Engine>
It works perfectly if I use a UserDatabaseRealm instead (Tomcat's default which uses conf/tomcat-users.xml file). However, I always get redirected to the error page if I use a JDBCRealm, even when I introduce an existing user/password in the database.
I forgot to mention that I'm using Eclipse to deploy, so everything is relative to $CATALINA_BASE and NOT $CATALINA_HOME. In development environments, $CATALINA_BASE points to $(WORKSPACE_DIR)/.metadata/.plugins/org.eclipse.wst.server.core/tmp0. Thus, MariaDB driver jar file is in $(WORKSPACE_DIR)/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/lib/mariadb-java-client.jar and the public key certificate is in $(WORKSPACE_DIR)/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/hogar.keystore (no problem with this).
By watching the logs, I noticed that whenever I reset the server (only reset, even before launching first request to my app), the following line is written:
127.0.0.1 - - [27/Oct/2013:21:29:32 +0100] "GET / HTTP/1.1" 404 961
No error or exception is showed in Eclipse's console tab. I guess that Tomcat is unable to establish a connection to the database, but, why?