java - Tomcat 7 的 JAAS 身份验证失败,没有错误消息

标签 java jsf tomcat jaas

与另一个用户 ( 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 &quot;%r&quot; %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>

摘 self 的 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/

非常感谢您的帮助!

最佳答案

我不确定它为什么现在可以工作,但我认为在我将 http-method 属性添加到我的 web.xml 安全配置后它一直在工作:

        <web-resource-collection>
        <web-resource-name>secured</web-resource-name>
        <url-pattern>/admin/*</url-pattern>
        <http-method>POST</http-method>
        <http-method>GET</http-method>
    </web-resource-collection> 

关于java - Tomcat 7 的 JAAS 身份验证失败,没有错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23956904/

相关文章:

Java 如何将音频数据存储在字节数组中。

java - 在 Java 中查找第三大 no

jsf - 切换 p :fieldset from another button

jsf - 为什么不是我的 f :param rendering inside h:outputText?

html - JSF dataTable 作为具有可点击行的 CSS 表?

tomcat - 如何使用在 Mac 上运行的 Jenkins 重启远程 Tomcat

java - Apache 可以基于 Tomcat webapp 的 Spring SecurityContext 限制访问吗?

java - 如何使用 lambda 来初始化具有命名线程的 ThreadFactory

java - 在 Unity Project 之间共享数据到 Android Studio java 代码

tomcat - fatwire可以在tomcat上运行吗?