package com.vci.client.uif.actions.client; import java.util.HashMap; import java.util.Map; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientLinkObject; import com.vci.client.common.providers.ServiceProvider; import com.vci.client.uif.actions.client.BusinessOperationAction.ValueType; import com.vci.client.uif.engine.client.IDataModel; 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.InvocationUtility; /** * 对数据权限进行校验,分为以下六种情况: * 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 DataRightUtil { private Map buttonParams = new HashMap(); private IDataModel dataModel = null; public DataRightUtil(Map map){ buttonParams = map; } public Map getButtonParams(){ return this.buttonParams; } public IDataModel getDataModel(){ return this.dataModel; } /** * 判断当前用户对链接对象是否具有操作权限 * @param selectedObject,选中对象 * @param key,操作键值 * @return * @throws VCIError */ public boolean checkLinkHasEditRight(Object selectedObject, String linkType, String key) throws VCIError { boolean hasRight = false; 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 * @throws VCIError */ public boolean checkLinkFBHasEditRight(Object selectedObject, String linkType, String key) throws VCIError { boolean hasRight = false; 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 * @throws VCIError */ public boolean checkTBoHasEditRight(Object selectedObject, String key) throws VCIError { boolean hasRight = false; 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 * @throws VCIError */ public boolean checkFBoHasEditRight(Object selectedObject, String key) throws VCIError { boolean hasRight = false; 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; } private boolean getCheckResult(String[] result, String opname) throws VCIError { VCIInvocationInfo invocationInfo = InvocationUtility.getInvocation(); 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); StringBuffer sb = new StringBuffer(); String[] extAttrs = invocationInfo.extAttribs; for(int i = 0; i < extAttrs.length; i++){ sb.append(extAttrs[i]); if(i != extAttrs.length - 1){ sb.append(","); } } params.paramValues = sb.toString(); params.opname = opname; params.objectmoid = nameOid; params.objectroid = revisionOid; params.businesstype = btmName; params.objectoid = oid; //System.out.println("=========================================="); //System.out.println("DataRightUtil.getCheckResult()"); //System.out.println("user:" + params.users); //System.out.println("userGroups:" + params.userGroups); //System.out.println("roles:" + params.roles); //System.out.println("paramValues:" + params.paramValues); //System.out.println("opname:" + params.opname); //System.out.println("objectmoid:" + params.objectmoid); //System.out.println("objectroid:" + params.objectroid); //System.out.println("businesstype:" + params.businesstype); //System.out.println("objectoid:" + params.objectoid); String where = ServiceProvider.getFrameService().checkRight(params); //System.out.println("checkResult where :" + where); //System.out.println("=========================================="); String[] ops = where.split(":"); String msg = "0"; //TODO 需要处理 query 类型的操作,权限定义(返回数据格)不一样的问题 for (String s : ops) { if (s != null && !s.equals("")) { String[] op = s.split(","); msg = op[1]; break; } } if(msg.length()>1){ msg=msg.substring(0, 1); } boolean res = ("1".equals(msg)); return res; } 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 } /** * 验证数据是否有操作权限 * @param rightCheckTypeParam * @param selectedObject * @param key * @return * @throws VCIError */ public boolean getCheckRes(String rightCheckTypeParam,Object selectedObject,String key) throws VCIError{ //DataRightUtil dru = new DataRightUtil(); boolean checkRes = false; if(rightCheckTypeParam.equals(RightCheckConstants.RIGHT_CHECK_TYPE_NONE)){ checkRes = true; } else if(rightCheckTypeParam.equals(RightCheckConstants.RIGHT_CHECK_TYPE_B)){ checkRes = checkTBoHasEditRight(selectedObject, key); } else if(rightCheckTypeParam.equals(RightCheckConstants.RIGHT_CHECK_TYPE_L)){ String linkType = getButtonParamLinkType(); checkRes = checkLinkHasEditRight(selectedObject, linkType, key); //校验From端权限 if(checkRes) { //校验Form端对象的权限 String fmapping = getParameterValue(ValueType.ButtonConfig, "fmapping", -1); if(fmapping != null && !fmapping.trim().equals("")) { checkRes = checkFBoHasEditRight(selectedObject, fmapping); } if(checkRes) { //校验To端权限 String tmapping = getParameterValue(ValueType.ButtonConfig, "tmapping", -1); if(tmapping != null && !tmapping.trim().equals("")) { checkRes = checkTBoHasEditRight(selectedObject, tmapping); } } } } else if(rightCheckTypeParam.equals(RightCheckConstants.RIGHT_CHECK_LOGICAL_B)){ // boolean b = dru.checkBoHasEditRight(selectedObject, key); // String linkType = getButtonParamLinkType(); // boolean l = dru.checkLinkHasEditRight(selectedObject, linkType, key); // checkRes = b && l; checkRes = false; } else if(rightCheckTypeParam.equals(RightCheckConstants.RIGHT_CHECK_TYPE_FB)) { String linkType = getButtonParamLinkType(); checkRes = checkLinkFBHasEditRight(selectedObject, linkType, key); } else if(rightCheckTypeParam.equals(RightCheckConstants.RIGHT_CHECK_TYPE_TB)) { } return checkRes; } private String getButtonParamLinkType(){ String res = ""; res = getParameterValue(ValueType.ButtonConfig, "linktype", -1); if(res == null){ res = getParameterValue(ValueType.ButtonConfig, "linkType", -1); if(res == null){ res = getParameterValue(ValueType.ButtonConfig, "LinkType", -1); if(res == null){ res = ""; } } } return res; } /** * 获取参数 * @param valueType 参数值的来源 * @param key 参数的 key * @param dataIndex 参数数据索引(第xx条数据的 x) * @return */ public String getParameterValue(ValueType valueType, String key, int dataIndex){ String res = null; Map map = null; if(valueType == ValueType.ButtonConfig){ map = getButtonParams(); } else if(valueType == ValueType.RuntimeData){ IDataModel dataModel = getDataModel(); Object rowData = dataModel.getSelectObjects()[dataIndex]; if(rowData instanceof IDataNode){ IDataNode dataNode = (IDataNode)rowData; map = dataNode.getValueMap(); } } res = map.get(key); return res; } }