关于 GlassFish/Tomcat 安全领域的问题

发布于 2024-10-21 00:03:07 字数 661 浏览 2 评论 0原文

我将 GlassFish 设置为使用“JDBCRealm”。配置看起来像这样并且工作正常:

<JDBCRealm userTable="users" userNameCol="user_name" 
userCredCol="user_pass" userRoleTable="user_roles" 
roleNameCol="role_name" ... />

我的数据库当前看起来像这样:

- USERS -
USER_NAME | USER_PASS
steve | password1

- USER_ROLES -
USER_NAME | ROLE_NAME
steve | ADMIN

我的问题是,如果我想规范化数据库中的数据,如何配置一个可以理解新数据库设计的领域?我是否必须编写自定义“领域”对象或类似的东西?

相反,我希望我的数据库看起来像这样:

- USERS -
USER_ID | USER_NAME | USER_PASS
1 | steve | password1

- ROLES -
ROLE_ID | ROLE_NAME
2 | ADMIN

- USER_ROLES -
USER_ID | ROLE_ID
1 | 2

非常感谢任何帮助!

I have GlassFish set up to use "JDBCRealm". The configuration looks like this and it works fine:

<JDBCRealm userTable="users" userNameCol="user_name" 
userCredCol="user_pass" userRoleTable="user_roles" 
roleNameCol="role_name" ... />

My database currently looks like this:

- USERS -
USER_NAME | USER_PASS
steve | password1

- USER_ROLES -
USER_NAME | ROLE_NAME
steve | ADMIN

My question is, if I want to normalize the data in the database, how do I configure a realm that can understand the new database design? Do I have to write a custom "realm" object or something like that?

Instead, I want my database to look something this:

- USERS -
USER_ID | USER_NAME | USER_PASS
1 | steve | password1

- ROLES -
ROLE_ID | ROLE_NAME
2 | ADMIN

- USER_ROLES -
USER_ID | ROLE_ID
1 | 2

Any help is greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淑女气质 2024-10-28 00:03:07

它应该工作简单。几天前我刚刚为 Glassfish 服务器做了这个。但我想Tomcat应该也是类似的。我有3个表:

  • 用户(登录(pk),密码,...)
  • 组(group_id(pk),group_name)
  • group_has_user(登录(来自用户表的fk),group_id(来自组表的fk))

我的JDBC领域看起来像下列:

<auth-realm name="Register-User" classname="com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm">
          <property name="jaas-context" value="jdbcRealm" />
          <property name="datasource-jndi" value="jdbc/ladb" />
          <property name="user-table" value="user" />
          <property name="user-name-column" value="login" />
          <property name="password-column" value="password" />
          <property name="group-table" value="group_has_user" />
          <property name="group-name-column" value="group_id" />
          <property name="digest-algorithm" value="SHA-256" />

如果遇到问题,请确保组表和连接表中的 group_id 列具有相同的名称。

It should work straightforward. I just did it a few days ago for Glassfish server. But I think it should be similar for Tomcat. I have 3 tables:

  • user (login (pk), password, ...)
  • group (group_id (pk), group_name)
  • group_has_user (login (fk from user table), group_id (fk from group table))

my JDBC Realm looks like the following:

<auth-realm name="Register-User" classname="com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm">
          <property name="jaas-context" value="jdbcRealm" />
          <property name="datasource-jndi" value="jdbc/ladb" />
          <property name="user-table" value="user" />
          <property name="user-name-column" value="login" />
          <property name="password-column" value="password" />
          <property name="group-table" value="group_has_user" />
          <property name="group-name-column" value="group_id" />
          <property name="digest-algorithm" value="SHA-256" />

If you experience problems, make shure that the columns group_id have the same name in group table and in the join-table.

囚我心虐我身 2024-10-28 00:03:07

我们解决这个问题的方法是标准化数据库并为 glassfish 创建视图。

                      Table "public.admin"
    Column     |            Type             | Modifiers 
---------------+-----------------------------+-----------
 id            | bigint                      | not null
 login         | character varying(255)      | not null
 password      | character varying(255)      | not null


             Table "public.role"
 Column |          Type          | Modifiers 
--------+------------------------+-----------
 id     | bigint                 | not null
 name   | character varying(255) | 



  Table "public.role_admins"
  Column  |  Type  | Modifiers 
----------+--------+-----------
 role_id  | bigint | not null
 admin_id | bigint | not null

这是视图:

           View "public.v_admin_role"
  Column   |          Type          | Modifiers 
-----------+------------------------+-----------
 login     | character varying(255) | 
 password  | character varying(255) | 
 role_name | character varying(255) | 
View definition:
 SELECT a.login, a.password, r.name AS role_name
   FROM admin a
   JOIN role_admins ra ON ra.admin_id = a.id
   JOIN role r ON r.id = ra.role_id
  WHERE a.active = true;

和配置

<auth-realm classname="com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm" name="gcsiadmin">
  <property name="user-name-column" value="login"/>
  <property name="password-column" value="password"/>
  <property name="group-name-column" value="role_name"/>
  <property name="datasource-jndi" value="jdbc/GcsiDS"/>
  <property name="user-table" value="v_admin_role"/>
  <property name="group-table" value="v_admin_role"/>
  <property name="jaas-context" value="jdbcRealm"/>
</auth-realm>

The way we tackle this issue is to normalize the database and create views for glassfish.

                      Table "public.admin"
    Column     |            Type             | Modifiers 
---------------+-----------------------------+-----------
 id            | bigint                      | not null
 login         | character varying(255)      | not null
 password      | character varying(255)      | not null


             Table "public.role"
 Column |          Type          | Modifiers 
--------+------------------------+-----------
 id     | bigint                 | not null
 name   | character varying(255) | 



  Table "public.role_admins"
  Column  |  Type  | Modifiers 
----------+--------+-----------
 role_id  | bigint | not null
 admin_id | bigint | not null

Here is the view:

           View "public.v_admin_role"
  Column   |          Type          | Modifiers 
-----------+------------------------+-----------
 login     | character varying(255) | 
 password  | character varying(255) | 
 role_name | character varying(255) | 
View definition:
 SELECT a.login, a.password, r.name AS role_name
   FROM admin a
   JOIN role_admins ra ON ra.admin_id = a.id
   JOIN role r ON r.id = ra.role_id
  WHERE a.active = true;

And the config

<auth-realm classname="com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm" name="gcsiadmin">
  <property name="user-name-column" value="login"/>
  <property name="password-column" value="password"/>
  <property name="group-name-column" value="role_name"/>
  <property name="datasource-jndi" value="jdbc/GcsiDS"/>
  <property name="user-table" value="v_admin_role"/>
  <property name="group-table" value="v_admin_role"/>
  <property name="jaas-context" value="jdbcRealm"/>
</auth-realm>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文