1

I'm trying to get authentication for my site using JDBC Realms and I'm getting a HTTP Status 403 - Access to the requested resource has been denied when I use correct credentials. When I use incorrect credentials it goes to the error page like it should. I'm able to query the database and get back responses so it's not the java connector that is the issue. Also if I change the name of the table I get an error saying the table doesn't exist so it appears to be connecting to the database just fine and querying it because it knows when the username and password are incorrect and sends me to the error page. The issues is when I use correct username/password. I'm using tomcat 7.0.61. Hopefully there is enough information to figure out what is wrong.

My database is called brew4me.

The persons table has the attributes:

| email|name|city |password|state_providence|country|

The user_roles table has the attribues:

|email|role_name|

An example row for the user_roles table would be

email@example.com|user

Also email=email for the tables.

My Realm in the server.xml file:

<Realm className="org.apache.catalina.realm.JDBCRealm" 
          connectionURL="jdbc:mysql://localhost:3306/brew4me" 
          connectionName="root" connectionPassword="#cs564brew4me"
          driverName="com.mysql.jdbc.Driver" 
          roleNameCol="email" 
          userCredCol="password" 
          userNameCol="email" 
          userRoleTable="user_roles" 
          userTable="person"/>

My configurations in web.xml:

<security-role>
    <role-name>user</role-name>
</security-role>

<security-constraint>
    <display-name>HomepageConstraint</display-name>
    <web-resource-collection>
        <web-resource-name>brew4me</web-resource-name>
        <url-pattern>/*</url-pattern>
    </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>/error.html</form-error-page>
    </form-login-config>
</login-config>

Heres the code for my login page:

<form method=post action="j_security_check" >
    Email:<input type="text"  name= "j_username" >
    Password:<input type="password"  name= "j_password" >
    <input type="submit" value="Login">
</form>

Console output if it might be helpful:

 Apr 28, 2015 12:05:18 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:brew4me' did not find a matching property.
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/7.0.61
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Mar 27 2015 12:03:56 UTC
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         7.0.61.0
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 7
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            6.1
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files\Java\jre1.8.0_40
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_40-b26
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         C:\apache-tomcat-7.0.61
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\apache-tomcat-7.0.61
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\apache-tomcat-7.0.61
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\apache-tomcat-7.0.61
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\apache-tomcat-7.0.61\wtpwebapps
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\apache-tomcat-7.0.61\endorsed
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Apr 28, 2015 12:05:18 AM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_40\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_40/bin/server;C:/Program Files/Java/jre1.8.0_40/bin;C:/Program Files/Java/jre1.8.0_40/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\AMD APP\bin\x86_64;C:\Program Files (x86)\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\SWTOOLS\ReadyApps;C:\Program Files (x86)\Common Files\Lenovo;C:\Program Files (x86)\Common Files\lenovo\easyplussdk\bin;C:\Modeltech_pe_edu_10.3c\win32pe_edu;C:\Program Files (x86)\Google\google_appengine\;C:\eclipse;;.
Apr 28, 2015 12:05:18 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Apr 28, 2015 12:05:18 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Apr 28, 2015 12:05:18 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1203 ms
Apr 28, 2015 12:05:18 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Apr 28, 2015 12:05:18 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.61
Apr 28, 2015 12:05:20 AM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [193] milliseconds.
Apr 28, 2015 12:05:20 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.61\webapps\docs
Apr 28, 2015 12:05:20 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\apache-tomcat-7.0.61\webapps\docs has finished in 264 ms
Apr 28, 2015 12:05:20 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.61\webapps\examples
Apr 28, 2015 12:05:21 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: contextInitialized()
Apr 28, 2015 12:05:21 AM org.apache.catalina.core.ApplicationContext log
INFO: SessionListener: contextInitialized()
Apr 28, 2015 12:05:21 AM org.apache.catalina.core.ApplicationContext log
INFO: ContextListener: attributeAdded('org.apache.jasper.compiler.TldLocationsCache', 'org.apache.jasper.compiler.TldLocationsCache@115992e1')
Apr 28, 2015 12:05:21 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\apache-tomcat-7.0.61\webapps\examples has finished in 744 ms
Apr 28, 2015 12:05:21 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.61\webapps\host-manager
Apr 28, 2015 12:05:21 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\apache-tomcat-7.0.61\webapps\host-manager has finished in 217 ms
Apr 28, 2015 12:05:21 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.61\webapps\manager
Apr 28, 2015 12:05:21 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\apache-tomcat-7.0.61\webapps\manager has finished in 223 ms
Apr 28, 2015 12:05:21 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory C:\apache-tomcat-7.0.61\webapps\ROOT
Apr 28, 2015 12:05:21 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deployment of web application directory C:\apache-tomcat-7.0.61\webapps\ROOT has finished in 133 ms
Apr 28, 2015 12:05:21 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Apr 28, 2015 12:05:21 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Apr 28, 2015 12:05:21 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3331 ms
BillHaggerty
  • 6,157
  • 10
  • 35
  • 68
Matt Nicol
  • 13
  • 3

1 Answers1

0

In your Realm you have wrongly defined the roleNameCol value.

Try setting it to roleNameCol="role_name"

MaVRoSCy
  • 17,747
  • 15
  • 82
  • 125
  • Thank you! This fixed the issue. I guess I didn't understand fully what the attribute was. I'm just glad it was some small mistake on my part. – Matt Nicol Apr 28 '15 at 12:23
  • glad i could help... so if you find an answer helpful is good to up-vote it and accept it so that others having the same issue can find an answer easily – MaVRoSCy Apr 28 '15 at 12:51
  • 1
    I just created my account because this was the first issue I couldn't solve by just googling it so I don't have enough reputation to up vote you I tried! When I get enough I'll come back! – Matt Nicol Apr 28 '15 at 15:20
  • i think that you can mark it as accepted answer though by clicking the tick (v) on the left of the answer – MaVRoSCy Apr 28 '15 at 16:13