我用Glassfish 3.1 + JDBCRealm + MySQL (MD5)实现了基于表单的自定义。我只有两个角色,用户和管理员。一切都很顺利,我从日志中可以看出,身份验证在这两种情况下都是作为uset和admin工作的(下面是观察日志)。
Q1:是否可以创建两个不同的索引文件,以便当用户是admin时,他/她转到/admin/index.xhtml,当用户是角色用户时,直接转到faces/ user /index.xhtml?
Q2:现在当我以用户身份登录时,我仍然可以直接写入整个链接到浏览器中的地址字段,为什么ja可以避免这种情况呢?
Q3:当我以用户身份登录并且欢迎文件列表中只有faces/admin/index.xhtml时,它将我重定向到该文件,即使xml文件告诉了其他内容,为什么?
<welcome-file-list>
<welcome-file>faces/admin/index.xhtml</welcome-file> *?? ----> it goes always here, cause it is the first one I think?*
<welcome-file>faces/user/index.xhtml</welcome-file>
</welcome-file-list>
<security-constraint>
<display-name>Admin Pages</display-name>
<web-resource-collection>
<web-resource-name>Protected Admin Area</web-resource-name>
<description/>
<url-pattern>/faces/admin/*</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>admin</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<display-name>User Pages</display-name>
<web-resource-collection>
<web-resource-name>Protected Users Area</web-resource-name>
<description/>
<url-pattern>/faces/users/*</url-pattern>
<!--url-pattern>/faces/users/index.xhtml</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>user</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>JDBCRealm</realm-name>
<form-login-config>
<form-login-page>/faces/loginForm.xhtml</form-login-page>
<form-error-page>/faces/loginError.xhtml</form-error-page>
</form-login-config>
</login-config>
</web-app>日志:
FINE: Login module initialized: class com.sun.enterprise.security.auth.login.JDBCLoginModule
FINEST: JDBC login succeeded for: admin groups:[admin, user]
FINE: JAAS login complete.
FINE: JAAS authentication committed.
FINE: Password login succeeded for : admin
FINE: Set security context as user: admin
FINE: [Web-Security] Setting Policy Context ID: old = null ctxID = jdbcrealm/jdbcrealm
FINE: [Web-Security] hasUserDataPermission perm: (javax.security.jacc.WebUserDataPermission GET)
FINE: [Web-Security] hasUserDataPermission isGranted: true
FINE: [Web-Security] Policy Context ID was: jdbcrealm/jdbcrealm
FINE: [Web-Security] Codesource with Web URL: file:/jdbcrealm/jdbcrealm
FINE: [Web-Security] Checking Web Permission with Principals : null(在我恐惧的答案后编辑)-在glassfish-web.xml中-我有这样的角色。如果我正确地理解了它,这意味着管理属于组管理、客户和用户。客户属于组:客户和用户,用户属于组用户。我理解得对吗?
<security-role-mapping>
<role-name>admin</role-name>
<group-name>admin</group-name>
<group-name>customer</group-name>
<group-name>user</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>customer</role-name>
<group-name>customer</group-name>
<group-name>user</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>user</role-name>
<group-name>user</group-name>
</security-role-mapping>
</glassfish-web-app>谢谢!萨米语
发布于 2012-02-29 12:10:11
A1)欢迎文件与角色无关。如果您需要执行任何类型的逻辑来调度用户,则需要考虑使用布尔型HttpServletRequest.isUserInRole(字符串角色)或类似的方法来找出用户在哪个角色中。
A2)这种事不应该发生。您需要检查您在JDBCRealm中的角色。据我所见,一切都是以正确的方式配置的。
( A3)我不确定我是否理解你所说的"XML“文件的正确方式。但欢迎-文件不一定与角色和..。见A1)
谢谢你,M
发布于 2020-04-29 12:20:01
我刚刚尝试了这一点,作为大学课程的一部分,下面是我如何获得我认为您想要的功能。我将Netbeans与Glassfish 4.1.1服务器结合使用,并且已经在服务器文件领域中配置了用户角色。
我的项目有3个文件:
index.xhtml users/mainmenu.xhtml admin/mainmenu.xhtml
欢迎页面设置为index.xhtml,具有以下超链接:
<h4>
<a href="/ED-Secure-war/faces/admin/mainmenu.xhtml">
Admin Login
</a>
</h4>
<h4>
<a href="/ED-Secure-war/faces/user/mainmenu.xhtml">
User Login
</a>
</h4>现在,由于每个用户组的访问都受到限制,所以当您单击索引上的超链接时,系统会提示您登录。如果您为管理链接输入一个有效的管理登录名,您将被重定向到admin/mainmenu.xhtml,反之亦然。
https://stackoverflow.com/questions/9471493
复制相似问题