Linux How to implement basic authentication with Glassfish?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5912577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to implement basic authentication with Glassfish?
提问by wolfiem
I'm tried this configuration but it didn't work for me. Basic Authentication in GlassfishI 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.
I'm tried this configuration but it didn't work for me. Basic Authentication in GlassfishI 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.
These are steps I've taken:
1. Login as admin to Admin interface.
2. Go to Security->Realms->File
3. Add a group name (Users) to Assign Groups field.
4. Open manage users at the top of the page.
5. Click New and add an user (testuser) and give a password.
6. Add (Users) to Group List.
7. put this lines to web.xml
These are steps I've taken:
1. Login as admin to Admin interface.
2. Go to Security->Realms->File
3. Add a group name (Users) to Assign Groups field.
4. Open manage users at the top of the page.
5. Click New and add an user (testuser) and give a password.
6. Add (Users) to Group List.
7. put this lines to 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. and put this lines to 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. After all I enabled 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.
My configuration is Glassfish 3.1, sun java6 jdk, Debian lenny and a simple "Hello World" page for testing.
What is missing here?
What is missing here?
UPDATE:
UPDATE:
I figured out it needs xml headers. After I've added them it started to work. My final configuration is below:
I figured out it needs xml headers. 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
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>
采纳答案by tachi512
You may try this guide: http://download.oracle.com/docs/cd/E19798-01/821-1750/beaxw/index.htmlI heard that web.xml sometimes not work properly. I had same problem but cannot test it now.
You may try this guide: http://download.oracle.com/docs/cd/E19798-01/821-1750/beaxw/index.htmlI heard that web.xml sometimes not work properly. I had same problem but cannot test it now.