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

uaa app 适配,rsa准备

上级 067c91d8
......@@ -8,7 +8,9 @@ import java.math.BigInteger;
import java.util.HashMap;
import java.math.BigDecimal;
import cn.ibizlab.core.uaa.extensions.domain.SysApp;
import cn.ibizlab.core.uaa.extensions.domain.SysStructure;
import cn.ibizlab.core.uaa.extensions.domain.handlers.SysAppsTypeHandler;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import com.fasterxml.jackson.annotation.JsonIgnore;
......@@ -62,6 +64,32 @@ public class SysPSSystem extends EntityMP implements Serializable {
private SysStructure sysstructure;
/**
* 结构
*/
@TableField(value = "apps",typeHandler = SysAppsTypeHandler.class)
@JSONField(name = "apps")
@JsonProperty("apps")
private List<SysApp> apps;
/**
* 属性 [MD5CHECK]
*
*/
@TableField(value = "md5check")
@JSONField(name = "md5check")
@JsonProperty("md5check")
private String md5check;
/**
* 属性 [SHOWORDER]
*
*/
@TableField(value = "showorder")
@JSONField(name = "showorder")
@JsonProperty("showorder")
private Integer showorder;
/**
* 设置 [系统名称]
......@@ -78,6 +106,31 @@ public class SysPSSystem extends EntityMP implements Serializable {
this.modify("sysstructure",sysstructure);
}
/**
* 设置 [APPS]
*/
public void setApps(List<SysApp> apps){
this.apps = apps ;
this.modify("apps",apps);
}
/**
* 设置 [MD5CHECK]
*/
public void setMd5check(String md5check){
this.md5check = md5check ;
this.modify("md5check",md5check);
}
/**
* 设置 [SHOWORDER]
*/
public void setShoworder(Integer showorder){
this.showorder = showorder ;
this.modify("showorder",showorder);
}
public SysStructure getSysstructure()
{
if (this.sysstructure!=null )
......
......@@ -3,6 +3,10 @@ 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.extensions.domain.SysApp;
import cn.ibizlab.core.uaa.extensions.service.SysAppService;
import cn.ibizlab.core.uaa.extensions.service.UAACoreService;
import cn.ibizlab.core.uaa.service.ISysPSSystemService;
import cn.ibizlab.core.uaa.service.ISysPermissionService;
import cn.ibizlab.util.annotation.DEField;
import cn.ibizlab.util.domain.EntityBase;
......@@ -40,6 +44,64 @@ public class SysPSSystemAspect
@Lazy
private ISysPermissionService sysPermissionService;
@Autowired
@Lazy
private ISysPSSystemService sysPSSystemService;
@Autowired
@Lazy
private UAACoreService uaaCoreService;
@Autowired
@Lazy
private SysAppService sysAppService;
@Before(value = "execution(* cn.ibizlab.core.uaa.service.ISysPSSystemService.create*(..))")
public void beforecreate(JoinPoint point) throws Exception {
saveApps(point);
}
@Before(value = "execution(* cn.ibizlab.core.uaa.service.ISysPSSystemService.update*(..))")
public void beforeupdate(JoinPoint point) throws Exception {
saveApps(point);
}
@Before(value = "execution(* cn.ibizlab.core.uaa.service.ISysPSSystemService.save*(..))")
public void beforesave(JoinPoint point) throws Exception {
saveApps(point);
}
private void saveApps(JoinPoint point)
{
uaaCoreService.resetApps();
sysAppService.resetAppNavigationBars();
Object[] args = point.getArgs();
if (args.length > 0) {
Object obj = args[0];
if (obj instanceof SysPSSystem)
prepairApps((SysPSSystem) obj);
else if (obj instanceof List)
((List<SysPSSystem>) obj).forEach(system -> prepairApps(system));
}
}
private void prepairApps(SysPSSystem system) {
if (StringUtils.isEmpty(system.getPssystemid()) || system.getSysstructure() == null)
return;
Map<String,SysApp> oldApps = new HashMap<>();
SysPSSystem old = sysPSSystemService.getById(system.getPssystemid());
if(old!=null&&old.getApps()!=null)
old.getApps().forEach(app->oldApps.put(app.getId(),app));
List<SysApp> newList=new ArrayList<>();
system.getSysstructure().getSysApps(true).forEach(appNode -> {
if(oldApps.containsKey(appNode.getId()))
newList.add(oldApps.get(appNode.getId()));
else
newList.add(appNode);
});
system.setApps(newList);
}
@After(value = "execution(* cn.ibizlab.core.uaa.service.ISysPSSystemService.create*(..))")
public void create(JoinPoint point) throws Exception {
savePermission(point);
......
package cn.ibizlab.core.uaa.extensions.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SysApp {
private String id;
private String label;
private String systemid;
private String fullName;
private String type;
private String addr;
}
package cn.ibizlab.core.uaa.extensions.domain;
import cn.ibizlab.core.uaa.domain.SysPSSystem;
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 cn.ibizlab.core.uaa.filter.SysPSSystemSearchContext;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.springframework.data.domain.Page;
import java.sql.Timestamp;
import java.util.*;
......@@ -217,4 +220,18 @@ public class SysStructure
}
}
public List<SysApp> getSysApps(boolean web) {
List<SysApp> apps=new ArrayList<>();
if (this.getApps() == null)
return apps;
this.getApps().forEach(app-> {
SysApp sysApp = SysApp.builder()
.label(app.getAppname()).systemid(systemid).id(systemid.toLowerCase()+"-app-"+app.getAppid().toLowerCase()).build();
apps.add(sysApp);
});
return apps;
}
}
package cn.ibizlab.core.uaa.extensions.domain.handlers;
import cn.ibizlab.core.uaa.extensions.domain.SysApp;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@MappedTypes({List.class})
@MappedJdbcTypes(JdbcType.VARCHAR)
public class SysAppsTypeHandler extends AbstractJsonTypeHandler<List>
{
private static ObjectMapper objectMapper = new ObjectMapper();
private JavaType type;
public SysAppsTypeHandler(Class<List> type) {
this.type = objectMapper.getTypeFactory().constructParametricType(ArrayList.class, SysApp.class);
}
@Override
protected List parse(String json) {
try {
return objectMapper.readValue(json, type);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
protected String toJson(List obj) {
try {
return objectMapper.writeValueAsString(obj);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
public static void setObjectMapper(ObjectMapper objectMapper) {
SysAppsTypeHandler.objectMapper = objectMapper;
}
}
\ No newline at end of file
package cn.ibizlab.core.uaa.extensions.service;
import cn.ibizlab.core.uaa.domain.SysPSSystem;
import cn.ibizlab.core.uaa.extensions.domain.SysApp;
import cn.ibizlab.core.uaa.filter.SysPSSystemSearchContext;
import cn.ibizlab.core.uaa.service.ISysPSSystemService;
import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.service.IBZConfigService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@Service
public class SysAppService {
@Autowired
private ISysPSSystemService sysPSSystemService;
@Autowired
private IBZConfigService ibzConfigService;
@Autowired
private UAACoreService uaaCoreService;
@Cacheable( value="ibzuaa_appnavbar",key = "'id:'+#p0+'||'+#p1")
public JSONObject getAppNavigationBar(String navId,String userId)
{
JSONObject jo=ibzConfigService.getConfig("AppNavigationBar",navId, userId);
if(!jo.containsKey("model"))
jo.put("model",new JSONArray());
LinkedHashMap<String,SysApp> defApps=uaaCoreService.getApps();
List<SysApp> list=new ArrayList<>();
JSONArray.parseArray(jo.get("model").toString(),SysApp.class).forEach(sysApp -> {
SysApp def=defApps.get(sysApp.getId());
if(def==null)return;
sysApp.setAddr(def.getAddr());
list.add(sysApp);
});
jo.remove("model");
jo.put("model",JSONArray.toJSON(list));
return jo;
}
@CacheEvict( value="ibzuaa_appnavbar",allEntries=true)
public void resetAppNavigationBars()
{
}
}
......@@ -7,24 +7,34 @@ import cn.ibizlab.core.uaa.domain.SysRole;
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.extensions.domain.SysApp;
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.ISysRoleService;
import cn.ibizlab.core.uaa.service.ISysUserRoleService;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
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.Base64Utils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.*;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.*;
@Service
......@@ -94,7 +104,19 @@ public class UAACoreService {
SysRolePermissionSearchContext context = new SysRolePermissionSearchContext();
context.getSelectCond().in("sys_roleid",roleIds).eq("permissionenable",1).orderByAsc("permissiontype","sys_permissionid");
context.setSize(Integer.MAX_VALUE);
Set<String> apps=new HashSet<>();
rolePermissionService.searchDefault(context).forEach(sysRolePermission -> {
if(PermissionType.APPMENU.toString().equals(sysRolePermission.getPermissiontype()))
{
//补充应用访问权
String appid = sysRolePermission.getPermissionid().split("-")[0].toLowerCase()+"-app-"+sysRolePermission.getPermissionid().split("-")[1].toLowerCase();
if(!apps.contains(appid)){
apps.add(appid);
authorities.add(new SimpleGrantedAuthority(sysRolePermission.getPermissiontype()+"_"+appid));
}
}
if(PermissionType.OPPRIV.toString().equals(sysRolePermission.getPermissiontype()))
authorities.add(new SimpleGrantedAuthority(sysRolePermission.getPermissionid()));
else
......@@ -143,4 +165,92 @@ public class UAACoreService {
rolePermissionService.removeBatch(delIds);
}
@Cacheable( value="syspssystem",key = "'row:all-apps'")
public LinkedHashMap<String,SysApp> getApps() {
LinkedHashMap<String,SysApp> appNode=new LinkedHashMap<>();
Page<SysPSSystem> page = sysPSSystemService.searchDefault(new SysPSSystemSearchContext());
page.getContent().forEach(system -> {
if (system.getSysstructure() == null)
{
return;
}
if (system.getApps() == null)
{
system.setApps(system.getSysstructure().getSysApps(true));
sysPSSystemService.update(system);
}
system.getApps().forEach(app-> {
appNode.put(app.getId(),app);
});
});
return appNode;
}
@CacheEvict( value="syspssystem",key = "'row:all-apps'")
public void resetApps()
{
}
@SneakyThrows
public boolean genKeyPair()
{
KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
gen.initialize(1024);
// 随机生成一对密钥(包含公钥和私钥)
KeyPair keyPair = gen.generateKeyPair();
// 获取 公钥 和 私钥
PublicKey pubKey = keyPair.getPublic();
PrivateKey priKey = keyPair.getPrivate();
String usrHome = System.getProperty("user.home")+"/.ibzrt";
File dir=new File(usrHome);
if(!dir.exists())
dir.mkdirs();
byte[] pubEncBytes = pubKey.getEncoded();
byte[] priEncBytes = priKey.getEncoded();
String pubEncBase64 = Base64Utils.encodeToString(pubEncBytes);
String priEncBase64 = Base64Utils.encodeToString(priEncBytes);
OutputStream out = null;
try {
out = new FileOutputStream(new File(dir,"ibzrt_rsa.pub"));
IOUtils.write(pubEncBase64,out);
} finally {
IOUtils.closeQuietly(out);
}
try {
out = new FileOutputStream(new File(dir,"ibzrt_rsa"));
IOUtils.write(priEncBase64,out);
} finally {
IOUtils.closeQuietly(out);
}
return true;
}
@SneakyThrows
public String getPublicKey()
{
String key="";
String usrHome = System.getProperty("user.home")+"/.ibzrt";
File pubKeyFile=new File(usrHome,"ibzrt_rsa.pub");
if(!pubKeyFile.exists())
{
key = IOUtils.toString(this.getClass().getResourceAsStream("/keypair/ibzrt_rsa.pub"));
}
else{
key = IOUtils.toString(new FileInputStream(pubKeyFile));
}
return key;
}
}
MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAKaTz4pgOR/p0RjlczM0dErf4ZUNziE/HJcfKDLPu77Gs2EJdDK0uGfPI3GX/eRwX9L9bTZJtz9sX2fkRqRt3gWnsMypT2P/cO/2GgtRCPHRFD7BI+Df32isEJZ6M4kD9tyKLw8Y9KuP0C20ZMMDeCrrbjMagMMrwTOM4/4eFjzVAgMBAAECgYEAnH3mj2hgolOmhg4hkOxpiGIV6lMi4OcKtAqoWDwCdHL12GbqTCytxZC7Cp+w/Wh5DZ3aeRL93c6xPsgdeaJh3kYa4ooo6b5tFHPU63VU5MBgwGzi26/6GB4GCXxGMB+SxmdigDmmPIYbXD+jO2oj1s8hj+DOE4U2fIjeZ//DumECQQDlA74KHNZlKxoWl0FoHCgcIHFBZcQWKO3puhrH7VsRYI7CVVguE57NBT6QvAmU9r32PDt64tS0Qd1sCrk4uEqtAkEAujSj/cwF4ctQZCbUoMMzK/mw8ZxW3M6VK3urbq8fyFJ2iT2aLV3jE3+tnDdpezcfnbs/9SVXeFmJpdg/L7hnyQJAQyxo1qCExmHxIgU1uyrfHPjrH2qRLIrO1gqvhkr5tkwjM59C4SkCIFLUejGdgeMp7wrVy4KzLzhOkT1H/PoZdQJAEbKxJ409veFKKcq7CPCkq3hXBg/a/a+w4+okOCfy+GJGG/M79TXoQFExWhi2MNzjZ2WFxbIf5zNzbszn7Iw1aQJBAIXpKrQ0sLxr0rFzsoHBrobPcnQeutzypQNTPkoItILVP9pWz+aUfIKnOHEC5GAdD2LPZZ/pF7ixdRd9nBab+pk=
\ No newline at end of file
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmk8+KYDkf6dEY5XMzNHRK3+GVDc4hPxyXHygyz7u+xrNhCXQytLhnzyNxl/3kcF/S/W02Sbc/bF9n5Eakbd4Fp7DMqU9j/3Dv9hoLUQjx0RQ+wSPg399orBCWejOJA/bcii8PGPSrj9AttGTDA3gq624zGoDDK8EzjOP+HhY81QIDAQAB
\ No newline at end of file
......@@ -8,6 +8,9 @@ import java.util.Map;
import java.util.HashMap;
import java.io.Serializable;
import java.math.BigDecimal;
import cn.ibizlab.core.uaa.extensions.domain.SysApp;
import cn.ibizlab.core.uaa.extensions.domain.SysStructure;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
......@@ -45,7 +48,7 @@ public class SysPSSystemDTO extends DTOBase implements Serializable {
*/
@JSONField(name = "sysstructure")
@JsonProperty("sysstructure")
private String sysstructure;
private SysStructure sysstructure;
/**
* 属性 [APPS]
......@@ -53,7 +56,7 @@ public class SysPSSystemDTO extends DTOBase implements Serializable {
*/
@JSONField(name = "apps")
@JsonProperty("apps")
private String apps;
private List<SysApp> apps;
/**
* 属性 [MD5CHECK]
......@@ -83,7 +86,7 @@ public class SysPSSystemDTO extends DTOBase implements Serializable {
/**
* 设置 [SYSSTRUCTURE]
*/
public void setSysstructure(String sysstructure){
public void setSysstructure(SysStructure sysstructure){
this.sysstructure = sysstructure ;
this.modify("sysstructure",sysstructure);
}
......@@ -91,7 +94,7 @@ public class SysPSSystemDTO extends DTOBase implements Serializable {
/**
* 设置 [APPS]
*/
public void setApps(String apps){
public void setApps(List<SysApp> apps){
this.apps = apps ;
this.modify("apps",apps);
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册