【问题标题】:Basic Authentication in GlassfishGlassfish 中的基本身份验证
【发布时间】:2010-10-08 17:26:16
【问题描述】:

我无法让 BASIC 身份验证与 Glassfish 一起使用。我正在开发一个应用程序,需要提示我输入用户名和密码。当我尝试访问应用程序时,应用程序会提示我输入密码,但在输入正确的登录信息后,我得到了HTTP Status 403 - Access to the requested resource has been denied

我已进入 Glassfish 管理控制台并在 file 领域创建了一些示例用户并启用了安全管理器。

接下来,在我的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>

我不确定下一步该做什么。我已经搜索了几个小时没有运气。验证是有效的,因为如果我输入了错误的登录信息,它会再次提示,但在成功验证后,我会收到上面显示的访问被拒绝消息。

如果有帮助,我正在运行 Glassfish Open Source 3.0.1 并使用 Netbeans 6.9 进行开发。

【问题讨论】:

    标签: security glassfish


    【解决方案1】:

    我不确定默认值是否适用,但您可能需要创建 sun-web.xml 并为角色“用户”设置映射:

    <sun-web-app error-url="">
      ... 
      <security-role-mapping>
        <role-name>User</role-name>
        <group-name>filerealm-group-name</group-name>
      </security-role-mapping>
      ...
    </sun-web-app>
    

    【讨论】:

      【解决方案2】:

      http://download.oracle.com/javaee/6/tutorial/doc/bnbxj.html 上的 Glassfish 文档似乎不正确。

      如果角色名称在 应用程序不一样 在服务器上定义的组名,使用 运行时部署描述符 指定映射。以下 示例演示如何执行此操作 glassfish-web.xml 文件中的映射, 这是用于网络的文件 应用

      在这种情况下你需要创建一个WEB-INF/glassfish-web-app.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
      <glassfish-web-app>
          <security-role-mapping>
              <role-name>User</role-name>
              <group-name>User</group-name>
          </security-role-mapping>
      </glassfish-web-app>
      

      【讨论】:

        猜你喜欢
        • 2013-12-01
        • 2015-03-24
        • 2011-08-20
        • 1970-01-01
        • 1970-01-01
        • 2021-06-20
        • 2011-01-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多