package com.vci.client.uif.actions.client;
|
|
import com.vci.client.auth2.utils.RightManagerHelper;
|
import com.vci.client.bof.ClientBusinessObject;
|
import com.vci.client.bof.ClientLinkObject;
|
import com.vci.client.common.providers.ServiceProvider;
|
import com.vci.client.uif.engine.common.GlobalContextParam;
|
import com.vci.client.uif.engine.common.IDataNode;
|
import com.vci.corba.framework.data.CheckValue;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.common.data.VCIInvocationInfo;
|
import com.vci.mw.ClientContextVariable;
|
|
/**
|
* 在DataRightUtil返回布尔类型的基础上,增加返回规则名字符串,逻辑上并无不同
|
* @author liumh
|
*/
|
|
/**
|
* 对数据权限进行校验,分为以下六种情况:
|
* 1、修改link
|
* 2、修改BO
|
* 3、修改link及BO,通过1和2的组合即可完成
|
* 4、基于BO创建link,通过判断BO作为from端对象的link(加入link名称的操作)操作权限,即通过步骤2
|
* 5、基于LO创建link,通过判断LO的TO端对象作为from端对象的link(加入link名称的操作)操作权限,即通过步骤2
|
* 6、基于参照创建对象,通过判断参照对象是否具有创建的权限即可,即通过步骤2
|
*
|
* 对于创建BO的权限通过功能模块授权进行处理,从数据层面暂不考虑
|
* @author VCI_STGK_Lincq
|
*
|
*/
|
public class DataRightReturnNameUtil {
|
|
/**
|
* 判断当前用户对链接对象是否具有操作权限
|
* @param selectedObject,选中对象
|
* @param key,操作键值
|
* @return 返回是否有权和规则名的对象数组
|
new Object[]{Boolean isHasRight,String ruleName}
|
默认是{false,""}
|
* @throws VCIError
|
*/
|
public Object[] checkLinkHasEditRight(Object selectedObject, String linkType, String key) throws VCIError {
|
Object[] hasRight = new Object[]{false,null};
|
String[] loResult = this.getLOcheckObject(selectedObject);
|
if (loResult != null && loResult.length != 0) {
|
String opname = linkType + "." + key;
|
hasRight = getCheckResult(loResult, opname);
|
}
|
return hasRight;
|
}
|
|
/**
|
* 判断当前用户对链接对象Fromd端BO对象是否具有操作权限
|
* @param selectedObject,选中对象
|
* @param key,操作键值
|
* @return 返回是否有权和规则名的对象数组
|
new Object[]{Boolean isHasRight,String ruleName}
|
默认是{false,""}
|
* @throws VCIError
|
*/
|
public Object[] checkLinkFBHasEditRight(Object selectedObject, String linkType, String key) throws VCIError {
|
Object[] hasRight = new Object[]{false,null};
|
String[] boResult = this.getTBOcheckObject(selectedObject);
|
if (boResult != null && boResult.length != 0) {
|
String opname = linkType + "." + key;
|
hasRight = getCheckResult(boResult, opname);
|
}
|
return hasRight;
|
}
|
|
/**
|
* 检查BO对当前对象是否基于修改权限
|
* 如果为link时正向得到TO端BO
|
* @param selectedObject,选中对象
|
* @param key,操作键值
|
* @return 返回是否有权和规则名的对象数组
|
new Object[]{Boolean isHasRight,String ruleName}
|
默认是{false,""}
|
* @throws VCIError
|
*/
|
public Object[] checkTBoHasEditRight(Object selectedObject, String key) throws VCIError {
|
Object[] hasRight = new Object[]{false,null};
|
String[] boResult = this.getTBOcheckObject(selectedObject);
|
if (boResult != null && boResult.length != 0) {
|
hasRight = getCheckResult(boResult, key);
|
}
|
return hasRight;
|
}
|
|
/**
|
* 检查BO对当前对象是否基于修改权限
|
* 如果为link时正向得到From端BO
|
* @param selectedObject,选中对象
|
* @param key,操作键值
|
* @return 返回是否有权和规则名的对象数组
|
new Object[]{Boolean isHasRight,String ruleName}
|
默认是{false,""}
|
* @throws VCIError
|
*/
|
public Object[] checkFBoHasEditRight(Object selectedObject, String key) throws VCIError {
|
Object[] hasRight = new Object[]{false,null};
|
String[] boResult = this.getFBOcheckObject(selectedObject);
|
if (boResult != null && boResult.length != 0) {
|
hasRight = getCheckResult(boResult, key);
|
}
|
return hasRight;
|
}
|
|
private String[] getLOcheckObject(Object selectedObject) {
|
String[] result = null;
|
if (selectedObject instanceof IDataNode){
|
IDataNode dataNode = (IDataNode) selectedObject;
|
Object masterObj = dataNode.getMaterObject();
|
if (masterObj instanceof ClientLinkObject) {
|
ClientLinkObject clo = (ClientLinkObject) masterObj;
|
result = new String[4];
|
result[0] = clo.getFromOid() + ";" + clo.getOid();
|
result[1] = clo.getFromBTMName();
|
result[2] = "";
|
result[3] = "";
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
* 得到BO对象,如果为link时正向得到To端BO,反向得到From端BO
|
* @param selectedObject
|
* @return
|
*/
|
private String[] getTBOcheckObject(Object selectedObject) {
|
String[] result = null;
|
if (selectedObject instanceof IDataNode){
|
IDataNode dataNode = (IDataNode) selectedObject;
|
Object masterObj = dataNode.getMaterObject();
|
if (masterObj instanceof ClientBusinessObject) {
|
ClientBusinessObject cbo = (ClientBusinessObject) masterObj;
|
result = new String[4];
|
result[0] = cbo.getBusinessObject().oid;
|
result[1] = cbo.getBusinessObject().btName;
|
result[2] = cbo.getBusinessObject().revisionid;
|
result[3] = cbo.getBusinessObject().nameoid;
|
} else if (masterObj instanceof ClientLinkObject) {
|
ClientLinkObject clo = (ClientLinkObject) masterObj;
|
result = new String[4];
|
if (dataNode.isForward()) {
|
result[0] = clo.getLinkObject().toOid;
|
result[1] = clo.getLinkObject().toBTName;
|
result[2] = clo.getLinkObject().toRevOid;
|
result[3] = clo.getLinkObject().toNameOid;
|
} else {
|
result[0] = clo.getLinkObject().fromOid;
|
result[1] = clo.getLinkObject().fromBTName;
|
result[2] = clo.getLinkObject().fromRevOid;
|
result[3] = clo.getLinkObject().fromNameOid;
|
}
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
* 得到BO对象,如果为link时正向得到From端BO,反向得到To端BO
|
* @param selectedObject
|
* @return
|
*/
|
private String[] getFBOcheckObject(Object selectedObject) {
|
String[] result = null;
|
if (selectedObject instanceof IDataNode){
|
IDataNode dataNode = (IDataNode) selectedObject;
|
Object masterObj = dataNode.getMaterObject();
|
if (masterObj instanceof ClientBusinessObject) {
|
ClientBusinessObject cbo = (ClientBusinessObject) masterObj;
|
result = new String[4];
|
result[0] = cbo.getBusinessObject().oid;
|
result[1] = cbo.getBusinessObject().btName;
|
result[2] = cbo.getBusinessObject().revisionid;
|
result[3] = cbo.getBusinessObject().nameoid;
|
} else if (masterObj instanceof ClientLinkObject) {
|
ClientLinkObject clo = (ClientLinkObject) masterObj;
|
result = new String[4];
|
if (dataNode.isForward()) {
|
result[0] = clo.getLinkObject().fromOid;
|
result[1] = clo.getLinkObject().fromBTName;
|
result[2] = clo.getLinkObject().fromRevOid;
|
result[3] = clo.getLinkObject().fromNameOid;
|
} else {
|
result[0] = clo.getLinkObject().toOid;
|
result[1] = clo.getLinkObject().toBTName;
|
result[2] = clo.getLinkObject().toRevOid;
|
result[3] = clo.getLinkObject().toNameOid;
|
}
|
}
|
}
|
|
return result;
|
}
|
|
/**
|
*
|
* @param result
|
* @param opname
|
* @return 返回长度是二的对象数组,第一个值是布尔类型-是否有权,第二个值是字符串类型-规则名
|
* 当有权时,即第一个值为true时,第二个值为空
|
* 当无权时,即第二个值为false时,
|
* 规则名有两种情况:
|
* 一、正常返回
|
* 二、返回null,表示没有规则名或者存储过程问题
|
* @throws VCIError
|
*/
|
public Object[] getCheckResult(String[] result, String opname) throws VCIError {
|
VCIInvocationInfo invocationInfo = ClientContextVariable.getInvocationInfo();
|
String oid = result[0];
|
String btmName = result[1];
|
String revisionOid = result[2];
|
String nameOid = result[3];
|
CheckValue params = new CheckValue();
|
params.users = invocationInfo.userName;
|
params.roles = getArrayString(invocationInfo.roleNames);
|
params.userGroups = getArrayString(invocationInfo.groupNames);
|
params.paramValues= GlobalContextParam.getInstance().getDefaultConditionString();
|
params.opname = opname;
|
params.objectmoid = nameOid;
|
params.objectroid = revisionOid;
|
params.businesstype = btmName;
|
params.objectoid = oid;
|
String where = ServiceProvider.getFrameService().checkRight(params);
|
String[] ops = where.split(":");
|
String msg = "0";
|
//TODO 需要处理 query 类型的操作,权限定义(返回数据格)不一样的问题
|
String[] op = null;
|
for (String s : ops) {
|
if (s != null && !s.equals("")) {
|
op = s.split(",");
|
msg = op[1];
|
break;
|
}
|
}
|
boolean res = ("1".equals(msg));
|
String ruleName = null;
|
if(op != null && !res && op.length == 3) {
|
if(op[2] != null && op[2].length() > 0) {
|
ruleName = op[2];
|
}
|
}
|
return new Object[]{res,ruleName};
|
}
|
|
protected String getArrayString(String[] values){
|
String res = "";
|
if (values != null) {
|
for (int i = 0; i < values.length; i++) {
|
if (i != 0) {
|
res += ",";
|
}
|
res += values[i];
|
}
|
}
|
return res;
|
}
|
|
/**
|
* @param args
|
*/
|
public static void main(String[] args) {
|
// TODO Auto-generated method stub
|
|
}
|
|
}
|