[英]How to implement basic authentication with Glassfish?
I'm tried this configuration but it didn't work for me. 我试过这个配置,但它对我不起作用。 Basic Authentication in Glassfish I also tried this guide http://maksim.sorokin.dk/it/2010/10/13/basic-authentication-in-glassfish-3/ but I couldn't get user-pass asking with it too.
Glassfish中的基本身份验证我也尝试过本指南http://maksim.sorokin.dk/it/2010/10/13/basic-authentication-in-glassfish-3/但我也无法通过用户传递问题。
These are steps I've taken: 这些是我采取的步骤:
1. Login as admin to Admin interface. 1.以管理员身份登录管理界面。
2. Go to Security->Realms->File 2.转到Security-> Realms-> File
3. Add a group name (Users) to Assign Groups field. 3.将组名称(用户)添加到“分配组”字段。
4. Open manage users at the top of the page. 4.在页面顶部打开管理用户。
5. Click New and add an user (testuser) and give a password. 5.单击“新建”并添加用户(testuser)并输入密码。
6. Add (Users) to Group List. 6.将(用户)添加到组列表。
7. put this lines to web.xml 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. and put this lines to sun-web.xml 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. After all I enabled Configurations->server-config->Security->Security Manager 9.毕竟我启用了Configurations-> server-config-> Security-> Security Manager
My configuration is Glassfish 3.1, sun java6 jdk, Debian lenny and a simple "Hello World" page for testing. 我的配置是Glassfish 3.1,sun java6 jdk,Debian lenny和一个简单的“Hello World”页面进行测试。
What is missing here? 这里缺少什么?
UPDATE: 更新:
I figured out it needs xml headers. 我发现它需要xml标题。 After I've added them it started to work.
我添加它们之后就开始工作了。 My final configuration is below:
我的最终配置如下:
<?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>
and 和
<?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>
You may try this guide: http://download.oracle.com/docs/cd/E19798-01/821-1750/beaxw/index.html I heard that web.xml sometimes not work properly. 您可以尝试本指南: http : //download.oracle.com/docs/cd/E19798-01/821-1750/beaxw/index.html我听说web.xml有时无法正常工作。 I had same problem but cannot test it now.
我有同样的问题,但现在无法测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.