我对 EJB 安全性和 GlassFish 身份验证、授权机制非常陌生。我有一个jdbc领域并配置sun-web.xml并web.xml映射角色并限制对页面的访问。
但是,我的问题是,当我限制对所有页面的访问时,它会起作用并在加载欢迎页面之前触发登录弹出窗口(使用 BASIC 身份验证)。
<web-resource-collection>
<web-resource-name>All Pages</web-resource-name>
<description/>
<url-pattern>/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>HEAD</http-method>
<http-method>PUT</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
但是当我限制对文件夹中页面的访问时security,GlassFish 不会提示登录并将用户重定向到受限页面。
<web-resource-collection>
<web-resource-name>All Pages</web-resource-name>
<description/>
<url-pattern>/security/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>HEAD</http-method>
<http-method>PUT</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>`
请帮我解决这个问题..提前非常感谢。
我打开安全管理器后也发现了这些条目
Processing login with credentials of type: class com.sun.enterprise.security.auth.login.PasswordCredential
Logging in user [admin] into realm: admin-realm using JAAS module: fileRealm
Login module initialized: class com.sun.enterprise.security.auth.login.FileLoginModule
File login succeeded for: admin
JAAS login complete.
JAAS authentication committed.
Password login succeeded for : admin
permission check done to set SecurityContext
Set security context as user: admin
[Web-Security] hasResource perm: (javax.security.jacc.WebResourcePermission /faces/security/UserRedirect.jsp GET)
似乎 admin-realm 中的管理员主体已自动进行身份验证并用于我的应用程序,而不是使用我的 jdbcrealm。关于如何解决这个问题的任何想法?
更新
对不起,我刚刚将身份验证更改为要检查的表单。我又把它改回了 BASIC。是的,我将 jdbcrealm 名称作为默认领域。
你的权利..正是这样
GlassFish 不会重定向到登录表单页面,并且对受限资源的访问不受限制
我认为这是因为 admin-realm admin 自动经过身份验证,当我尝试访问受限制的页面时,它会检查经过身份验证的用户,并且由于它是管理员并且它具有对页面的授权,因此该页面是可访问的并且不会提示登录。
当我运行应用程序并且不尝试登录到玻璃鱼的管理控制台时,这些仍然出现
Processing login with credentials of type: class com.sun.enterprise.security.auth.login.PasswordCredential
Logging in user [admin] into realm: admin-realm using JAAS module: fileRealm
Login module initialized: class com.sun.enterprise.security.auth.login.FileLoginModule
File login succeeded for: admin
JAAS login complete.
JAAS authentication committed.
Password login succeeded for : admin
permission check done to set SecurityContext
Set security context as user: admin
还有这些
(unresolved javax.security.jacc.WebUserDataPermission /security/* null)
(unresolved javax.security.jacc.WebUserDataPermission /:/security/* null)
(unresolved com.sun.corba.ee.impl.presentation.rmi.DynamicAccessPermission access null)
(unresolved javax.security.jacc.WebResourcePermission /:/security/* null)
(unresolved javax.security.jacc.WebResourcePermission /security/* !DELETE,GET,HEAD,OPTIONS,POST,PUT,TRACE)
(unresolved com.sun.enterprise.security.CORBAObjectPermission * *)
更新 2
我尝试使用<url-pattern>/*</url-pattern>
而不是<url-pattern>/security/*</url-pattern>
有趣的是,这就是我在跟踪中得到的。
Processing login with credentials of type: class com.sun.enterprise.security.auth.login.PasswordCredential
Logging in user [employee] into realm: emsSecurity using JAAS module: jdbcRealm
Login module initialized: class com.sun.enterprise.security.auth.login.JDBCLoginModule
JDBC login succeeded for: employee groups:[Ljava.lang.String;@16bfca4
JAAS login complete.
JAAS authentication committed.
Password login succeeded for : employee
permission check done to set SecurityContext
Set security context as user: employee
它进入拒绝访问页面。
'HTTP 状态 403 - 访问请求的资源已被拒绝'
我不明白 glassfish 如何在没有用户提交登录凭据的情况下对用户员工进行身份验证。它甚至说“密码登录成功:员工”。请帮我解决这个问题。
首先非常感谢您的努力。我仍然坚持这个问题。我在这里发布xml文件。
sun-web.xml
<security-role-mapping>
<role-name>Employee</role-name>
<group-name>Employee</group-name>
web.xml
<security-constraint>
<display-name>Login Constraint</display-name>
<web-resource-collection>
<web-resource-name>User Redirect page</web-resource-name>
<description/>
<url-pattern>/security/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
<http-method>HEAD</http-method>
<http-method>PUT</http-method>
<http-method>OPTIONS</http-method>
<http-method>TRACE</http-method>
<http-method>DELETE</http-method>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>Employee</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>deliverySecurity</realm-name>
<form-login-config>
<form-login-page>/Login.jsp</form-login-page>
<form-error-page>/index.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description/>
<role-name>Employee</role-name>
</security-role>
也没有堆栈跟踪。没有例外.. 用户只是被重定向到安全页面,就好像没有身份验证要求一样。这是一个使用 Netbeans 6.5.1 和 Glassfish v2 的 jsf 可视化 Web 开发项目。非常感谢。

