Project

General

Profile

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