田源
2025-01-09 8a166a60cfd1a2e593ffa103d10c0dc224fc8628
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
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
 
    }
 
}