Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
e3efdf27
Commit
e3efdf27
authored
May 24, 2022
by
Zheng Jie
Browse files
Merge branch 'master' into deploy
parents
84e31988
d78e1dec
Changes
4
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/AuthorityDto.java
0 → 100644
View file @
e3efdf27
/*
* Copyright 2019-2020 Zheng Jie
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
me.zhengjie.modules.security.service.dto
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
org.springframework.security.core.GrantedAuthority
;
/**
* 避免序列化问题
* @author Zheng Jie
* @date 2018-11-30
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public
class
AuthorityDto
implements
GrantedAuthority
{
private
String
authority
;
}
eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java
View file @
e3efdf27
...
...
@@ -38,10 +38,10 @@ public class JwtUserDto implements UserDetails {
private
final
List
<
Long
>
dataScopes
;
@JSONField
(
serialize
=
false
)
private
final
List
<
Granted
Authority
>
authorities
;
private
final
List
<
Authority
Dto
>
authorities
;
public
Set
<
String
>
getRoles
()
{
return
authorities
.
stream
().
map
(
Granted
Authority:
:
getAuthority
).
collect
(
Collectors
.
toSet
());
return
authorities
.
stream
().
map
(
Authority
Dto
:
:
getAuthority
).
collect
(
Collectors
.
toSet
());
}
@Override
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/RoleService.java
View file @
e3efdf27
...
...
@@ -15,13 +15,13 @@
*/
package
me.zhengjie.modules.system.service
;
import
me.zhengjie.modules.security.service.dto.AuthorityDto
;
import
me.zhengjie.modules.system.domain.Role
;
import
me.zhengjie.modules.system.service.dto.RoleDto
;
import
me.zhengjie.modules.system.service.dto.RoleQueryCriteria
;
import
me.zhengjie.modules.system.service.dto.RoleSmallDto
;
import
me.zhengjie.modules.system.service.dto.UserDto
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.security.core.GrantedAuthority
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.List
;
...
...
@@ -119,7 +119,7 @@ public interface RoleService {
* @param user 用户信息
* @return 权限信息
*/
List
<
Granted
Authority
>
mapToGrantedAuthorities
(
UserDto
user
);
List
<
Authority
Dto
>
mapToGrantedAuthorities
(
UserDto
user
);
/**
* 验证是否被用户关联
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/RoleServiceImpl.java
View file @
e3efdf27
...
...
@@ -19,6 +19,7 @@ import cn.hutool.core.collection.CollectionUtil;
import
lombok.RequiredArgsConstructor
;
import
me.zhengjie.exception.BadRequestException
;
import
me.zhengjie.modules.security.service.UserCacheClean
;
import
me.zhengjie.modules.security.service.dto.AuthorityDto
;
import
me.zhengjie.modules.system.domain.Menu
;
import
me.zhengjie.modules.system.domain.Role
;
import
me.zhengjie.exception.EntityExistException
;
...
...
@@ -38,11 +39,8 @@ import org.springframework.cache.annotation.Cacheable;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.security.core.GrantedAuthority
;
import
org.springframework.security.core.authority.SimpleGrantedAuthority
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.IOException
;
import
java.util.*
;
...
...
@@ -166,19 +164,19 @@ public class RoleServiceImpl implements RoleService {
@Override
@Cacheable
(
key
=
"'auth:' + #p0.id"
)
public
List
<
Granted
Authority
>
mapToGrantedAuthorities
(
UserDto
user
)
{
public
List
<
Authority
Dto
>
mapToGrantedAuthorities
(
UserDto
user
)
{
Set
<
String
>
permissions
=
new
HashSet
<>();
// 如果是管理员直接返回
if
(
user
.
getIsAdmin
())
{
permissions
.
add
(
"admin"
);
return
permissions
.
stream
().
map
(
SimpleGranted
Authority:
:
new
)
return
permissions
.
stream
().
map
(
Authority
Dto
:
:
new
)
.
collect
(
Collectors
.
toList
());
}
Set
<
Role
>
roles
=
roleRepository
.
findByUserId
(
user
.
getId
());
permissions
=
roles
.
stream
().
flatMap
(
role
->
role
.
getMenus
().
stream
())
.
filter
(
menu
->
StringUtils
.
isNotBlank
(
m
enu
.
getPermission
())
)
.
map
(
Menu:
:
getPermission
).
collect
(
Collectors
.
toSet
());
return
permissions
.
stream
().
map
(
SimpleGranted
Authority:
:
new
)
.
map
(
M
enu
:
:
getPermission
)
.
filter
(
StringUtils:
:
isNotBlank
).
collect
(
Collectors
.
toSet
());
return
permissions
.
stream
().
map
(
Authority
Dto
:
:
new
)
.
collect
(
Collectors
.
toList
());
}
...
...
Write
Preview
Supports
Markdown
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