简体   繁体   English

GlassFish JDBC领域组成员

[英]GlassFish JDBC Realm Group Membership

I have been busy setting up authentication, a JDBC realm in particular, on GlassFish 3.1. 我一直忙于在GlassFish 3.1上设置身份验证,特别是JDBC领域。 I have been operating under the assumption that: 我一直在假设:

  • The "User" table contains the login name ("email_address") and the password ("password") “用户”表包含登录名(“email_address”)和密码(“密码”)
  • The "Group" table contains a list of group names ("name") “组”表包含组名列表(“名称”)
  • A "User_Group" table matches users and groups up. “User_Group”表与用户和组匹配。

Nowhere was I able to configure the "User_Group" table however so I was left wondering how the server would ever be able to match users up to groups. 我无处可配置“User_Group”表,但是我想知道服务器如何能够将用户与组匹配。 Needless to say it did not work. 不用说它没用。 Closer inspection however suggests that: 然而,仔细检查表明:

  • The "User" table contains the login name ("email_address") and the password ("password") “用户”表包含登录名(“email_address”)和密码(“密码”)
  • The "Group" table contains the login name ("email_address") as primary key , and a comma-separated list of group names ("Administrator,User") in a single column ("groups") “组”表包含登录名(“email_address”) 作为主键 ,以及以逗号分隔的组名列表(“Administrator,User”)在一列中(“组”)

Is this correct and, if so, why go through the trouble of creating a separate "Group" table? 这是正确的,如果是这样,为什么要经历创建单独的“组”表的麻烦? Since it seems you can have only one grouplist per login ("email_address") wouldn't it be just as easy as to simply add a column called "groups" to the "User" table and discard the "Group" table altogether? 由于看起来每次登录只能有一个组列表(“email_address”),只是简单地将一个名为“groups”的列添加到“User”表中并完全丢弃“Group”表就不那么容易了吗?

Thanks! 谢谢!

I'm not sure what material you've followed to configure the JDBC realm, but it appear to be incomplete or incorrect. 我不确定您配置JDBC领域的材料是什么,但它看起来不完整或不正确。 Following is a description of the configuration I've used to configure the JDBC realm. 以下是我用于配置JDBC领域的配置的描述。


The database structure (as DDL statements): 数据库结构(作为DDL语句):

The USERS table USERS表

CREATE TABLE USERS (
        USERID VARCHAR(50) NOT NULL,
        PASSWORD VARCHAR(128) NOT NULL
    );

--//@UNDO

DROP TABLE USERS;

The GROUPS table GROUPS表

CREATE TABLE GROUPS (
        GROUPID VARCHAR(20) NOT NULL
    );

--//@UNDO

DROP TABLE GROUPS;

The USERS_GROUPS join table USERS_GROUPS联接表

CREATE TABLE USERS_GROUPS (
        GROUPID VARCHAR(20) NOT NULL,
        USERID VARCHAR(50) NOT NULL
    );

--//@UNDO

DROP TABLE USERS_GROUPS;

The Glassfish JDBCRealm configuration snippet from domain.xml : 来自domain.xml的Glassfish JDBCRealm配置代码段:

    <auth-realm name="MyRealm" classname="com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm">
      <property description="null" name="jaas-context" value="jdbcRealm"></property>
      <property name="encoding" value="Hex"></property>
      <property description="null" name="password-column" value="PASSWORD"></property>
      <property name="datasource-jndi" value="jdbc/myDS"></property>
      <property name="group-table" value="USERS_GROUPS"></property>
      <property name="user-table" value="USERS"></property>
      <property description="null" name="group-name-column" value="GROUPID"></property>
      <property name="digest-algorithm" value="SHA-512"></property>
      <property description="null" name="user-name-column" value="USERID"></property>
    </auth-realm>

Note, the group-name-column attribute having a value of GROUPID , which maps to the GROUPID column of the join table USERS_GROUPS and not the group table GROUPS . 注意, group-name-column属性的值为GROUPID ,它映射到连接表USERS_GROUPSGROUPID列,而不是组表GROUPS This is because the JDBCRealm issues the following SQL statements (if you decompile the com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm class): 这是因为JDBCRealm发出以下SQL语句(如果您反编译com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm类):

The password query, with the user Id being the parameter that is passed from the DigestLoginModule: 密码查询,用户Id是从DigestLoginModule传递的参数:

SELECT <passwordColumn> FROM <userTable> WHERE <userNameColumn> = ?

The group query, with the user Id being passed as the parameter: 组查询,用户ID作为参数传递:

SELECT <groupNameColumn> FROM <groupTable> WHERE <groupTableUserNameColumn> = ?;

When you consider the second query's structure, it is quite obvious that the group Table must either contain the user Id mapped to a group Id (which leads to duplication of group data for users mapped to multiple groups), or that the group Table must be the join table that maps users to groups. 当您考虑第二个查询的结构时,很明显组表必须包含映射到组ID的用户ID(这会导致映射到多个组的用户的组数据重复),或者组表必须是将用户映射到组的连接表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM