2011-05-06 21 views
3

我試過這種配置,但它不適合我。 Basic Authentication in Glassfish 我也試過這個指南 http://maksim.sorokin.dk/it/2010/10/13/basic-authentication-in-glassfish-3/但我不能得到用戶通過問它。如何使用Glassfish實現基本認證?

這些是我採取的步驟:
1.以admin身份登錄到Admin界面。
2.轉到安全 - >領域 - >文件
3.將組名(用戶)添加到指定組字段。
4.打開管理頁面頂部的用戶。
5.單擊新建並添加用戶(testuser)並給出密碼。
6.將(用戶)添加到組列表。
7.把這個線到web.xml

<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Secure Application</web-resource-name> 
     <url-pattern>/*</url-pattern> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
    </web-resource-collection> 

    <auth-constraint> 
     <role-name>User</role-name> 
    </auth-constraint> 
    </security-constraint> 

    <login-config> 
    <auth-method>BASIC</auth-method> 
    <realm-name>file</realm-name> 
    </login-config> 

    <security-role> 
    <role-name>User</role-name> 
    </security-role> 

8,並把此行sun-web.xml中

<sun-web-app error-url=""> 
    <security-role-mapping> 
    <role-name>User</role-name> 
    <group-name>Users</group-name> 
    </security-role-mapping> 
</sun-web-app> 

9.所有我設置 - 啓用後>服務器 - config-> Security-> Security Manager

我的配置是Glassfish 3.1,sun java6 jdk,Debian lenny和一個簡單的「Hello World」頁面進行測試。

這裏缺少什麼?

更新:

我想出了它需要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"> 
<security-constraint> 
    <web-resource-collection> 
     <web-resource-name>Secure Application</web-resource-name> 
     <url-pattern>/*</url-pattern> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
    </web-resource-collection> 

    <auth-constraint> 
     <role-name>Users</role-name> 
    </auth-constraint> 
</security-constraint> 

    <login-config> 
    <auth-method>BASIC</auth-method> 
    <realm-name>file</realm-name> 
    </login-config> 

    <security-role> 
    <role-name>Users</role-name> 
    </security-role> 
</web-app> 

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd"> 
<sun-web-app error-url=""> 
    <security-role-mapping> 
    <role-name>Users</role-name> 
    <group-name>Users</group-name> 
    </security-role-mapping> 
</sun-web-app> 
+0

第9步真的有必要嗎?我也使用文件和jdbc領域,但從未啓用安全管理器。只是一個想法...你的配置文件看起來很好。您可以將Glassfish中javax.enterprise.system.core.security模塊的日誌記錄設置爲FINEST,並檢查日誌文件中的任何提示。 – 2011-05-07 18:46:26

+0

沒有第九步就沒有工作。我發現它需要xml頭文件。 – wolfiem 2011-05-09 08:23:08

+0

我不知道和@Matt Handy完全相同。任何Oracle的教程都不會說明如何啓用該功能。在最新的Netbeans中,如果我啓用安全管理器,我不能再使用Netbeans集成的Glassfish,它不會再啓動了。 – Sami 2013-04-13 14:29:09

回答