提交 5ce9d74a 编写于 作者: sq3536's avatar sq3536

更改结构

上级 b2cf0255
package cn.ibizlab.core.uaa.extensions.aspect;
import cn.ibizlab.core.uaa.domain.SysPSSystem;
import cn.ibizlab.core.uaa.domain.SysPermission;
import cn.ibizlab.core.uaa.extensions.domain.PermissionType;
import cn.ibizlab.core.uaa.service.ISysPermissionService;
import cn.ibizlab.util.annotation.DEField;
import cn.ibizlab.util.domain.EntityBase;
import cn.ibizlab.util.enums.DEFieldDefaultValueType;
import cn.ibizlab.util.enums.DEPredefinedFieldType;
import cn.ibizlab.util.errors.BadRequestAlertException;
import cn.ibizlab.util.helper.DEFieldCacheMap;
import cn.ibizlab.util.security.AuthenticationUser;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.AlternativeJdkIdGenerator;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 实体属性默认值切面,只有新建(Create)时才会填充默认值
*/
@Aspect
@Order(0)
@Component
public class SysPSSystemAspect
{
@Autowired
@Lazy
private ISysPermissionService sysPermissionService;
@After(value = "execution(* cn.ibizlab.core.uaa.service.ISysPSSystemService.create*(..))")
public void create(JoinPoint point) throws Exception {
savePermission(point);
}
@After(value = "execution(* cn.ibizlab.core.uaa.service.ISysPSSystemService.update*(..))")
public void update(JoinPoint point) throws Exception {
savePermission(point);
}
@After(value = "execution(* cn.ibizlab.core.uaa.service.ISysPSSystemService.save*(..))")
public void save(JoinPoint point) throws Exception {
savePermission(point);
}
private void savePermission(JoinPoint point)
{
Object[] args = point.getArgs();
if (args.length > 0) {
Object obj = args[0];
if (obj instanceof SysPSSystem)
syncPermission((SysPSSystem) obj);
else if (obj instanceof List)
((List<SysPSSystem>) obj).forEach(system -> syncPermission(system));
}
}
private void syncPermission(SysPSSystem system)
{
if(StringUtils.isEmpty(system.getPssystemid())||system.getSysstructure()==null)
return;
Map<String,Integer> delPermission = new HashMap<>();
sysPermissionService.list(new QueryWrapper<SysPermission>().select("sys_permissionid").eq("pssystemid",system.getPssystemid())).forEach(sysPermission -> delPermission.put(sysPermission.getPermissionid(),1));
List<SysPermission> list = system.getSysstructure().getSysPermissions(PermissionType.OPPRIV);
list.addAll(system.getSysstructure().getSysPermissions(PermissionType.APPMENU));
list.addAll(system.getSysstructure().getSysPermissions(PermissionType.UNIRES));
list.forEach(sysPermission -> delPermission.remove(sysPermission.getPermissionid()));
sysPermissionService.removeBatch(delPermission.keySet());
sysPermissionService.saveBatch(list);
}
}
package cn.ibizlab.core.uaa.extensions.domain;
import cn.ibizlab.core.uaa.domain.SysPermission;
import cn.ibizlab.core.uaa.extensions.domain.Structure.AppNode;
import cn.ibizlab.core.uaa.extensions.domain.Structure.EntityNode;
import cn.ibizlab.core.uaa.extensions.domain.Structure.FuncItem;
import cn.ibizlab.core.uaa.extensions.domain.Structure.UniResNode;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import liquibase.pro.packaged.S;
import lombok.Data;
import java.util.*;
......@@ -190,4 +192,30 @@ public class SysStructure
return itemNode;
}
public List<SysPermission> getSysPermissions(PermissionType type)
{
List<SysPermission> list = new ArrayList<>();
PermissionNode root = getPermissionTree(type);
loopPermissionNode(list,root);
return list;
}
private void loopPermissionNode(List<SysPermission> list,PermissionNode root)
{
if(root.getChildren()!=null){
root.getChildren().forEach(node->{
if(node.getType()!=null){
SysPermission sysPermission = new SysPermission();
sysPermission.setPermissionid(node.getId());
sysPermission.setPermissionname(node.getFullName());
sysPermission.setPssystemid(node.getSystemid());
sysPermission.setPermissiontype(node.getType().toString());
list.add(sysPermission);
}
loopPermissionNode(list,node);
});
}
}
}
......@@ -6,13 +6,18 @@ import cn.ibizlab.core.uaa.domain.SysRolePermission;
import cn.ibizlab.core.uaa.extensions.domain.PermissionNode;
import cn.ibizlab.core.uaa.extensions.domain.PermissionType;
import cn.ibizlab.core.uaa.filter.SysPSSystemSearchContext;
import cn.ibizlab.core.uaa.filter.SysRolePermissionSearchContext;
import cn.ibizlab.core.uaa.service.ISysPSSystemService;
import cn.ibizlab.core.uaa.service.ISysRolePermissionService;
import cn.ibizlab.core.uaa.service.ISysUserRoleService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.domain.Page;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
......@@ -23,11 +28,17 @@ import java.util.*;
public class UAACoreService {
@Autowired
@Lazy
private ISysPSSystemService sysPSSystemService;
@Autowired
@Lazy
private ISysRolePermissionService rolePermissionService;
@Autowired
@Lazy
private ISysUserRoleService userRoleService;
public Map<String,List<PermissionNode>> getPermissionTree()
{
List<PermissionNode> apps = new ArrayList<>();
......@@ -58,4 +69,23 @@ public class UAACoreService {
return rolePermissions;
}
public Collection<GrantedAuthority> getAuthoritiesByUserId(String userId)
{
Set<GrantedAuthority> authorities = new LinkedHashSet<>();
Set<String> roleIds = new HashSet<>();
userRoleService.selectByUserid(userId).forEach(sysUserRole -> roleIds.add(sysUserRole.getRoleid()));
roleIds.forEach(roleid->authorities.add(new SimpleGrantedAuthority("ROLE_"+roleid)));
SysRolePermissionSearchContext context = new SysRolePermissionSearchContext();
context.getSelectCond().in("sys_roleid",roleIds).eq("permissionenable",1).orderByAsc("permissiontype","sys_permissionid");
context.setSize(Integer.MAX_VALUE);
rolePermissionService.searchDefault(context).forEach(sysRolePermission -> {
if(PermissionType.OPPRIV.toString().equals(sysRolePermission.getPermissiontype()))
authorities.add(new SimpleGrantedAuthority(sysRolePermission.getPermissionid()));
else
authorities.add(new SimpleGrantedAuthority(sysRolePermission.getPermissiontype()+"_"+sysRolePermission.getPermissionid()));
});
return authorities;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册