我尝试使用JDBC Realms为我的网站获取身份验证,并且我获得了HTTP状态403 - 当我使用正确的凭据时,拒绝访问所请求的资源。当我使用不正确的凭据时,它会像应该的那样转到错误页面。我能够查询数据库并获得回复,因此不是问题的java连接器。此外,如果我更改表的名称,我会收到一个错误,表示该表不存在,因此它似乎正好连接到数据库并查询它,因为它知道用户名和密码何时不正确并将我发送给错误页面。问题是我使用正确的用户名/密码。我使用的是tomcat 7.0.61。希望有足够的信息来弄清楚什么是错的。
我的数据库名为brew4me。
人员表具有以下属性:
| email|name|city |password|state_providence|country|
user_roles表具有attribues:
|email|role_name|
user_roles表的示例行是
email@example.com|user
另外发送电子邮件=电子邮件表格。
我的领域在server.xml文件中:
<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"/>
我在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>
下面是登录页面的代码:
<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>
控制台输出,如果它可能有帮助:
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
答案 0 :(得分:0)
在Realm
中,您错误地定义了roleNameCol
值。
尝试将其设置为roleNameCol="role_name"