---
title: "OpenJWeb 1.6版本Java快速开发平台矩阵组织结构及Spring Security权限实现方法"
author: "cjc"
date: "2009-03-10T21:20:00Z"
tags: []
slug: "openjweb-1-6-java-spring-security"
draft: false
lastmod: "2009-03-10T21:20:00Z"
id: 446864
url: "https://cjc.iteye.com/blog/446864"
---

矩阵结构的数据库设计:

组织结构表(单位ID,部门ID,上级部门ID,...)

用户表(单位ID,部门ID,用户ID,用户名称,口令...)

组织结构关系表(部门ID,用户ID)

上述表中如何体现矩阵型的组织结构?在用户表中有一个部门ID,关联组织结构表的部门ID,这样部门和用户是一对多的,即一个行政部门有多个用户,一个用户只能属于一个行政部门;

利用组织结构表和组织结构关系表可建立多对多的组织结构-人员关系,这样用户除了属于一个行政部门外,如果要体现兼职,或者属于多个群组,可利用此表存储多对多关系.这样即有组织结构表反映垂直的组织结构关系,又可利用组织结构-人员多对多关系建立任意的关联.

在使用了Spring Security的权限框架的系统中,一个完整的用户权限集合是:

用户-权限+用户-角色-权限+用户按行政部门的组织结构权限+用户按群组(即多对多的组织结构)划分获得的权限,在openjweb中实现了所有上述权限,其数据库的视图参考如下:

create or replace view v\_user\_auth as  
select a.user\_id,a.login\_id,b.comm\_code,b.auth\_name,b.auth\_resource from  
comm\_user a,comm\_auth b ,comm\_user\_auth c  
where c.user\_id = a.user\_id  
and c.auth\_id = b.auth\_id  
union  
select a.user\_id,a.login\_id,b.comm\_code,b.auth\_name,b.auth\_resource from  
comm\_user a,comm\_auth b , comm\_user\_role d,comm\_role\_auth e  
where a.user\_id = d.user\_id  
and d.role\_id = e.role\_id  
and e.auth\_id = b.auth\_id

union  
select distinct a.user\_id,a.login\_id,b.comm\_code,b.auth\_name,b.auth\_resource from  
comm\_user a,comm\_auth b , comm\_org\_emp\_rel d,comm\_dept\_auth e  
where a.user\_id = d.user\_id  
and d.org\_id = e.dept\_id  
and e.auth\_id = b.auth\_id

union

select distinct a.user\_id,a.login\_id,b.comm\_code,b.auth\_name,b.auth\_resource from  
comm\_user a,comm\_auth b ,comm\_dept d ,comm\_dept\_auth e  
where a.dept\_id = d.pk\_id  
and d.row\_id = e.dept\_id  
and e.auth\_id = b.auth\_id;

说明:comm\_auth为权限基本信息表;

comm\_user\_auth为用户权限关系表

comm\_user\_role为用户角色关系表

comm\_role\_auth为角色权限关系表

comm\_roles为角色表

comm\_org\_emp\_rel为组织结构人员关系表(即多对多关系表)

comm\_dept\_auth为组织结构权限表

comm\_dept为组织结构基本信息表

目前openjweb已经实现了用户,角色,权限,组织结构基本信息录入及用户-权限,用户-角色关联，角色授权,组织结构-人员多对多维护,组织结构授权等功能,形成了一个完整的权限管理解决方案.