2016-11-23 51 views
0

我最近開始學習有關Java EE web編程的知識,並且我使用一些帶有Netbeans 8.2和Glashfish 4.1.1的JSP頁面來形成認證主題,是,我是以下教程:獲取HTTP狀態403 - 在Glassfish 4.1.1上登錄後禁止登錄

https://www.youtube.com/watch?v=GXnwtR1lT3w 

我是按照步驟一步,但是當我用我的用戶名和密碼的服務器登錄只給我一個HTTP狀態403 - 禁止錯誤,我是配置用戶的文件'AppAdmin'作爲組列表的服務器配置的領域安全部分。

這是我的login.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
 
<!DOCTYPE html> 
 
<html> 
 
    <head> 
 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
 
     <title>Login</title> 
 
    </head> 
 
    <body> 
 
     <h1>Login Page</h1> 
 
     <p>Please enter your username and password to login.</p> 
 
     <form action="j_security_check" method="POST"> 
 
     <table border="0"> 
 
      <tbody> 
 
       <tr> 
 
        <td>Username:</td> 
 
        <td><input type="text" name="j_username" value="" /></td> 
 
       </tr> 
 
       <tr> 
 
        <td>Password:</td> 
 
        <td><input type="password" name="j_password" value="" /></td> 
 
       </tr> 
 
       <tr> 
 
        <td></td> 
 
        <td><input type="submit" value="Login Now" /></td> 
 
       </tr> 
 
      </tbody> 
 
     </table> 
 
     </form> 
 
    </body> 
 
</html>

這是我的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"> 
 
    <session-config> 
 
     <session-timeout> 
 
      30 
 
     </session-timeout> 
 
    </session-config> 
 
    <security-constraint> 
 
     <display-name>Admin Pages</display-name> 
 
     <web-resource-collection> 
 
      <web-resource-name>Administrative Pages</web-resource-name> 
 
      <description/> 
 
      <url-pattern>/admin/*</url-pattern> 
 
     </web-resource-collection> 
 
     <auth-constraint> 
 
      <description/> 
 
      <role-name>admin</role-name> 
 
     </auth-constraint> 
 
    </security-constraint> 
 
    <login-config> 
 
     <auth-method>FORM</auth-method> 
 
     <realm-name>file</realm-name> 
 
     <form-login-config> 
 
      <form-login-page>/login.jsp</form-login-page> 
 
      <form-error-page>/login_error.jsp</form-error-page> 
 
     </form-login-config> 
 
    </login-config> 
 
    <security-role> 
 
     <description>Administrators</description> 
 
     <role-name>admin</role-name> 
 
    </security-role> 
 
    <security-role> 
 
     <description>Common Users</description> 
 
     <role-name>user</role-name> 
 
    </security-role> 
 
</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>admin</role-name> 
 
    <principal-name>admin</principal-name> 
 
    <group-name>AppAdmin</group-name> 
 
    </security-role-mapping> 
 
    <security-role-mapping> 
 
    <role-name>user</role-name> 
 
    <principal-name>user</principal-name> 
 
    <group-name>AppUser</group-name> 
 
    </security-role-mapping> 
 
    <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>

我stucked在這一部分,我嘗試了一些事情,我在一些論壇,沒有運氣閱讀。

謝謝你的幫助和時間。

回答

0

我知道這個問題是相當古老的,但無論如何。檢查我的配置文件,它看起來像,如果您的羣組列表設置爲AppAdmin然後在:

<security-role> 
    <description>Administrators</description> 
    <role-name>admin</role-name> 
</security-role> 

而是「管理」的應該是AppAdmin。

希望這可以解決您的問題。