为什么我在jdbcRealm数据库中列出web.xml中的安全角色? [英] Why do I list security roles in web.xml when they're in jdbcRealm database?

查看:155
本文介绍了为什么我在jdbcRealm数据库中列出web.xml中的安全角色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Glassfish 3上运行JavaEE 6 Web应用程序。我使用JAAS和jdbcRealm以及默认主体到角色映射。在我的数据库中,我有用于将用户名映射到其角色的表:

I run JavaEE 6 web application on Glassfish 3. I use JAAS with jdbcRealm and default principal to role mapping. In my database I have table for mapping usernames to their roles:

 username | role
----------+-------
 john     | admin
 mary     | user

为什么我需要再次在 web中列出这些角色。 xml

<security-role>
  <role-name>admin</role-name>
</security-role>
<security-role>
  <role-name>user</role-name>
</security-role>

没有那个 isUserInRole()总是返回 false

推荐答案

您不会在<$ c中重新定义安全角色$ C>的web.xml 。您列出它们,以便应用程序服务器知道它们在您的代码中的使用。

You don't redefine security roles in web.xml. You list them so an application server knows about their use in your code.

部署安全应用程序时,应用程序服务器会读取部署描述符以获取有关安全性配置的信息。它知道您的应用程序中使用的角色。然后,应用程序可以使用角色,并期望应用程序服务器能够将它们映射到用户和组(最终再次解析为用户,因为用户是安全性最好的构建块)。

When you deploy a secured application, an application server reads a deployment descriptor to solicit information about security configuration. It knows about roles that are used in your application. The application can then use the roles and expect the application server is able to map them to users and groups (that ultimately resolve to users again as users are the security finest building blocks).

说到将角色映射到用户,这就是领域的来源。它提供了映射,因此您知道部署描述符中的角色X映射到数据库中的角色X,而角色X又映射到用户A和B.

Speaking of mapping roles to users, that's where a realm comes in. It offers the mapping so you know that a role X in a deployment descriptor maps to the role X in a database that in turn map to users A and B.

据说,jdbcRealm使用的数据库具有完全相同的角色,因为它们是应用程序服务器需要映射到应用程序中的角色的用户的密钥。

With that said, the database that's used by jdbcRealm has exactly the same roles because they're the keys to users that the application server needs to map to roles in the application.

您在代码中使用的内容和部署描述符是通过jdbcRealm提供的映射解析为真实用户的一组用户的逻辑名称。

What you use in your code and a deployment descriptor is a logical name of a group of users that are resolved to real users via the mapping that's offered by the jdbcRealm.

这篇关于为什么我在jdbcRealm数据库中列出web.xml中的安全角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆