【发布时间】:2014-07-20 08:23:38
【问题描述】:
与另一个用户 (issue with JAAS authentication on Tomcat 7) 的帖子相关,我尝试在我的 JSF 应用程序中使用 JASS 进行身份验证。
不幸的是,如果我尝试登录,我总是会被定向到 loginFailed.xhtml 页面。
我使用 Tomcat7、JSF 2.2 和 Derby 数据库来存储用户/密码。
这是我的 server.xml 的摘录:
<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 "%r" %s %b" prefix="localhost_access_log."
suffix=".txt" />
<Context docBase="socialanalysis" path="/socialanalysis"
reloadable="true" source="org.eclipse.jst.jee.server:socialanalysis">
<Realm className="org.apache.catalina.realm.JDBCRealm"
driverName="org.apache.derby.jdbc.ClientDriver" connectionURL="jdbc:derby://localhost:1527/socialanalysis"
connectionName="socialanalysis" connectionPassword="socialanalysis"
userTable="users" userNameCol="username" userCredCol="password"
userRoleTable="users_roles" roleNameCol="rolename"/>
</Context>
</Host>
摘自我的 web.xml:
<security-constraint>
<web-resource-collection>
<web-resource-name>secured</web-resource-name>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<security-role>
<role-name>user</role-name>
</security-role>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginFailed.xhtml</form-error-page>
</form-login-config>
</login-config>
我按照本教程创建数据库: http://www.thejavageek.com/2013/07/07/configure-jdbcrealm-jaas-for-mysql-and-tomcat-7-with-form-based-authentication/
非常感谢您的帮助!
【问题讨论】:
-
您的数据库表及其内容如何?
-
Faces Servlet 的 url-pattern 是什么?如果你使用 /* 它可以阻止访问 j_security_check。
-
感谢您的回答@cy3er。我有三个表(USERS、ROLES、USERS_ROLES)。用户由两列(用户名、密码)组成。在 USERS 中有一个条目(“benutzer”、“passwort”)。 ROLES 只有一列 ROLENAME 和一个条目(“用户”)。最后,USERS_ROLES 有 USERNAME 和 ROLENAME 列。 USERS_ROLES 有条目“benutzer,用户”
-
感谢您的回答@bhdrk。我的 Faces Servlet 的 url-pattern 配置如下:
Faces Servlet *.jsf Faces Servlet *.xhtml