mirror of https://github.com/elunez/eladmin
修复用户多角色时登录失败的bug
parent
99041161d7
commit
5f43a5dabc
|
@ -21,7 +21,7 @@ import org.springframework.stereotype.Component;
|
||||||
@Component
|
@Component
|
||||||
@Aspect
|
@Aspect
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DataScopeAspect {
|
public class LogAspect {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private LogService logService;
|
private LogService logService;
|
|
@ -35,7 +35,7 @@ public class ConfigurerAdapter implements WebMvcConfigurer {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 可解决Long 类型在 前端精度丢失的问题, 如不想全局 直接添加注解 @JsonSerialize(using= ToStringSerializer.class) 到相应的字段上
|
// 可解决Long 类型在 前端精度丢失的问题, 如不想全局 直接添加注解 @JsonSerialize(using= ToStringSerializer.class) 到相应的字段
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
// public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
package me.zhengjie.modules.security.service;
|
package me.zhengjie.modules.security.service;
|
||||||
|
|
||||||
import me.zhengjie.modules.system.domain.Permission;
|
|
||||||
import me.zhengjie.modules.system.domain.Role;
|
import me.zhengjie.modules.system.domain.Role;
|
||||||
import me.zhengjie.modules.system.domain.User;
|
import me.zhengjie.modules.system.domain.User;
|
||||||
import me.zhengjie.modules.system.repository.PermissionRepository;
|
|
||||||
import me.zhengjie.modules.system.repository.RoleRepository;
|
import me.zhengjie.modules.system.repository.RoleRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.cache.annotation.CacheConfig;
|
import org.springframework.cache.annotation.CacheConfig;
|
||||||
|
@ -12,7 +10,6 @@ import org.springframework.security.core.GrantedAuthority;
|
||||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -23,9 +20,6 @@ public class JwtPermissionService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private RoleRepository roleRepository;
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private PermissionRepository permissionRepository;
|
|
||||||
|
|
||||||
@Cacheable(key = "'loadPermissionByUser:' + #p0.username")
|
@Cacheable(key = "'loadPermissionByUser:' + #p0.username")
|
||||||
public Collection<GrantedAuthority> mapToGrantedAuthorities(User user) {
|
public Collection<GrantedAuthority> mapToGrantedAuthorities(User user) {
|
||||||
|
|
||||||
|
@ -33,11 +27,7 @@ public class JwtPermissionService {
|
||||||
|
|
||||||
Set<Role> roles = roleRepository.findByUsers_Id(user.getId());
|
Set<Role> roles = roleRepository.findByUsers_Id(user.getId());
|
||||||
|
|
||||||
Set<Permission> permissions = new HashSet<>();
|
return roles.stream().flatMap(role -> role.getPermissions().stream())
|
||||||
|
|
||||||
permissions.addAll(permissionRepository.findByRoles(roles));
|
|
||||||
|
|
||||||
return permissions.stream()
|
|
||||||
.map(permission -> new SimpleGrantedAuthority(permission.getName()))
|
.map(permission -> new SimpleGrantedAuthority(permission.getName()))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,4 @@ public interface PermissionRepository extends JpaRepository<Permission, Long>, J
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<Permission> findByPid(long pid);
|
List<Permission> findByPid(long pid);
|
||||||
|
|
||||||
Set<Permission> findByRoles(Set<Role> roles);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue