Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
4425b81e
Commit
4425b81e
authored
Sep 30, 2018
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增数据权限过滤注解
parent
eb2a24dc
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
106 additions
and
35 deletions
+106
-35
sql/ruoyi.pdm
+0
-0
sql/ry_20180903.sql
+4
-4
src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
+69
-19
src/main/java/com/ruoyi/framework/aspectj/DataSourceAspect.java
+4
-4
src/main/java/com/ruoyi/framework/aspectj/lang/annotation/DataScope.java
+21
-0
src/main/java/com/ruoyi/framework/aspectj/lang/annotation/DataSource.java
+1
-1
src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
+1
-1
src/main/java/com/ruoyi/project/system/dept/service/DeptServiceImpl.java
+2
-2
src/main/java/com/ruoyi/project/system/role/service/RoleServiceImpl.java
+2
-2
src/main/java/com/ruoyi/project/system/user/service/UserServiceImpl.java
+2
-2
No files found.
sql/ruoyi.pdm
View file @
4425b81e
This source diff could not be displayed because it is too large. You can
view the blob
instead.
sql/ry_20180903.sql
View file @
4425b81e
...
...
@@ -374,8 +374,8 @@ insert into sys_role_dept values ('2', '105');
drop
table
if
exists
sys_user_post
;
create
table
sys_user_post
(
user_id
varchar
(
64
)
not
null
comment
'用户ID'
,
post_id
varchar
(
64
)
not
null
comment
'岗位ID'
,
user_id
int
(
11
)
not
null
comment
'用户ID'
,
post_id
int
(
11
)
not
null
comment
'岗位ID'
,
primary
key
(
user_id
,
post_id
)
)
engine
=
innodb
default
charset
=
utf8
comment
=
'用户与岗位关联表'
;
...
...
@@ -450,8 +450,8 @@ create table sys_dict_data
dict_label
varchar
(
100
)
default
''
comment
'字典标签'
,
dict_value
varchar
(
100
)
default
''
comment
'字典键值'
,
dict_type
varchar
(
100
)
default
''
comment
'字典类型'
,
css_class
varchar
(
5
00
)
default
''
comment
'样式属性(其他样式扩展)'
,
list_class
varchar
(
5
00
)
default
''
comment
'表格回显样式'
,
css_class
varchar
(
1
00
)
default
''
comment
'样式属性(其他样式扩展)'
,
list_class
varchar
(
1
00
)
default
''
comment
'表格回显样式'
,
is_default
char
(
1
)
default
'N'
comment
'是否默认(Y是 N否)'
,
status
char
(
1
)
default
'0'
comment
'状态(0正常 1停用)'
,
create_by
varchar
(
64
)
default
''
comment
'创建者'
,
...
...
src/main/java/com/ruoyi/framework/
datascope/DataScopeUtils
.java
→
src/main/java/com/ruoyi/framework/
aspectj/DataScopeAspect
.java
View file @
4425b81e
package
com
.
ruoyi
.
framework
.
datascope
;
package
com
.
ruoyi
.
framework
.
aspectj
;
import
java.lang.reflect.Method
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.stereotype.Component
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.security.ShiroUtils
;
import
com.ruoyi.framework.aspectj.lang.annotation.DataScope
;
import
com.ruoyi.framework.web.domain.BaseEntity
;
import
com.ruoyi.project.system.role.domain.Role
;
import
com.ruoyi.project.system.user.domain.User
;
/**
* 数据
范围
处理
* 数据
过滤
处理
*
* @author ruoyi
*/
public
class
DataScopeUtils
@Aspect
@Component
public
class
DataScopeAspect
{
/**
* 全部数据权限
...
...
@@ -23,13 +35,40 @@ public class DataScopeUtils
public
static
final
String
DATA_SCOPE_CUSTOM
=
"2"
;
/**
* 数据范围过滤
*
* @return 标准连接条件对象
* 数据权限过滤关键字
*/
public
static
String
dataScopeFilter
()
public
static
final
String
DATA_SCOPE
=
"dataScope"
;
// 配置织入点
@Pointcut
(
"@annotation(com.ruoyi.framework.aspectj.lang.annotation.DataScope)"
)
public
void
dataScopePointCut
()
{
}
@Before
(
"dataScopePointCut()"
)
public
void
doBefore
(
JoinPoint
point
)
throws
Throwable
{
return
dataScopeFilter
(
"u"
);
handleDataScope
(
point
);
}
protected
void
handleDataScope
(
final
JoinPoint
joinPoint
)
{
// 获得注解
DataScope
controllerDataScope
=
getAnnotationLog
(
joinPoint
);
if
(
controllerDataScope
==
null
)
{
return
;
}
// 获取当前的用户
User
currentUser
=
ShiroUtils
.
getUser
();
if
(
currentUser
!=
null
)
{
// 如果是超级管理员,则不过滤数据
if
(!
currentUser
.
isAdmin
())
{
dataScopeFilter
(
joinPoint
,
currentUser
,
controllerDataScope
.
tableAlias
());
}
}
}
/**
...
...
@@ -38,15 +77,8 @@ public class DataScopeUtils
* @param da 部门表别名
* @return 标准连接条件对象
*/
public
static
String
dataScopeFilter
(
String
da
)
public
static
void
dataScopeFilter
(
JoinPoint
joinPoint
,
User
user
,
String
alias
)
{
User
user
=
ShiroUtils
.
getUser
();
// 如果是超级管理员,则不过滤数据
if
(
user
.
isAdmin
())
{
return
StringUtils
.
EMPTY
;
}
StringBuilder
sqlString
=
new
StringBuilder
();
for
(
Role
role
:
user
.
getRoles
())
...
...
@@ -59,14 +91,32 @@ public class DataScopeUtils
}
else
if
(
DATA_SCOPE_CUSTOM
.
equals
(
dataScope
))
{
sqlString
.
append
(
StringUtils
.
format
(
" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) "
,
da
,
role
.
getRoleId
()));
sqlString
.
append
(
StringUtils
.
format
(
" OR {}.dept_id IN ( SELECT dept_id FROM sys_role_dept WHERE role_id = {} ) "
,
alias
,
role
.
getRoleId
()));
}
}
if
(
StringUtils
.
isNotBlank
(
sqlString
.
toString
()))
{
return
" AND ("
+
sqlString
.
substring
(
4
)
+
")"
;
BaseEntity
baseEntity
=
(
BaseEntity
)
joinPoint
.
getArgs
()[
0
];
baseEntity
.
getParams
().
put
(
DATA_SCOPE
,
" AND ("
+
sqlString
.
substring
(
4
)
+
")"
);
}
}
/**
* 是否存在注解,如果存在就获取
*/
private
DataScope
getAnnotationLog
(
JoinPoint
joinPoint
)
{
Signature
signature
=
joinPoint
.
getSignature
();
MethodSignature
methodSignature
=
(
MethodSignature
)
signature
;
Method
method
=
methodSignature
.
getMethod
();
if
(
method
!=
null
)
{
return
method
.
getAnnotation
(
DataScope
.
class
);
}
return
StringUtils
.
EMPTY
;
return
null
;
}
}
src/main/java/com/ruoyi/framework/aspectj/D
s
Aspect.java
→
src/main/java/com/ruoyi/framework/aspectj/D
ataSource
Aspect.java
View file @
4425b81e
...
...
@@ -11,7 +11,7 @@ import org.slf4j.LoggerFactory;
import
org.springframework.core.annotation.Order
;
import
org.springframework.stereotype.Component
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.framework.aspectj.lang.annotation.D
s
;
import
com.ruoyi.framework.aspectj.lang.annotation.D
ataSource
;
import
com.ruoyi.framework.datasource.DynamicDataSourceContextHolder
;
/**
...
...
@@ -22,11 +22,11 @@ import com.ruoyi.framework.datasource.DynamicDataSourceContextHolder;
@Aspect
@Order
(
1
)
@Component
public
class
D
s
Aspect
public
class
D
ataSource
Aspect
{
protected
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Pointcut
(
"@annotation(com.ruoyi.framework.aspectj.lang.annotation.D
s
)"
)
@Pointcut
(
"@annotation(com.ruoyi.framework.aspectj.lang.annotation.D
ataSource
)"
)
public
void
dsPointCut
()
{
...
...
@@ -39,7 +39,7 @@ public class DsAspect
Method
method
=
signature
.
getMethod
();
D
s
dataSource
=
method
.
getAnnotation
(
Ds
.
class
);
D
ataSource
dataSource
=
method
.
getAnnotation
(
DataSource
.
class
);
if
(
StringUtils
.
isNotNull
(
dataSource
))
{
...
...
src/main/java/com/ruoyi/framework/aspectj/lang/annotation/DataScope.java
0 → 100644
View file @
4425b81e
package
com
.
ruoyi
.
framework
.
aspectj
.
lang
.
annotation
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* 数据权限过滤注解
*
* @author ruoyi
*/
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
public
@interface
DataScope
{
/** 表的别名 */
String
tableAlias
()
default
""
;
}
src/main/java/com/ruoyi/framework/aspectj/lang/annotation/D
s
.java
→
src/main/java/com/ruoyi/framework/aspectj/lang/annotation/D
ataSource
.java
View file @
4425b81e
...
...
@@ -14,7 +14,7 @@ import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
*/
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
D
s
public
@interface
D
ataSource
{
/**
* 切换数据源名称
...
...
src/main/java/com/ruoyi/framework/config/ResourcesConfig.java
View file @
4425b81e
...
...
@@ -32,7 +32,7 @@ public class ResourcesConfig implements WebMvcConfigurer
@Override
public
void
addResourceHandlers
(
ResourceHandlerRegistry
registry
)
{
/**
头像
上传路径 */
/**
文件
上传路径 */
registry
.
addResourceHandler
(
"/profile/**"
).
addResourceLocations
(
"file:"
+
RuoYiConfig
.
getProfile
());
/** swagger配置 */
...
...
src/main/java/com/ruoyi/project/system/dept/service/DeptServiceImpl.java
View file @
4425b81e
...
...
@@ -9,7 +9,7 @@ import org.springframework.stereotype.Service;
import
com.ruoyi.common.constant.UserConstants
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.security.ShiroUtils
;
import
com.ruoyi.framework.
datascope.DataScopeUtils
;
import
com.ruoyi.framework.
aspectj.lang.annotation.DataScope
;
import
com.ruoyi.project.system.dept.domain.Dept
;
import
com.ruoyi.project.system.dept.mapper.DeptMapper
;
import
com.ruoyi.project.system.role.domain.Role
;
...
...
@@ -31,9 +31,9 @@ public class DeptServiceImpl implements IDeptService
* @return 部门信息集合
*/
@Override
@DataScope
(
tableAlias
=
"d"
)
public
List
<
Dept
>
selectDeptList
(
Dept
dept
)
{
dept
.
getParams
().
put
(
"dataScope"
,
DataScopeUtils
.
dataScopeFilter
(
"d"
));
return
deptMapper
.
selectDeptList
(
dept
);
}
...
...
src/main/java/com/ruoyi/project/system/role/service/RoleServiceImpl.java
View file @
4425b81e
...
...
@@ -11,7 +11,7 @@ import com.ruoyi.common.constant.UserConstants;
import
com.ruoyi.common.support.Convert
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.security.ShiroUtils
;
import
com.ruoyi.framework.
datascope.DataScopeUtils
;
import
com.ruoyi.framework.
aspectj.lang.annotation.DataScope
;
import
com.ruoyi.project.system.role.domain.Role
;
import
com.ruoyi.project.system.role.domain.RoleDept
;
import
com.ruoyi.project.system.role.domain.RoleMenu
;
...
...
@@ -48,9 +48,9 @@ public class RoleServiceImpl implements IRoleService
* @return 角色数据集合信息
*/
@Override
@DataScope
(
tableAlias
=
"u"
)
public
List
<
Role
>
selectRoleList
(
Role
role
)
{
role
.
getParams
().
put
(
"dataScope"
,
DataScopeUtils
.
dataScopeFilter
());
return
roleMapper
.
selectRoleList
(
role
);
}
...
...
src/main/java/com/ruoyi/project/system/user/service/UserServiceImpl.java
View file @
4425b81e
...
...
@@ -8,7 +8,7 @@ import com.ruoyi.common.constant.UserConstants;
import
com.ruoyi.common.support.Convert
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.security.ShiroUtils
;
import
com.ruoyi.framework.
datascope.DataScopeUtils
;
import
com.ruoyi.framework.
aspectj.lang.annotation.DataScope
;
import
com.ruoyi.framework.shiro.service.PasswordService
;
import
com.ruoyi.project.system.post.domain.Post
;
import
com.ruoyi.project.system.post.mapper.PostMapper
;
...
...
@@ -55,10 +55,10 @@ public class UserServiceImpl implements IUserService
* @return 用户信息集合信息
*/
@Override
@DataScope
(
tableAlias
=
"u"
)
public
List
<
User
>
selectUserList
(
User
user
)
{
// 生成数据权限过滤条件
user
.
getParams
().
put
(
"dataScope"
,
DataScopeUtils
.
dataScopeFilter
());
return
userMapper
.
selectUserList
(
user
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment