我们解决这个问题的方法是规范化数据库并为 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>