我无法将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进行开发。
答案 0 :(得分:6)
我不确定默认值是否适用,但您可能需要创建 sun-web.xml 并为角色“User”设置映射:
<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>
答案 1 :(得分:1)
似乎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>