【问题标题】:How to implement basic authentication with Glassfish?如何使用 Glassfish 实现基本身份验证?
【发布时间】:2011-08-20 05:35:51
【问题描述】:

我尝试过这种配置,但它对我不起作用。 Basic Authentication in Glassfish 我也试过这个指南 http://maksim.sorokin.dk/it/2010/10/13/basic-authentication-in-glassfish-3/ 但我也无法获得用户通行证。

这些是我已采取的步骤:
1. 以管理员身份登录到管理界面。
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。毕竟我启用了 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>

【问题讨论】:

  • 第9步真的有必要吗?我也使用文件和 jdbc 领域,但从未启用安全管理器。只是一个想法...您的配置文件看起来不错。您可以将 Glassfish 中 javax.enterprise.system.core.security 模块的日志记录设置为 FINEST 并检查您的日志文件是否有任何提示。
  • 没有第九步就不行。我发现它需要 xml 标头。
  • 我想知道和@Matt Handy 完全一样。任何 Oracle 的教程都没有告诉启用它。在最新的 Netbeans 中,如果我启用安全管理器,我将无法再使用集成了 Netbeans 的 Glassfish,它只是不再启动。
  • 我有 Glassfish 4.0 和 Netbeans 7.3.1 并且不需要“sun-web.xml”。根据您的步骤创建文件后,我删除了该文件。但是,我确实必须编辑“glassfish-web.xml”并添加如下行:Userstestuser名称> docs.oracle.com/javaee/6/tutorial/doc/bnbxj.html

标签: java linux security glassfish basic-authentication


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-12-01
    • 1970-01-01
    • 2017-11-02
    • 2015-03-24
    • 2021-06-30
    • 1970-01-01
    相关资源
    最近更新 更多