如何使用Glassfish实现基本认证? [英] How to implement basic authentication with Glassfish?

查看:204
本文介绍了如何使用Glassfish实现基本认证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这种配置,但它对我没有用。
Glassfish中的基本身份验证
我也试过这个指南
http://maksim.sorokin。 dk / it / 2010/10/13 / basic-authentication-in-glassfish-3 / ,但是我也无法获得用户传递的询问。



以下是我已采取的步骤:

1.以管理员身份登录到管理界面。

2.转到安全 - >领域 - >文件

3.将组名称(Users)添加到Assign Groups字段。

4.打开管理页面顶部的用户。

5.单击新建并添加用户(testuser)并给出密码。

6.将用户添加到组列表中。
7.将这些行放到web.xml中



< security-constraint>
< web-resource-collection>
< web-resource-name>安全应用程序< / web-resource-name>
< url-pattern> / *< / url-pattern>
< http-method> GET< / http-method>
< http-method> POST< / http-method>
< / web-resource-collection>

< auth-constraint>
<角色名称>用户< /角色名称>
< / auth-constraint>
< / security-constraint>

< login-config>
< auth-method> BASIC< / auth-method>
< realm-name>档案< / realm-name>
< / login-config>

< security-role>
<角色名称>用户< /角色名称>
< / security-role>

8。并将这些行放在sun-web.xml中< sun-web-app error-and-sun-web.xml


$ b

 < URL =  > 
< security-role-mapping>
<角色名称>用户< /角色名称>
< group-name>用户< / 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.0encoding =UTF -8\" >?;
< web-app version =3.0xmlns =http://java.sun.com/xml/ns/javaeexmlns:xsi =http://www.w3.org/2001/ XMLSchema-instancexsi: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>安全应用程序< / web-resource-name>
< url-pattern> / *< / url-pattern>
< http-method> GET< / http-method>
< http-method> POST< / http-method>
< / web-resource-collection>

< auth-constraint>
<角色名称>用户< /角色名称>
< / auth-constraint>
< / security-constraint>

< login-config>
< auth-method> BASIC< / auth-method>
< realm-name>档案< / realm-name>
< / login-config>

< security-role>
<角色名称>用户< /角色名称>
< / security-role>
< / web-app>

 <?xml version =1.0encoding =UTF-8?> 
<!DOCTYPE sun-web-app PUBLIC - // Sun Microsystems,Inc. //DTD Application Server 9.0 Servlet 2.5 // ENhttp://www.sun.com/software/appserver/的DTD /太阳网络app_2_5-0.dtd>
< sun-web-app error-url =>
< security-role-mapping>
<角色名称>用户< /角色名称>
< group-name>用户< / group-name>
< / security-role-mapping>
< / sun-web-app>


解决方案

您可以试试本指南: http://download.oracle.com/docs/cd/E19798 -01 / 821-1750 / beaxw / index.html 我听说web.xml有时无法正常工作。我有同样的问题,但现在无法测试。


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.

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

<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

My configuration is Glassfish 3.1, sun java6 jdk, Debian lenny and a simple "Hello World" page for testing.

What is missing here?

UPDATE:

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

<?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. I had same problem but cannot test it now.

这篇关于如何使用Glassfish实现基本认证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆