Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
long-tern-care-service
Project
Project
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
hubin
long-tern-care-service
Commits
e6c4ee2e
Commit
e6c4ee2e
authored
Feb 17, 2023
by
maqing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
启动优化
parent
b91156fc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
30 deletions
+60
-30
SystemResourceinterface.java
...graim/ltc/pojo/entity/system/SystemResourceinterface.java
+11
-0
AuthorizationManager.java
...m/hungraim/ltc/gateway/security/AuthorizationManager.java
+8
-7
SystemInterfaceMapper.java
...va/com/hungraim/ltc/system/dao/SystemInterfaceMapper.java
+9
-4
SystemInterfaceServiceImpl.java
...m/ltc/system/service/impl/SystemInterfaceServiceImpl.java
+32
-19
No files found.
common/common-core/src/main/java/com/hungraim/ltc/pojo/entity/system/SystemResourceinterface.java
0 → 100644
View file @
e6c4ee2e
package
com
.
hungraim
.
ltc
.
pojo
.
entity
.
system
;
import
com.baomidou.mybatisplus.annotation.TableName
;
import
lombok.Data
;
@Data
@TableName
(
"LTC_RESOURCE_INTERFACE"
)
public
class
SystemResourceinterface
{
private
Long
resourceId
;
private
Long
interfaceId
;
}
gateway-service/src/main/java/com/hungraim/ltc/gateway/security/AuthorizationManager.java
View file @
e6c4ee2e
...
...
@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
import
com.alibaba.fastjson.JSONObject
;
import
com.hungraim.ltc.constant.AuthConstants
;
import
com.hungraim.ltc.pojo.entity.system.SystemInterface
;
import
com.hungraim.ltc.pojo.entity.system.SystemRoleResource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.collections4.ListUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -87,14 +88,14 @@ public class AuthorizationManager implements ReactiveAuthorizationManager<Author
String
[]
splitpath
=
path
.
split
(
"/"
);
String
pathNew
=
"/"
+
splitpath
[
1
]
+
"/"
+
splitpath
[
2
]
+
"/*"
;
Set
<
String
>
authorities
=
new
HashSet
<>();
Map
<
String
,
List
<
Long
>>
rolesResources
=
redisTemplate
.
opsForHash
().
entries
(
AuthConstants
.
PERMISSION_ROLES_RESOURCE_KEY
);
Map
<
String
,
List
<
S
ystemInterface
>>
interfaces
=
redisTemplate
.
opsForHash
().
entries
(
AuthConstants
.
PERMISSION_RESOURCE_INTERFACE_KEY
);
List
<
Long
>
resources
=
rolesResources
.
get
(
roleId
);
for
(
Long
resource
:
resources
)
{
List
<
S
ystemInterface
>
systemInterfaces
=
interfaces
.
get
(
resource
.
toString
());
Map
<
String
,
List
<
SystemRoleResource
>>
rolesResources
=
redisTemplate
.
opsForHash
().
entries
(
AuthConstants
.
PERMISSION_ROLES_RESOURCE_KEY
);
Map
<
String
,
List
<
S
tring
>>
interfaces
=
redisTemplate
.
opsForHash
().
entries
(
AuthConstants
.
PERMISSION_RESOURCE_INTERFACE_KEY
);
List
<
SystemRoleResource
>
resources
=
rolesResources
.
get
(
roleId
);
for
(
SystemRoleResource
resource
:
resources
)
{
List
<
S
tring
>
systemInterfaces
=
interfaces
.
get
(
resource
.
getResourceId
()
.
toString
());
if
(
systemInterfaces
!=
null
&&
systemInterfaces
.
size
()
>
0
)
{
for
(
S
ystemInterface
iter
:
systemInterfaces
)
{
if
(
pathMatcher
.
match
(
iter
.
getInterfaceUrl
()
,
pathNew
))
{
for
(
S
tring
iter
:
systemInterfaces
)
{
if
(
pathMatcher
.
match
(
iter
,
pathNew
))
{
authorities
.
addAll
(
Convert
.
toList
(
String
.
class
,
roleId
));
}
}
...
...
system/system-admin-service/src/main/java/com/hungraim/ltc/system/dao/SystemInterfaceMapper.java
View file @
e6c4ee2e
...
...
@@ -3,6 +3,8 @@ package com.hungraim.ltc.system.dao;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.hungraim.ltc.pojo.entity.system.SystemInterface
;
import
com.hungraim.ltc.pojo.entity.system.SystemResource
;
import
com.hungraim.ltc.pojo.entity.system.SystemResourceinterface
;
import
com.hungraim.ltc.pojo.entity.system.SystemRoleResource
;
import
org.apache.ibatis.annotations.*
;
import
java.util.List
;
...
...
@@ -14,14 +16,17 @@ import java.util.List;
@Mapper
public
interface
SystemInterfaceMapper
extends
BaseMapper
<
SystemInterface
>
{
@Select
(
"SELECT a.INTERFACE_ID,a.INTERFACE_URL FROM LTC_INTERFACE a,LTC_RESOURCE_INTERFACE e where a.INTERFACE_ID=e.INTERFACE_ID and e.RESOURCE_ID=#{resourceId}"
)
List
<
SystemInterface
>
listInterface
(
Long
resourceId
);
@Select
(
"SELECT a.INTERFACE_ID,a.INTERFACE_URL FROM LTC_INTERFACE a"
)
List
<
SystemInterface
>
listInterface
();
@Select
(
"select c.RESOURCE_ID,c.INTERFACE_ID from LTC_RESOURCE_INTERFACE c"
)
List
<
SystemResourceinterface
>
listResourceInterface
();
@Select
(
"select b.ROLE_ID from LTC_ROLE b"
)
List
<
Long
>
listRole
();
@Select
(
"select c.RESOURCE_ID
from LTC_ROLE_RESOURCE c WHERE c.ROLE_ID=#{roleId}
"
)
List
<
Long
>
listRoleResource
(
Long
roleId
);
@Select
(
"select c.RESOURCE_ID
,c.ROLE_ID from LTC_ROLE_RESOURCE c
"
)
List
<
SystemRoleResource
>
listRoleResource
(
);
}
system/system-admin-service/src/main/java/com/hungraim/ltc/system/service/impl/SystemInterfaceServiceImpl.java
View file @
e6c4ee2e
...
...
@@ -3,6 +3,8 @@ package com.hungraim.ltc.system.service.impl;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.hungraim.ltc.constant.AuthConstants
;
import
com.hungraim.ltc.pojo.entity.system.SystemInterface
;
import
com.hungraim.ltc.pojo.entity.system.SystemResourceinterface
;
import
com.hungraim.ltc.pojo.entity.system.SystemRoleResource
;
import
com.hungraim.ltc.system.dao.SystemInterfaceMapper
;
import
com.hungraim.ltc.system.service.ISystemInterfaceService
;
import
lombok.extern.slf4j.Slf4j
;
...
...
@@ -11,6 +13,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* @author mq
...
...
@@ -34,29 +37,39 @@ public class SystemInterfaceServiceImpl extends ServiceImpl<SystemInterfaceMappe
@Override
public
void
listResourceInterface
()
{
try
{
redisTemplate
.
delete
(
AuthConstants
.
PERMISSION_RESOURCE_INTERFACE_KEY
);
redisTemplate
.
delete
(
AuthConstants
.
PERMISSION_ROLES_RESOURCE_KEY
);
Map
<
String
,
List
<
Long
>>
roleResourcesMap
=
new
TreeMap
<>();
Map
<
String
,
List
<
SystemInterface
>>
stringStringHashMap
=
new
HashMap
<>();
Map
<
String
,
List
<
SystemRoleResource
>>
roleResourcesMap
=
new
TreeMap
<>();
Map
<
String
,
List
<
String
>>
stringStringHashMap
=
new
HashMap
<>();
//角色数据
List
<
Long
>
roles
=
systemInterfaceMapper
.
listRole
();
String
roleId
;
for
(
Long
role
:
roles
)
{
List
<
Long
>
roleResources
=
systemInterfaceMapper
.
listRoleResource
(
role
);
//保存资源和接口
for
(
Long
roleResource:
roleResources
){
List
<
SystemInterface
>
systemInterfaces
=
systemInterfaceMapper
.
listInterface
(
roleResource
);
stringStringHashMap
.
put
(
roleResource
.
toString
(),
systemInterfaces
);
}
// 转换 roles -> ROLE_{roleId}
roleId
=
AuthConstants
.
AUTHORITY_PREFIX
+
role
;
//保存角色和资源
roleResourcesMap
.
put
(
roleId
,
roleResources
);
}
//角色和资源数据
List
<
SystemRoleResource
>
roleResources
=
systemInterfaceMapper
.
listRoleResource
();
//资源和接口数据
List
<
SystemResourceinterface
>
resourceInterface
=
systemInterfaceMapper
.
listResourceInterface
();
//接口数据
List
<
SystemInterface
>
systemInterfaces
=
systemInterfaceMapper
.
listInterface
();
roles
.
stream
().
forEach
(
role
->
{
//角色和资源数据
List
<
SystemRoleResource
>
roleResourceList
=
roleResources
.
stream
().
filter
(
roleResource
->
roleResource
.
getRoleId
().
equals
(
role
)).
collect
(
Collectors
.
toList
());
roleResourceList
.
stream
().
forEach
(
roleResource
->
{
//资源和接口数据
List
<
SystemResourceinterface
>
resourceinterfaceList
=
resourceInterface
.
stream
().
filter
(
role2
->
role2
.
getResourceId
().
equals
(
roleResource
.
getResourceId
())).
collect
(
Collectors
.
toList
());
List
<
String
>
systemResourceinterfaces
=
new
ArrayList
<>();
resourceinterfaceList
.
stream
().
forEach
(
resourceinterface
->{
List
<
SystemInterface
>
collect
=
systemInterfaces
.
stream
().
filter
(
role2
->
role2
.
getInterfaceId
().
equals
(
resourceinterface
.
getInterfaceId
())).
collect
(
Collectors
.
toList
());
systemResourceinterfaces
.
add
(
collect
.
get
(
0
).
getInterfaceUrl
());
});
//资源和接口
stringStringHashMap
.
put
(
roleResource
.
getResourceId
().
toString
(),
systemResourceinterfaces
);
});
//角色和资源
roleResourcesMap
.
put
(
AuthConstants
.
AUTHORITY_PREFIX
+
role
.
toString
(),
roleResourceList
);
});
redisTemplate
.
opsForHash
().
putAll
(
AuthConstants
.
PERMISSION_ROLES_RESOURCE_KEY
,
roleResourcesMap
);
redisTemplate
.
opsForHash
().
putAll
(
AuthConstants
.
PERMISSION_RESOURCE_INTERFACE_KEY
,
stringStringHashMap
);
}
catch
(
RuntimeException
e
){
e
.
printStackTrace
();
}
}
}
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