Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
有来技术
youlai-mall
提交
f6866749
Y
youlai-mall
项目概览
有来技术
/
youlai-mall
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
youlai-mall
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f6866749
编写于
7月 05, 2021
作者:
D
DaniR
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop-local' into develop
上级
3f89c119
fd72b5de
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
124 addition
and
4 deletion
+124
-4
youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/SysPermissionServiceImpl.java
...m/youlai/admin/service/impl/SysPermissionServiceImpl.java
+2
-0
youlai-common/common-redis/src/main/java/com/youlai/common/redis/RedisConfig.java
...is/src/main/java/com/youlai/common/redis/RedisConfig.java
+0
-1
youlai-gateway/src/main/java/com/youlai/gateway/component/AdminRoleLocalCache.java
...ava/com/youlai/gateway/component/AdminRoleLocalCache.java
+45
-0
youlai-gateway/src/main/java/com/youlai/gateway/component/RedisChannelListener.java
...va/com/youlai/gateway/component/RedisChannelListener.java
+23
-0
youlai-gateway/src/main/java/com/youlai/gateway/config/RedisGatewyConfig.java
...ain/java/com/youlai/gateway/config/RedisGatewyConfig.java
+40
-0
youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerManager.java
...va/com/youlai/gateway/security/ResourceServerManager.java
+14
-3
未找到文件。
youlai-admin/admin-boot/src/main/java/com/youlai/admin/service/impl/SysPermissionServiceImpl.java
浏览文件 @
f6866749
...
...
@@ -21,6 +21,7 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
@Autowired
private
RedisTemplate
redisTemplate
;
@Override
public
List
<
SysPermission
>
listPermRoles
()
{
return
this
.
baseMapper
.
listPermRoles
();
...
...
@@ -50,6 +51,7 @@ public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionMapper, S
urlPermRoles
.
put
(
perm
,
roles
);
});
redisTemplate
.
opsForHash
().
putAll
(
GlobalConstants
.
URL_PERM_ROLES_KEY
,
urlPermRoles
);
redisTemplate
.
convertAndSend
(
"cleanRoleLocalCache"
,
"true"
);
}
// 初始化URL【按钮->角色(集合)】规则
List
<
SysPermission
>
btnPermList
=
permissions
.
stream
()
...
...
youlai-common/common-redis/src/main/java/com/youlai/common/redis/RedisConfig.java
浏览文件 @
f6866749
...
...
@@ -16,7 +16,6 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
@AutoConfigureBefore
(
RedisAutoConfiguration
.
class
)
public
class
RedisConfig
{
@Bean
public
RedisTemplate
<
String
,
Object
>
redisTemplate
(
LettuceConnectionFactory
lettuceConnectionFactory
)
{
...
...
youlai-gateway/src/main/java/com/youlai/gateway/component/AdminRoleLocalCache.java
0 → 100644
浏览文件 @
f6866749
package
com.youlai.gateway.component
;
import
com.google.common.cache.Cache
;
import
com.google.common.cache.CacheBuilder
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
/**
* @author DaniR
* @version 1.0
* @description 本地缓存设置
* @createDate 2021/6/16 10:08
*/
@Slf4j
@Component
public
class
AdminRoleLocalCache
<
T
>
{
private
Cache
<
String
,
T
>
localCache
=
null
;
@PostConstruct
private
void
init
(){
localCache
=
CacheBuilder
.
newBuilder
()
//设置本地缓存容器的初始容量
.
initialCapacity
(
1
)
//设置本地缓存的最大容量
.
maximumSize
(
10
)
//设置写缓存后多少秒过期
.
expireAfterWrite
(
120
,
TimeUnit
.
SECONDS
).
build
();
}
public
void
setLocalCache
(
String
key
,
T
object
){
localCache
.
put
(
key
,
object
);
}
public
<
T
>
T
getCache
(
String
key
){
return
(
T
)
localCache
.
getIfPresent
(
key
);
}
public
void
remove
(
String
key
){
localCache
.
invalidate
(
key
);
}
}
youlai-gateway/src/main/java/com/youlai/gateway/component/RedisChannelListener.java
0 → 100644
浏览文件 @
f6866749
package
com.youlai.gateway.component
;
import
cn.hutool.core.util.StrUtil
;
import
com.youlai.common.constant.GlobalConstants
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.connection.Message
;
import
org.springframework.data.redis.connection.MessageListener
;
import
java.nio.charset.StandardCharsets
;
public
class
RedisChannelListener
implements
MessageListener
{
@Autowired
private
AdminRoleLocalCache
adminRoleLocalCache
;
@Override
public
void
onMessage
(
Message
message
,
byte
[]
bytes
)
{
String
msg
=
new
String
(
message
.
getBody
(),
StandardCharsets
.
UTF_8
);
String
channel
=
new
String
(
message
.
getChannel
(),
StandardCharsets
.
UTF_8
);
adminRoleLocalCache
.
remove
(
GlobalConstants
.
URL_PERM_ROLES_KEY
);
}
}
youlai-gateway/src/main/java/com/youlai/gateway/config/RedisGatewyConfig.java
0 → 100644
浏览文件 @
f6866749
package
com.youlai.gateway.config
;
import
com.youlai.gateway.component.RedisChannelListener
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.data.redis.connection.RedisConnectionFactory
;
import
org.springframework.data.redis.listener.ChannelTopic
;
import
org.springframework.data.redis.listener.RedisMessageListenerContainer
;
import
org.springframework.data.redis.listener.adapter.MessageListenerAdapter
;
@Configuration
public
class
RedisGatewyConfig
{
@Autowired
private
RedisConnectionFactory
connectionFactory
;
@Bean
public
RedisMessageListenerContainer
redisMessageListenerContainer
(){
RedisMessageListenerContainer
container
=
new
RedisMessageListenerContainer
();
container
.
setConnectionFactory
(
connectionFactory
);
container
.
addMessageListener
(
messageListenerAdapter
(),
channelTopic
());
return
container
;
}
@Bean
MessageListenerAdapter
messageListenerAdapter
(){
return
new
MessageListenerAdapter
(
redisChannelListener
());
}
@Bean
RedisChannelListener
redisChannelListener
(){
return
new
RedisChannelListener
();
}
@Bean
ChannelTopic
channelTopic
(){
return
new
ChannelTopic
(
"cleanRoleLocalCache"
);
}
}
youlai-gateway/src/main/java/com/youlai/gateway/security/ResourceServerManager.java
浏览文件 @
f6866749
...
...
@@ -8,8 +8,10 @@ import cn.hutool.json.JSONObject;
import
cn.hutool.json.JSONUtil
;
import
com.youlai.common.constant.AuthConstants
;
import
com.youlai.common.constant.GlobalConstants
;
import
com.youlai.gateway.component.AdminRoleLocalCache
;
import
lombok.AllArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.server.reactive.ServerHttpRequest
;
...
...
@@ -39,7 +41,11 @@ import java.util.Set;
public
class
ResourceServerManager
implements
ReactiveAuthorizationManager
<
AuthorizationContext
>
{
private
RedisTemplate
redisTemplate
;
private
AdminRoleLocalCache
adminRoleLocalCache
;
// 是否演示环境
@Value
(
"${demo}"
)
private
Boolean
isDemoEnv
;
@Override
public
Mono
<
AuthorizationDecision
>
check
(
Mono
<
Authentication
>
mono
,
AuthorizationContext
authorizationContext
)
{
ServerHttpRequest
request
=
authorizationContext
.
getExchange
().
getRequest
();
...
...
@@ -65,9 +71,14 @@ public class ResourceServerManager implements ReactiveAuthorizationManager<Autho
// Restful接口权限设计 @link https://www.cnblogs.com/haoxianrui/p/14396990.html
String
restfulPath
=
request
.
getMethodValue
()
+
":"
+
path
;
log
.
info
(
"请求方法:RESTFul请求路径:{}"
,
restfulPath
);
Map
<
String
,
Object
>
permRolesRules
=
(
Map
<
String
,
Object
>)
adminRoleLocalCache
.
getCache
(
GlobalConstants
.
URL_PERM_ROLES_KEY
);
if
(
isDemoEnv
){
// 缓存取【URL权限标识->角色集合】权限规则
Map
<
String
,
Object
>
permRolesRules
=
redisTemplate
.
opsForHash
().
entries
(
GlobalConstants
.
URL_PERM_ROLES_KEY
);
if
(
null
==
permRolesRules
){
permRolesRules
=
redisTemplate
.
opsForHash
().
entries
(
GlobalConstants
.
URL_PERM_ROLES_KEY
);
adminRoleLocalCache
.
setLocalCache
(
GlobalConstants
.
URL_PERM_ROLES_KEY
,
permRolesRules
);
}
}
// 根据 “请求路径” 和 权限规则中的“URL权限标识”进行Ant匹配,得出拥有权限的角色集合
Set
<
String
>
hasPermissionRoles
=
CollectionUtil
.
newHashSet
();
// 【声明定义】有权限的角色集合
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录