1 |
1399
|
tao
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Purpose: A Class that represents an XML Text node and its contents,
|
4 |
|
|
* and can build itself from a database connection
|
5 |
|
|
* Copyright: 2000 Regents of the University of California and the
|
6 |
|
|
* National Center for Ecological Analysis and Synthesis
|
7 |
|
|
* Authors: Matt Jones
|
8 |
|
|
*
|
9 |
|
|
* '$Author$'
|
10 |
|
|
* '$Date$'
|
11 |
|
|
* '$Revision$'
|
12 |
|
|
*
|
13 |
|
|
* This program is free software; you can redistribute it and/or modify
|
14 |
|
|
* it under the terms of the GNU General Public License as published by
|
15 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
16 |
|
|
* (at your option) any later version.
|
17 |
|
|
*
|
18 |
|
|
* This program is distributed in the hope that it will be useful,
|
19 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
20 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
21 |
|
|
* GNU General Public License for more details.
|
22 |
|
|
*
|
23 |
|
|
* You should have received a copy of the GNU General Public License
|
24 |
|
|
* along with this program; if not, write to the Free Software
|
25 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
26 |
|
|
*/
|
27 |
|
|
|
28 |
5089
|
daigle
|
package edu.ucsb.nceas.metacat.accesscontrol;
|
29 |
1399
|
tao
|
|
30 |
|
|
import java.util.Vector;
|
31 |
2663
|
sgarg
|
import org.apache.log4j.Logger;
|
32 |
1399
|
tao
|
/**
|
33 |
|
|
* A Class that represents an XML access rule. It include principal and
|
34 |
|
|
* permission
|
35 |
|
|
*/
|
36 |
|
|
public class AccessRule
|
37 |
|
|
{
|
38 |
1402
|
tao
|
private String permissionType = null;
|
39 |
4468
|
daigle
|
private Vector<String> principal = new Vector<String>();
|
40 |
1402
|
tao
|
private int permission = 0;
|
41 |
2663
|
sgarg
|
private Logger logMetacat = Logger.getLogger(AccessRule.class);
|
42 |
1402
|
tao
|
|
43 |
|
|
/** Set the permssionType */
|
44 |
|
|
public void setPermissionType(String type)
|
45 |
|
|
{
|
46 |
|
|
permissionType = type;
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
public String getPermissionType()
|
50 |
|
|
{
|
51 |
|
|
return permissionType;
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
/** Set the a principle */
|
55 |
|
|
public void addPrincipal(String newPrincipal)
|
56 |
|
|
{
|
57 |
|
|
this.principal.addElement(newPrincipal);
|
58 |
|
|
}
|
59 |
1399
|
tao
|
|
60 |
1402
|
tao
|
/** Get the principle vector */
|
61 |
4468
|
daigle
|
public Vector<String> getPrincipal()
|
62 |
1402
|
tao
|
{
|
63 |
|
|
return principal;
|
64 |
|
|
}
|
65 |
1399
|
tao
|
|
66 |
1402
|
tao
|
/**
|
67 |
|
|
* Set a permission.
|
68 |
|
|
*/
|
69 |
|
|
public void setPermission(int myPermission)
|
70 |
|
|
{
|
71 |
|
|
permission = myPermission;
|
72 |
|
|
}
|
73 |
1399
|
tao
|
|
74 |
1402
|
tao
|
/**
|
75 |
|
|
* Get permission
|
76 |
|
|
*/
|
77 |
|
|
public int getPermission()
|
78 |
|
|
{
|
79 |
|
|
return permission;
|
80 |
|
|
}
|
81 |
|
|
|
82 |
|
|
/**
|
83 |
|
|
* Copy a AccessRule to another accessrule object
|
84 |
|
|
*/
|
85 |
1406
|
tao
|
public Object clone()
|
86 |
1402
|
tao
|
{
|
87 |
|
|
// create a new object
|
88 |
|
|
AccessRule newRule = new AccessRule();
|
89 |
|
|
// set permissiontype
|
90 |
2663
|
sgarg
|
logMetacat.info("copy permission type: "+
|
91 |
2588
|
sgarg
|
this.getPermissionType());
|
92 |
1406
|
tao
|
newRule.setPermissionType(this.getPermissionType());
|
93 |
1402
|
tao
|
// set permission
|
94 |
2663
|
sgarg
|
logMetacat.info("copy permission: "+
|
95 |
2588
|
sgarg
|
this.getPermission());
|
96 |
1406
|
tao
|
newRule.setPermission(this.getPermission());
|
97 |
1402
|
tao
|
// walk through all the principals
|
98 |
1406
|
tao
|
Vector principalVector = this.getPrincipal();
|
99 |
1402
|
tao
|
for (int i=0; i<principalVector.size(); i++)
|
100 |
1399
|
tao
|
{
|
101 |
1402
|
tao
|
String name = (String)principalVector.elementAt(i);
|
102 |
2663
|
sgarg
|
logMetacat.info("copy principle: "+ name);
|
103 |
1402
|
tao
|
// Add this name to newrules
|
104 |
|
|
newRule.addPrincipal(name);
|
105 |
1399
|
tao
|
}
|
106 |
1402
|
tao
|
return newRule;
|
107 |
|
|
}
|
108 |
|
|
|
109 |
1406
|
tao
|
|
110 |
1402
|
tao
|
}//AccessRule
|