Tomcat can't set properties for DataSource connection

Viewed 1324

I'm trying to implement a form based authentication system using Tomcat 10. I've checked my form using a UserDatabaseRealm and it works fine. I've added my Realm in the META-INF/context.xml file and Resources as a Global Resource in the server.xml file. I've used a Resource-Link file for accessing the Resource defined in server.xml file.

When I run the app on the server I get the error saying the app couldn't set the SQL properties I've defined. When I enter the username I have entered in the form, I get a 403 error and the console log says it couldn't find the column 'user_name' in 'where clause'.

Jul 13, 2021 12:36:54 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: Match [Server/Service/Engine/Host/Context/Realm] failed to set property [connectionName] to [root] Jul 13, 2021 12:36:54 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: Match [Server/Service/Engine/Host/Context/Realm] failed to set property [connectionPassword] to [root] Jul 13, 2021 12:36:54 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: Match [Server/Service/Engine/Host/Context/Realm] failed to set property [connectionURL] to [jdbc:mysql://localhost/tomcat_mail] Jul 13, 2021 12:36:54 PM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: Match [Server/Service/Engine/Host/Context/Realm] failed to set property [driverName] to [com.mysql.cj.jdbc.Driver] Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Server version name: Apache Tomcat/9.0.46 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Server built: May 8 2021 17:35:52 UTC Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Server version number: 9.0.46.0 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: OS Name:
Windows 10 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: OS Version: 10.0 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Architecture: amd64 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Java Home: C:\Program Files\Java\jdk-16.0.1 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: JVM Version: 16.0.1+9-24 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: JVM Vendor: Oracle Corporation Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: CATALINA_BASE:
C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: CATALINA_HOME:
C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -Dcatalina.base=C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -Dcatalina.home=C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -Dwtp.deploy=C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\wtpwebapps Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -Dfile.encoding=Cp1252 Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.VersionLoggerListener log INFO: Command line argument: -XX:+ShowCodeDetailsInExceptionMessages Jul 13, 2021 12:36:54 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent INFO: The Apache Tomcat Native library which allows using OpenSSL was not found on the java.library.path: [C:\Program Files\Java\jdk-16.0.1\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jdk-16.0.1/bin/server;C:/Program Files/Java/jdk-16.0.1/bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\PuTTY;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files\nodejs;C:\Program Files\MySQL\MySQL Shell 8.0\bin;C:\Users\sjose\AppData\Local\Programs\Python\Python39\Scripts;C:\Users\sjose\AppData\Local\Programs\Python\Python39;C:\Users\sjose\AppData\Local\Microsoft\WindowsApps;C:\Users\sjose\AppData\Local\Programs\Microsoft VS Code\bin;%JAVA_HOME\bin%;C:\Users\sjose\AppData\Local\atom\bin;C:\Users\sjose.dotnet\tools;C:\Users\sjose\AppData\Roaming\npm;C:\Program Files\apache-maven-3.8.1\bin;;C:\Users\sjose\Desktop;;.] Jul 13, 2021 12:36:54 PM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-nio-8080"] Jul 13, 2021 12:36:54 PM org.apache.catalina.startup.Catalina load INFO: Server initialization in [590] milliseconds Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. Jul 13, 2021 12:36:55 PM org.apache.catalina.core.StandardService startInternal INFO: Starting service [Catalina] Jul 13, 2021 12:36:55 PM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet engine: [Apache Tomcat/9.0.46] Jul 13, 2021 12:36:56 PM org.apache.catalina.startup.ContextConfig validateSecurityRoles WARNING: Security role name [user] used in an without being defined in a Jul 13, 2021 12:36:56 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Jul 13, 2021 12:36:56 PM org.apache.tomcat.util.descriptor.web.SecurityConstraint findUncoveredHttpMethods SEVERE: For security constraints with URL pattern [/*] only the HTTP methods [POST GET] are covered. All other methods are uncovered. Jul 13, 2021 12:36:56 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\docs] Jul 13, 2021 12:36:57 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Jul 13, 2021 12:36:57 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deployment of web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\docs] has finished in [781] ms Jul 13, 2021 12:36:57 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\examples] Jul 13, 2021 12:36:58 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Jul 13, 2021 12:36:58 PM org.apache.catalina.core.ApplicationContext log INFO: ContextListener: contextInitialized() Jul 13, 2021 12:36:58 PM org.apache.catalina.core.ApplicationContext log INFO: SessionListener: contextInitialized() Jul 13, 2021 12:36:58 PM org.apache.catalina.core.ApplicationContext log INFO: ContextListener: attributeAdded('StockTicker', 'async.Stockticker@921dbcf') Jul 13, 2021 12:36:58 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deployment of web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\examples] has finished in [972] ms Jul 13, 2021 12:36:58 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\host-manager] Jul 13, 2021 12:36:58 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Jul 13, 2021 12:36:58 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deployment of web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\host-manager] has finished in [627] ms Jul 13, 2021 12:36:58 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\manager] Jul 13, 2021 12:36:59 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Jul 13, 2021 12:36:59 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deployment of web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\manager] has finished in [640] ms Jul 13, 2021 12:36:59 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\ROOT] Jul 13, 2021 12:37:00 PM org.apache.jasper.servlet.TldScanner scanJars INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. Jul 13, 2021 12:37:00 PM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deployment of web application directory [C:\Users\sjose\Documents\Apache_Tomcat_9\apache-tomcat-9.0.46\webapps\ROOT] has finished in [638] ms Jul 13, 2021 12:37:00 PM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-nio-8080"] Jul 13, 2021 12:37:00 PM org.apache.catalina.startup.Catalina start INFO: Server startup in [5459] milliseconds Jul 13, 2021 12:43:13 PM org.apache.catalina.realm.DataSourceRealm getRoles SEVERE: Exception retrieving roles for [daniel@abc.com] java.sql.SQLSyntaxErrorException: Unknown column 'user_name' in 'where clause' at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114) at jdk.proxy2/jdk.proxy2.$Proxy11.executeQuery(Unknown Source) at org.apache.catalina.realm.DataSourceRealm.getRoles(DataSourceRealm.java:514) at org.apache.catalina.realm.DataSourceRealm.authenticate(DataSourceRealm.java:334) at org.apache.catalina.realm.DataSourceRealm.authenticate(DataSourceRealm.java:264) at org.apache.catalina.authenticator.FormAuthenticator.doAuthenticate(FormAuthenticator.java:244) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:632) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:687) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:893) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1707) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:831)

I have created a MySQL database called tomcat_mail. It has three tables :

  1. tomcat_users : user_name, password
  2. tomcat_roles : role_name
  3. tomcat_users_roles : user_name, role_name

I'll attach my server.xml, context.xml and web.xml files here.

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--><!-- Note:  A "Server" is not itself a "Container", so you may not
     define subcomponents such as "Valves" at this level.
     Documentation at /docs/config/server.html
 --><Server port="8006" shutdown="SHUTDOWN">
  <Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  <!--APR library loader. Documentation at /docs/apr.html -->
  <Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  <!-- Prevent memory leaks due to use of particular java/javax APIs-->
  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    -->
    
       <Resource name="jdbc/EmailTomcat" auth="Container" type="javax.sql.DataSource"
               maxTotal="100" maxIdle="30" maxWaitMillis="10000"
               factory = "org.apache.tomcat.jdbc.pool.DataSourceFactory"
               username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/tomcat_mail"/>
    
    <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>

  <!-- A "Service" is a collection of one or more "Connectors" that share
       a single "Container" Note:  A "Service" is not itself a "Container",
       so you may not define subcomponents such as "Valves" at this level.
       Documentation at /docs/config/service.html
   -->
  <Service name="Catalina">

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->
    <!--
    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150" minSpareThreads="4"/>
    -->


    <!-- A "Connector" represents an endpoint by which requests are received
         and responses are returned. Documentation at :
         HTTP Connector: /docs/config/http.html
         AJP  Connector: /docs/config/ajp.html
         Define a non-SSL/TLS HTTP/1.1 Connector on port 8080
    -->
    <Connector connectionTimeout="20000" port="8090" protocol="HTTP/1.1" redirectPort="8443"/>
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the
         AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true">
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="conf/localhost-rsa.jks"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>
    -->

    <!-- Define an AJP 1.3 Connector on port 8009 -->
    <!--
    <Connector protocol="AJP/1.3"
               address="::1"
               port="8009"
               redirectPort="8443" />
    -->

    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine defaultHost="localhost" name="Catalina">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

            <Realm className="org.apache.catalina.realm.DataSourceRealm"   dataSourceName="jdbc/EmailTomcat"
     driverName="com.mysql.cj.jdbc.Driver"          connectionURL="jdbc:mysql://localhost/tomcat_mail"
         connectionName="root" connectionPassword="root"
   userTable="tomcat_users" userNameCol="user_name" userCredCol="password"
   userRoleTable="tomcat_roles" roleNameCol="role_name"/>
        
      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
      </Realm>
      
      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log" suffix=".txt"/>

      <Context docBase="EmailTomcat" path="/EmailTomcat" reloadable="true" source="org.eclipse.jst.jee.server:EmailTomcat"/></Host>
    </Engine>
  </Service>
</Server>

context.xml

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

<Context>
          
<ResourceLink global="jdbc/EmailTomcat" name="jdbc/EmailTomcat" type="javax.sql.DataSource"/>

   <Realm className="org.apache.catalina.realm.DataSourceRealm"   dataSourceName="jdbc/EmailTomcat"
     driverName="com.mysql.cj.jdbc.Driver"          connectionURL="jdbc:mysql://localhost/tomcat_mail"
         connectionName="root" connectionPassword="root"
   userTable="tomcat_users" userNameCol="user_name" userCredCol="password"
   userRoleTable="tomcat_roles" roleNameCol="role_name"/>

   
   <Resource name="jdbc/EmailTomcat" auth="Container" type="javax.sql.DataSource"
               factory = "org.apache.tomcat.jdbc.pool.DataSourceFactory"
               username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/tomcat_mail"/>

</Context>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

<resource-ref>
<description>Email App using Tomcat</description>
<res-ref-name>jdbc/EmailTomcat</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

        <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
          
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Authentication</web-resource-name>
            <url-pattern>/*</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>

        <auth-constraint>
            <role-name>user</role-name>
        </auth-constraint>

        <user-data-constraint>
            <!-- transport-guarantee can be CONFIDENTIAL, INTEGRAL, or NONE -->
            <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.html</form-login-page>
            <form-error-page>/login-failed.html</form-error-page>
        </form-login-config>
    </login-config>
    
    
</web-app>
1 Answers

Never mind. Found the solution. DataSource Realm doesn't take those properties as attributes.

Related