1
|
/**
|
2
|
* '$RCSfile$'
|
3
|
* Copyright: 2004 Regents of the University of California and the
|
4
|
* National Center for Ecological Analysis and Synthesis
|
5
|
* Purpose: To test the Access Controls in metacat by JUnit
|
6
|
*
|
7
|
* '$Author: daigle $'
|
8
|
* '$Date: 2009-08-14 14:26:08 -0700 (Fri, 14 Aug 2009) $'
|
9
|
* '$Revision: 5027 $'
|
10
|
*
|
11
|
* This program is free software; you can redistribute it and/or modify
|
12
|
* it under the terms of the GNU General Public License as published by
|
13
|
* the Free Software Foundation; either version 2 of the License, or
|
14
|
* (at your option) any later version.
|
15
|
*
|
16
|
* This program is distributed in the hope that it will be useful,
|
17
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19
|
* GNU General Public License for more details.
|
20
|
*
|
21
|
* You should have received a copy of the GNU General Public License
|
22
|
* along with this program; if not, write to the Free Software
|
23
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
24
|
*/
|
25
|
|
26
|
package edu.ucsb.nceas.metacattest;
|
27
|
|
28
|
import java.io.IOException;
|
29
|
import java.io.StringReader;
|
30
|
import java.util.Vector;
|
31
|
|
32
|
import junit.framework.Test;
|
33
|
import junit.framework.TestSuite;
|
34
|
|
35
|
import edu.ucsb.nceas.MCTestCase;
|
36
|
import edu.ucsb.nceas.metacat.DocInfoHandler;
|
37
|
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException;
|
38
|
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface;
|
39
|
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList;
|
40
|
import edu.ucsb.nceas.metacat.accesscontrol.XMLAccessDAO;
|
41
|
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
|
42
|
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
|
43
|
import edu.ucsb.nceas.metacat.client.MetacatException;
|
44
|
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
|
45
|
import edu.ucsb.nceas.metacat.properties.PropertyService;
|
46
|
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
|
47
|
|
48
|
import org.xml.sax.ContentHandler;
|
49
|
import org.xml.sax.ErrorHandler;
|
50
|
import org.xml.sax.InputSource;
|
51
|
import org.xml.sax.SAXException;
|
52
|
import org.xml.sax.XMLReader;
|
53
|
import org.xml.sax.helpers.XMLReaderFactory;
|
54
|
|
55
|
/**
|
56
|
* A JUnit test for testing Access Control API in Metacat. Note that this is different
|
57
|
* than the Access Control test. That test is more concerned with making sure different
|
58
|
* combinations of access rules act appropriately. This test is more concerned with the
|
59
|
* funtioning of the API itself.
|
60
|
*/
|
61
|
public class AccessAPITest extends MCTestCase {
|
62
|
|
63
|
/**
|
64
|
* Constructor to build the test
|
65
|
*
|
66
|
* @param name
|
67
|
* the name of the test method
|
68
|
*/
|
69
|
public AccessAPITest(String name) {
|
70
|
super(name);
|
71
|
}
|
72
|
|
73
|
/**
|
74
|
* Establish a testing framework by initializing appropriate objects
|
75
|
*/
|
76
|
public void setUp() throws Exception {
|
77
|
metacatConnectionNeeded = true;
|
78
|
super.setUp();
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* Release any objects after tests are complete
|
83
|
*/
|
84
|
public void tearDown() {
|
85
|
}
|
86
|
|
87
|
/**
|
88
|
* Create a suite of tests to be run together
|
89
|
*/
|
90
|
public static Test suite() {
|
91
|
TestSuite suite = new TestSuite();
|
92
|
suite.addTest(new AccessAPITest("initialize"));
|
93
|
// Test basic functions
|
94
|
suite.addTest(new AccessAPITest("testSetSingleAccess"));
|
95
|
suite.addTest(new AccessAPITest("testSetBlockAccess"));
|
96
|
|
97
|
return suite;
|
98
|
}
|
99
|
|
100
|
/**
|
101
|
* Run an initial test that always passes to check that the test harness is
|
102
|
* working.
|
103
|
*/
|
104
|
public void initialize() {
|
105
|
assertTrue(1 == 1);
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
* Test adding access records for single principals.
|
110
|
*/
|
111
|
public void testSetSingleAccess() {
|
112
|
String principal = null;
|
113
|
Vector<XMLAccessDAO> accessDAOList = null;
|
114
|
Vector<XMLAccessDAO> realAccessDAOList = null;
|
115
|
XMLAccessDAO accessDAO = null;
|
116
|
String accessXML = null;
|
117
|
|
118
|
try {
|
119
|
debug("AccessAPITest.testSetSingleAccess Running");
|
120
|
|
121
|
m.login(username, password);
|
122
|
|
123
|
// insert a document for us to test with
|
124
|
String docId = generateDocumentId() + ".1";
|
125
|
String testDoc = getTestDocFromFile(testdatadir + "accessBlockTestFile1.xml");
|
126
|
// debug("test doc: " + testDoc);
|
127
|
insertDocumentId(docId, testDoc, SUCCESS, false);
|
128
|
|
129
|
// test inserting a single access record with allowFirst permission order and allow read
|
130
|
// access. We expect this to succeed.
|
131
|
debug("AccessAPITest.testSetSingleAccess - Test 1, add user allowFirst allow read access");
|
132
|
principal = "uid=test30,o=NCEAS,dc=ecoinformatics,dc=org";
|
133
|
setSingleAccess(docId, principal,
|
134
|
Integer.toString(AccessControlInterface.READ),
|
135
|
AccessControlInterface.ALLOW,
|
136
|
AccessControlInterface.ALLOWFIRST,
|
137
|
true);
|
138
|
accessDAOList = new Vector<XMLAccessDAO>();
|
139
|
accessDAO = new XMLAccessDAO();
|
140
|
accessDAO.setDocId(docId);
|
141
|
accessDAO.setPrincipalName(principal);
|
142
|
accessDAO.setPermission(new Long(AccessControlInterface.READ));
|
143
|
accessDAO.setPermType(AccessControlInterface.ALLOW);
|
144
|
accessDAO.setPermOrder(AccessControlInterface.ALLOWFIRST);
|
145
|
accessDAOList.add(accessDAO);
|
146
|
|
147
|
// get the access control for this doc id from metacat and make sure this
|
148
|
// access record is in that list.
|
149
|
accessXML = m.getAccessControl(docId);
|
150
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
151
|
compareAccessDAOs(realAccessDAOList, accessDAOList, false);
|
152
|
|
153
|
// test inserting a single access record with denyFirst permission order and allow read
|
154
|
// access. We expect this to fail since a single doc cannot have multiple permission orders.
|
155
|
debug("AccessAPITest.testSetSingleAccess - Test 2, add user denyFirst allow read/write access");
|
156
|
principal = "uid=test31,o=NCEAS,dc=ecoinformatics,dc=org";
|
157
|
setSingleAccess(docId, principal,
|
158
|
Integer.toString(AccessControlInterface.READ | AccessControlInterface.WRITE),
|
159
|
AccessControlInterface.ALLOW,
|
160
|
AccessControlInterface.DENYFIRST,
|
161
|
false);
|
162
|
|
163
|
|
164
|
} catch (AccessControlException ace) {
|
165
|
fail("AccessAPITest.testSetSingleAccess - Access Control error: " + ace.getMessage());
|
166
|
} catch (IOException ioe) {
|
167
|
fail("AccessAPITest.testSetSingleAccess - I/O error: " + ioe.getMessage());
|
168
|
} catch (MetacatAuthException mae) {
|
169
|
fail("AccessAPITest.testSetSingleAccess - Metacat authentication error: " + mae.getMessage());
|
170
|
} catch (MetacatException me) {
|
171
|
fail("AccessAPITest.testSetSingleAccess - Metacat error: " + me.getMessage());
|
172
|
} catch (InsufficientKarmaException ike) {
|
173
|
fail("AccessAPITest.testSetSingleAccess - Insufficient karma error: " + ike.getMessage());
|
174
|
} catch (MetacatInaccessibleException mie) {
|
175
|
fail("AccessAPITest.testSetSingleAccess - Metacat Inaccessible Error: " + mie.getMessage());
|
176
|
}
|
177
|
}
|
178
|
|
179
|
/**
|
180
|
* Test setting a block of access for a document. Each call should replace the access for that
|
181
|
* document.
|
182
|
*/
|
183
|
public void testSetBlockAccess() {
|
184
|
String accessBlockXML = null;
|
185
|
String accessXML = null;
|
186
|
Vector<XMLAccessDAO> realAccessDAOList = null;
|
187
|
Vector<XMLAccessDAO> accessBlockDAOList = null;
|
188
|
|
189
|
try {
|
190
|
debug("AccessAPITest.testSetBlockAccess - Running");
|
191
|
|
192
|
// log in
|
193
|
m.login(username, password);
|
194
|
|
195
|
// insert a document for us to test with
|
196
|
String docId = generateDocumentId() + ".1";
|
197
|
String testDoc = getTestDocFromFile(testdatadir + "accessBlockTestFile1.xml");
|
198
|
// debug("test doc: " + testDoc);
|
199
|
insertDocumentId(docId, testDoc, SUCCESS, false);
|
200
|
|
201
|
// replace access for doc using the access section in accessBlock1.xml,
|
202
|
// then test that the access was updated and that is the only access
|
203
|
// for the doc
|
204
|
debug("AccessAPITest.testSetBlockAccess - Test 1 using accessBlock1.xml");
|
205
|
accessBlockXML = getTestDocFromFile(testdatadir + "accessBlock1.xml");
|
206
|
setBlockAccess(docId, accessBlockXML, true);
|
207
|
accessXML = m.getAccessControl(docId);
|
208
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
209
|
accessBlockDAOList = getAccessDAOList(docId, accessBlockXML);
|
210
|
debugAccessDAOList(accessBlockDAOList);
|
211
|
compareAccessDAOs(realAccessDAOList, accessBlockDAOList, true);
|
212
|
|
213
|
// replace access for doc using the access section in accessBlock2.xml,
|
214
|
// then test that the access was updated and that is the only access
|
215
|
// for the doc
|
216
|
debug("AccessAPITest.testSetBlockAccess - Test 2 using accessBlock2.xml");
|
217
|
accessBlockXML = getTestDocFromFile(testdatadir + "accessBlock2.xml");
|
218
|
setBlockAccess(docId, accessBlockXML, true);
|
219
|
accessXML = m.getAccessControl(docId);
|
220
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
221
|
accessBlockDAOList = getAccessDAOList(docId, accessBlockXML);
|
222
|
debugAccessDAOList(accessBlockDAOList);
|
223
|
compareAccessDAOs(realAccessDAOList, accessBlockDAOList, true);
|
224
|
|
225
|
// replace access for doc using the access section in accessBlock3.xml,
|
226
|
// then test that the access was updated and that is the only access
|
227
|
// for the doc
|
228
|
debug("AccessAPITest.testSetBlockAccess - Test 3 using accessBlock3.xml");
|
229
|
accessBlockXML = getTestDocFromFile(testdatadir + "accessBlock3.xml");
|
230
|
setBlockAccess(docId, accessBlockXML, true);
|
231
|
accessXML = m.getAccessControl(docId);
|
232
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
233
|
accessBlockDAOList = getAccessDAOList(docId, accessBlockXML);
|
234
|
debugAccessDAOList(accessBlockDAOList);
|
235
|
compareAccessDAOs(realAccessDAOList, accessBlockDAOList, true);
|
236
|
|
237
|
// replace access for doc using the access section in accessBlock4.xml,
|
238
|
// then test that the access was updated and that is the only access
|
239
|
// for the doc
|
240
|
debug("AccessAPITest.testSetBlockAccess - Test 4 using accessBlock4.xml");
|
241
|
accessBlockXML = getTestDocFromFile(testdatadir + "accessBlock4.xml");
|
242
|
setBlockAccess(docId, accessBlockXML, true);
|
243
|
accessXML = m.getAccessControl(docId);
|
244
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
245
|
accessBlockDAOList = getAccessDAOList(docId, accessBlockXML);
|
246
|
debugAccessDAOList(accessBlockDAOList);
|
247
|
compareAccessDAOs(realAccessDAOList, accessBlockDAOList, true);
|
248
|
|
249
|
// replace access for doc using the access section in accessBlock5.xml,
|
250
|
// then test that the access was updated and that is the only access
|
251
|
// for the doc
|
252
|
debug("AccessAPITest.testSetBlockAccess - Test 5 using accessBlock5.xml");
|
253
|
accessBlockXML = getTestDocFromFile(testdatadir + "accessBlock5.xml");
|
254
|
setBlockAccess(docId, accessBlockXML, true);
|
255
|
accessXML = m.getAccessControl(docId);
|
256
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
257
|
accessBlockDAOList = getAccessDAOList(docId, accessBlockXML);
|
258
|
debugAccessDAOList(accessBlockDAOList);
|
259
|
compareAccessDAOs(realAccessDAOList, accessBlockDAOList, true);
|
260
|
|
261
|
// replace access for doc using the access section in accessBlock6.xml,
|
262
|
// then test that the access was updated and that is the only access
|
263
|
// for the doc
|
264
|
debug("AccessAPITest.testSetBlockAccess - Test 6 using accessBlock6.xml");
|
265
|
accessBlockXML = getTestDocFromFile(testdatadir + "accessBlock6.xml");
|
266
|
setBlockAccess(docId, accessBlockXML, true);
|
267
|
accessXML = m.getAccessControl(docId);
|
268
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
269
|
accessBlockDAOList = getAccessDAOList(docId, accessBlockXML);
|
270
|
debugAccessDAOList(accessBlockDAOList);
|
271
|
compareAccessDAOs(realAccessDAOList, accessBlockDAOList, true);
|
272
|
|
273
|
// replace access for doc using the access section in accessBlock7.xml,
|
274
|
// then test that the access was updated and that is the only access
|
275
|
// for the doc
|
276
|
debug("AccessAPITest.testSetBlockAccess - Test 7 using accessBlock7.xml");
|
277
|
accessBlockXML = getTestDocFromFile(testdatadir + "accessBlock7.xml");
|
278
|
setBlockAccess(docId, accessBlockXML, true);
|
279
|
accessXML = m.getAccessControl(docId);
|
280
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
281
|
accessBlockDAOList = getAccessDAOList(docId, accessBlockXML);
|
282
|
debugAccessDAOList(accessBlockDAOList);
|
283
|
compareAccessDAOs(realAccessDAOList, accessBlockDAOList, true);
|
284
|
|
285
|
// replace access for doc using the access section in accessBlock8.xml,
|
286
|
// then test that the access was updated and that is the only access
|
287
|
// for the doc
|
288
|
debug("AccessAPITest.testSetBlockAccess - Test 8 using accessBlock8.xml");
|
289
|
accessBlockXML = getTestDocFromFile(testdatadir + "accessBlock8.xml");
|
290
|
setBlockAccess(docId, accessBlockXML, true);
|
291
|
accessXML = m.getAccessControl(docId);
|
292
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
293
|
accessBlockDAOList = getAccessDAOList(docId, accessBlockXML);
|
294
|
debugAccessDAOList(accessBlockDAOList);
|
295
|
compareAccessDAOs(realAccessDAOList, accessBlockDAOList, true);
|
296
|
|
297
|
// replace access for doc using the access section in accessBlock9.xml,
|
298
|
// then test that the access was updated and that is the only access
|
299
|
// for the doc
|
300
|
debug("AccessAPITest.testSetBlockAccess - Test 9 using accessBlock9.xml");
|
301
|
accessBlockXML = getTestDocFromFile(testdatadir + "accessBlock9.xml");
|
302
|
setBlockAccess(docId, accessBlockXML, true);
|
303
|
accessXML = m.getAccessControl(docId);
|
304
|
realAccessDAOList = getAccessDAOList(docId, accessXML);
|
305
|
accessBlockDAOList = getAccessDAOList(docId, accessBlockXML);
|
306
|
debugAccessDAOList(accessBlockDAOList);
|
307
|
compareAccessDAOs(realAccessDAOList, accessBlockDAOList, true);
|
308
|
|
309
|
} catch (AccessControlException ace) {
|
310
|
fail("AccessAPITest.testSetBlockAccess - Access Control error: " + ace.getMessage());
|
311
|
} catch (IOException ioe) {
|
312
|
fail("AccessAPITest.testSetBlockAccess - I/O error: " + ioe.getMessage());
|
313
|
} catch (MetacatAuthException mae) {
|
314
|
fail("AccessAPITest.testSetBlockAccess - Metacat authentication error: " + mae.getMessage());
|
315
|
} catch (MetacatException me) {
|
316
|
fail("AccessAPITest.testSetBlockAccess - Metacat error: " + me.getMessage());
|
317
|
} catch (InsufficientKarmaException ike) {
|
318
|
fail("AccessAPITest.testSetBlockAccess - Metacat error: " + ike.getMessage());
|
319
|
} catch (MetacatInaccessibleException mie) {
|
320
|
fail("AccessAPITest.testSetBlockAccess - Metacat Inaccessible Error: " + mie.getMessage());
|
321
|
}
|
322
|
}
|
323
|
|
324
|
/**
|
325
|
* Insert a single row of access for a document.
|
326
|
*
|
327
|
* @param docId
|
328
|
* the id of the document to update
|
329
|
* @param principal
|
330
|
* the principal credentails
|
331
|
* @param permission
|
332
|
* the permission
|
333
|
* @param permType
|
334
|
* the permission type
|
335
|
* @param permOrder
|
336
|
* the permission order
|
337
|
* @param successExpected
|
338
|
* if true, we expect the insert to succeed, otherwise, we expect
|
339
|
* it to fail
|
340
|
* @return the metacat response xml
|
341
|
*/
|
342
|
private String setSingleAccess(String docId, String principal, String permission,
|
343
|
String permType, String permOrder, boolean successExpected) {
|
344
|
debug("AccessAPITest.setSingleAccess - docid: " + docId + ", prinicpal: " +
|
345
|
principal + ", permission: " + permission + ", permType: " + permType +
|
346
|
", permOrder: " + permOrder + ", errorExpected: " + successExpected);
|
347
|
String response = null;
|
348
|
try {
|
349
|
// set the access using metacat client
|
350
|
response = m.setAccess(docId, principal, permission, permType, permOrder);
|
351
|
|
352
|
debug("AccessAPITest.setSingleAccess - response: " + response);
|
353
|
|
354
|
if (successExpected) {
|
355
|
assertTrue(response, (response.indexOf("<success>") != -1));
|
356
|
} else {
|
357
|
assertTrue(response, (response.indexOf("<success>") == -1));
|
358
|
}
|
359
|
} catch (MetacatInaccessibleException mie) {
|
360
|
fail("AccessAPITest.setSingleAccess - Metacat inaccessible: " + mie.getMessage());
|
361
|
} catch (InsufficientKarmaException ike) {
|
362
|
|
363
|
} catch (MetacatException me) {
|
364
|
if (successExpected) {
|
365
|
fail("AccessAPITest.setSingleAccess - Metacat error: " + me.getMessage());
|
366
|
} else {
|
367
|
debug("AccessAPITest.setSingleAccess - Expected Metacat error: " + me.getMessage());
|
368
|
}
|
369
|
} catch (Exception e) {
|
370
|
fail("AccessAPITest.setSingleAccess - General error: " + e.getMessage());
|
371
|
}
|
372
|
|
373
|
return response;
|
374
|
}
|
375
|
|
376
|
/**
|
377
|
* Replace a block of access
|
378
|
*
|
379
|
* @param docId
|
380
|
* the id of the doc we want to update
|
381
|
* @param accessBlockXML
|
382
|
* the access xml section
|
383
|
* @param successExpected
|
384
|
* if true, we expect the insert to succeed, otherwise, we expect
|
385
|
* it to fail
|
386
|
* @return the metacat response xml
|
387
|
*/
|
388
|
private String setBlockAccess(String docId, String accessBlockXML, boolean successExpected) {
|
389
|
debug("AccessAPITest.setBlockAccess - docid: " + docId + ", accessBlockXML: " +
|
390
|
accessBlockXML + ", errorExpected: " + successExpected);
|
391
|
String response = null;
|
392
|
try {
|
393
|
// set the access using metacat client
|
394
|
response = m.setAccess(docId, accessBlockXML);
|
395
|
|
396
|
debug("AccessAPITest.setBlockAccess - response: " + response);
|
397
|
|
398
|
if (successExpected) {
|
399
|
assertTrue(response, (response.indexOf("<success>") != -1));
|
400
|
} else {
|
401
|
assertTrue(response, (response.indexOf("<success>") == -1));
|
402
|
}
|
403
|
} catch (MetacatInaccessibleException mie) {
|
404
|
fail("AccessAPITest.setBlockAccess - Metacat inaccessible: " + mie.getMessage());
|
405
|
} catch (InsufficientKarmaException ike) {
|
406
|
|
407
|
} catch (MetacatException me) {
|
408
|
if (successExpected) {
|
409
|
fail("AccessAPITest.setBlockAccess - Metacat error: " + me.getMessage());
|
410
|
} else {
|
411
|
debug("AccessAPITest.setBlockAccess - Expected Metacat error: " + me.getMessage());
|
412
|
}
|
413
|
} catch (Exception e) {
|
414
|
fail("AccessAPITest.setBlockAccess - General error: " + e.getMessage());
|
415
|
}
|
416
|
|
417
|
return response;
|
418
|
}
|
419
|
|
420
|
/**
|
421
|
* Compare two lists of XML Access DAO objects. The first list is the master
|
422
|
* list and the second is the sub list. All elements of the sub list must be
|
423
|
* in the master list or a failed assertion is generated. If the exactMatch
|
424
|
* parameter is true, the master and sub lists must be the same, otherwise,
|
425
|
* the sub list can be a subset of the master list.
|
426
|
*
|
427
|
* @param mainAccessDAOList
|
428
|
* The main list of DAOs
|
429
|
* @param subAccessDAOList
|
430
|
* The sub list of DAOs
|
431
|
* @param exactMatch
|
432
|
* if true, the master and sub lists must be exactly the same,
|
433
|
* otherwise, the sublist must only be a subset of the master
|
434
|
*/
|
435
|
private void compareAccessDAOs(Vector<XMLAccessDAO> mainAccessDAOList,
|
436
|
Vector<XMLAccessDAO> subAccessDAOList, boolean exactMatch) {
|
437
|
|
438
|
|
439
|
//debug("test access DAO: ");
|
440
|
//debugAccessDAOList(subAccessDAOList);
|
441
|
//debug("\naccess DAOs from database: ");
|
442
|
//debugAccessDAOList(mainAccessDAOList);
|
443
|
|
444
|
// if exactMatch is true, both lists must be the same size. The next section will
|
445
|
// make sure elements match.
|
446
|
if (exactMatch) {
|
447
|
if (mainAccessDAOList.size() != subAccessDAOList.size()) {
|
448
|
fail("AccessAPITest.compareAccessDAOs - access DAO list sizes do not match. " +
|
449
|
"Primary DAO list size: " + mainAccessDAOList.size() +
|
450
|
", secondary DAO list size: " + subAccessDAOList.size());
|
451
|
}
|
452
|
}
|
453
|
|
454
|
// iterate through the sub list and make sure all its elements are in the master list
|
455
|
for (XMLAccessDAO subAccessDAO : subAccessDAOList) {
|
456
|
boolean matchFound = false;
|
457
|
for (XMLAccessDAO mainAccessDAO : mainAccessDAOList) {
|
458
|
if (subAccessDAO.getDocId().equals(mainAccessDAO.getDocId()) &&
|
459
|
subAccessDAO.getPermOrder().equals(mainAccessDAO.getPermOrder()) &&
|
460
|
subAccessDAO.getPermType().equals(mainAccessDAO.getPermType()) &&
|
461
|
subAccessDAO.getPrincipalName().equals(mainAccessDAO.getPrincipalName()) &&
|
462
|
subAccessDAO.getPermission().equals(mainAccessDAO.getPermission())) {
|
463
|
matchFound = true;
|
464
|
break;
|
465
|
}
|
466
|
}
|
467
|
|
468
|
if (!matchFound) {
|
469
|
fail("AccessAPITest.compareAccessDAOs - secondary access DAO does not exist in " +
|
470
|
"primary DAO list");
|
471
|
}
|
472
|
}
|
473
|
}
|
474
|
|
475
|
/**
|
476
|
* Get a vector of access DAO objects from an EML 2.1.0-like access section
|
477
|
* of xml
|
478
|
*
|
479
|
* @param docId
|
480
|
* the doc id that we are getting access for. this makes it
|
481
|
* easier to create a DocInfoHandler object.
|
482
|
* @param accessXML
|
483
|
* the access xml we want to parse.
|
484
|
* @return a list of XML access DAO objects.
|
485
|
*/
|
486
|
private Vector<XMLAccessDAO> getAccessDAOList(String docId, String accessXML)
|
487
|
throws AccessControlException {
|
488
|
|
489
|
Vector<XMLAccessDAO> accessControlList = null;
|
490
|
XMLReader parser = null;
|
491
|
DocInfoHandler docInfoHandler = new DocInfoHandler(docId);
|
492
|
ContentHandler chandler = docInfoHandler;
|
493
|
|
494
|
try {
|
495
|
// Get an instance of the parser. the DocInfoHandler will handle
|
496
|
// the extraction of access info.
|
497
|
String parserName = PropertyService.getProperty("xml.saxparser");
|
498
|
parser = XMLReaderFactory.createXMLReader(parserName);
|
499
|
|
500
|
// Turn off validation
|
501
|
parser.setFeature("http://xml.org/sax/features/validation", false);
|
502
|
parser.setContentHandler((ContentHandler)chandler);
|
503
|
parser.setErrorHandler((ErrorHandler)chandler);
|
504
|
|
505
|
parser.parse(new InputSource(new StringReader(accessXML)));
|
506
|
|
507
|
accessControlList = docInfoHandler.getAccessControlList();
|
508
|
} catch (PropertyNotFoundException pnfe) {
|
509
|
throw new AccessControlException("AccessAPITest.getAccessDAOList - " +
|
510
|
"property error: " + pnfe.getMessage());
|
511
|
} catch (IOException ioe) {
|
512
|
throw new AccessControlException("AccessAPITest.getAccessDAOList - " +
|
513
|
"I/O error: " + ioe.getMessage());
|
514
|
} catch (SAXException se) {
|
515
|
throw new AccessControlException("AccessAPITest.getAccessDAOList - " +
|
516
|
"SAX error: " + se.getMessage());
|
517
|
}
|
518
|
|
519
|
return accessControlList;
|
520
|
}
|
521
|
|
522
|
/**
|
523
|
* Print out the contents of an access DAO list
|
524
|
* @param accessDAOList
|
525
|
*/
|
526
|
private void debugAccessDAOList(Vector<XMLAccessDAO> accessDAOList) {
|
527
|
for (XMLAccessDAO xmlAccessDAO : accessDAOList) {
|
528
|
debug("Doc ID: " + xmlAccessDAO.getDocId());
|
529
|
debug("Perm Order: " + xmlAccessDAO.getPermOrder());
|
530
|
debug("Perm Type: " + xmlAccessDAO.getPermType());
|
531
|
debug("Principal " + xmlAccessDAO.getPrincipalName());
|
532
|
String permissionStr =
|
533
|
AccessControlList.txtValue(xmlAccessDAO.getPermission().intValue());
|
534
|
debug("Permission " + permissionStr);
|
535
|
}
|
536
|
}
|
537
|
}
|