[英]How to implement basic authentication with Glassfish?
我試過這個配置,但它對我不起作用。 Glassfish中的基本身份驗證我也嘗試過本指南http://maksim.sorokin.dk/it/2010/10/13/basic-authentication-in-glassfish-3/但我也無法通過用戶傳遞問題。
這些是我采取的步驟:
1.以管理員身份登錄管理界面。
2.轉到Security-> Realms-> File
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.畢竟我啟用了Configurations-> server-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>
您可以嘗試本指南: http : //download.oracle.com/docs/cd/E19798-01/821-1750/beaxw/index.html我聽說web.xml有時無法正常工作。 我有同樣的問題,但現在無法測試。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.