j_security_check Glassfish错误

时间:2013-09-05 23:42:00

标签: java-ee authentication glassfish java-ee-7

我正在尝试构建一个使用FORM身份验证的应用程序,但是当我运行该示例时,我会看到一个屏幕显示:

An Error Occurred:

Index: 0, Size: 0

Stack Trace

我正在运行GlassFish Server开源版4.0(版本89)

表单的代码:

<h:form class="form-signin" p:action="j_security_check">
    <h:inputText class="form-control top" p:name="j_username" p:placeholder="Username" p:autofocus="true" />
    <h:inputSecret class="form-control bottom" p:name="j_password" p:placeholder="Password" />
    <h:commandButton class="btn btn-lg btn-primary btn-block" value="Login" />
</h:form>

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <display-name>myKitchen</display-name>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <security-role-ref>
            <description/>
            <role-name>user</role-name>
            <role-link>User</role-link>
        </security-role-ref>
        <security-role-ref>
            <description/>
            <role-name>User</role-name>
            <role-link>User</role-link>
        </security-role-ref>
        <security-role-ref>
            <description/>
            <role-name>admin</role-name>
            <role-link>Admin</role-link>
        </security-role-ref>
        <security-role-ref>
            <description/>
            <role-name>Admin</role-name>
            <role-link>Admin</role-link>
        </security-role-ref>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/app/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>app/index.xhtml</welcome-file>
    </welcome-file-list>
    <security-constraint>
        <display-name>User Pages</display-name>
        <web-resource-collection>
            <web-resource-name>User Pages Area</web-resource-name>
            <description>Pages that only authenticated users should be able to use</description>
            <url-pattern>/protected/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <description/>
            <role-name>Admin</role-name>
            <role-name>User</role-name>
        </auth-constraint>
        <user-data-constraint>
            <description/>
            <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
    <security-role>
        <description>Regular user</description>
        <role-name>User</role-name>
    </security-role>
    <security-role>
        <description>Admin user</description>
        <role-name>Admin</role-name>
    </security-role>
    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>JDBCRealm</realm-name>
        <form-login-config>
            <form-login-page>/app/index.xhtml</form-login-page>
            <form-error-page>/app/errors/auth.xhtml</form-error-page>
        </form-login-config>
    </login-config>
</web-app>

的glassfish-web.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <security-role-mapping>
    <role-name>user</role-name>
    <group-name>user</group-name>
    <group-name>User</group-name>
  </security-role-mapping>
  <security-role-mapping>
    <role-name>admin</role-name>
    <group-name>admin</group-name>
    <group-name>Admin</group-name>
  </security-role-mapping>
  <security-role-mapping>
    <role-name>Admin</role-name>
    <group-name>admin</group-name>
    <group-name>Admin</group-name>
  </security-role-mapping>
  <security-role-mapping>
    <role-name>User</role-name>
    <group-name>user</group-name>
    <group-name>User</group-name>
  </security-role-mapping>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</glassfish-web-app>

我遵循的教程:link

1 个答案:

答案 0 :(得分:0)

定义数据库连接密码修复了问题