Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTTP禁止我在正确身份验证时访问指定的资源-JavaEE_Java_Mysql_Authentication_Netbeans_Glassfish - Fatal编程技术网

HTTP禁止我在正确身份验证时访问指定的资源-JavaEE

HTTP禁止我在正确身份验证时访问指定的资源-JavaEE,java,mysql,authentication,netbeans,glassfish,Java,Mysql,Authentication,Netbeans,Glassfish,我正在尝试使用NetBeans(IDE)、GlassFish 4.1.0(web服务器)和MySql 5.7.11(数据库服务器)开发JavaEE7.0Web应用程序。我的操作系统是Windows 8.1 我想建立一个非常基本的身份验证系统。用户输入已插入数据库的用户名和密码,如果正确,他将能够访问名为index.jsp的网页。 因此,为了开发该认证系统,我采取了以下方法: 1-在GlassFish管理控制台中,我进入“安全/领域/文件”窗口,添加用户名:“john”和密码:“azerty”。“

我正在尝试使用NetBeans(IDE)、GlassFish 4.1.0(web服务器)和MySql 5.7.11(数据库服务器)开发JavaEE7.0Web应用程序。我的操作系统是Windows 8.1

我想建立一个非常基本的身份验证系统。用户输入已插入数据库的用户名和密码,如果正确,他将能够访问名为index.jsp的网页。 因此,为了开发该认证系统,我采取了以下方法:

1-在GlassFish管理控制台中,我进入“安全/领域/文件”窗口,添加用户名:“john”和密码:“azerty”。“john”所属的组列表称为“cemsAdmin”:

2-在“安全”常规窗口中,我启用了默认主体到角色映射选项:

3-在我的NetBeans web app项目中,我在web.xml文档中编写了以下代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<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>
</servlet>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>

<jsp-config>
    <jsp-property-group>
        <description>JSP configuration for the admin console</description>
        <url-pattern>/admin/index.jsp</url-pattern>
    </jsp-property-group>

    <jsp-property-group>
        <description>JSP configuration for the store front</description>
        <url-pattern>/index.jsp</url-pattern>
        <url-pattern>/WEB-INF/view/*</url-pattern>
    </jsp-property-group>
</jsp-config>

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>file</realm-name>
    <form-login-config>
        <form-login-page>/admin/login.jsp</form-login-page>
        <form-error-page>/admin/error.jsp</form-error-page>
    </form-login-config>
</login-config>
<resource-ref>
    <description>Connect to the cems database</description>
    <res-ref-name>jdbc/cems</res-ref-name>
    <res-type>javax.sql.ConnectionPoolDataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
当我运行所有代码时,我获得以下网页:

因此,我输入用户名“john”和密码“azerty”,出现以下HTTP错误

我真的不知道发生了什么事。你能帮我吗


非常感谢您的帮助。

您需要在web.xml中添加一个安全约束。 大概是这样的:

<security-constraint>
    <display-name>Constraint1</display-name>
    <web-resource-collection>
        <web-resource-name>rr</web-resource-name>
        <description/>
        <url-pattern>/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>RoleOne</role-name>
    </auth-constraint>
</security-constraint>
<security-role>
    <description/>
    <role-name>RoleOne</role-name>
</security-role>

约束1
rr
/管理员/*
罗莱昂
罗莱昂

您还缺少安全角色定义。

你好,Armando,谢谢您的帮助。我刚采纳了你的建议。但是,它不起作用。我添加了一个安全约束、一个身份验证约束和一个安全角色,但它给了我相同的HTTP禁止错误。在我提供的示例中,url模式不是应用约束的模式。您的资源的模式是/admin/*Use*,以确保约束应用于该文件夹中的每个资源
<security-constraint>
    <display-name>Constraint1</display-name>
    <web-resource-collection>
        <web-resource-name>rr</web-resource-name>
        <description/>
        <url-pattern>/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>RoleOne</role-name>
    </auth-constraint>
</security-constraint>
<security-role>
    <description/>
    <role-name>RoleOne</role-name>
</security-role>