Revision 819
Added by bojilova over 22 years ago
AccessControlList.java | ||
---|---|---|
47 | 47 |
import org.xml.sax.helpers.XMLReaderFactory; |
48 | 48 |
import org.xml.sax.helpers.DefaultHandler; |
49 | 49 |
|
50 |
//import edu.ucsb.nceas.dbadapter.AbstractDatabase; |
|
51 |
|
|
52 | 50 |
/** |
53 | 51 |
* A Class that loads eml-access.xml file containing ACL for a metadata |
54 | 52 |
* document into relational DB. It extends DefaultHandler class to handle |
... | ... | |
116 | 114 |
* @param serverCode the serverid from xml_replication on which this document |
117 | 115 |
* resides. |
118 | 116 |
*/ |
119 |
public AccessControlList(Connection conn, String aclid, Reader acl, |
|
117 |
public AccessControlList(Connection conn, String aclid, //Reader acl,
|
|
120 | 118 |
String user, String[] groups, int serverCode) |
121 |
throws SAXException, IOException, ClassNotFoundException, |
|
122 |
Exception |
|
119 |
throws SAXException, IOException, McdbException |
|
123 | 120 |
{ |
124 | 121 |
String parserName = MetaCatUtil.getOption("saxparser"); |
125 | 122 |
this.server = MetaCatUtil.getOption("server"); |
... | ... | |
133 | 130 |
this.user = user; |
134 | 131 |
this.groups = groups; |
135 | 132 |
this.aclid = aclid; |
136 |
DocumentImpl aclinfo = new DocumentImpl(conn,aclid,false); |
|
137 |
this.rev = aclinfo.getRev(); |
|
138 | 133 |
this.resourceURL = new Vector(); |
139 | 134 |
this.resourceID = new Vector(); |
140 | 135 |
this.principal = new Vector(); |
... | ... | |
143 | 138 |
// this.publicAcc = null; |
144 | 139 |
this.serverCode = serverCode; |
145 | 140 |
|
146 |
// Initialize the parser and read the queryspec |
|
141 |
// read the access file from db connection |
|
142 |
DocumentImpl acldoc = new DocumentImpl(conn, aclid); |
|
143 |
String acl = acldoc.toString(); |
|
144 |
this.rev = acldoc.getRev(); |
|
145 |
|
|
146 |
// Initialize the parse |
|
147 | 147 |
XMLReader parser = initializeParser(); |
148 |
parser.parse(new InputSource(acl)); |
|
149 |
|
|
148 |
// parse the access file and write the info to xml_access |
|
149 |
parser.parse(new InputSource(new StringReader(acl))); |
|
150 |
|
|
150 | 151 |
} |
151 | 152 |
|
152 |
/**
|
|
153 |
* Construct an instance of the AccessControlList class.
|
|
154 |
* It parses eml-access file and loads acl data into db connection.
|
|
155 |
* It is used from command line execution.
|
|
156 |
*
|
|
157 |
* @param conn the JDBC connection where acl data are loaded
|
|
158 |
* @param docid the Accession# of the document with the acl data
|
|
159 |
* @param aclfilename the name of acl file containing acl data
|
|
160 |
* @param user the user connected to MetaCat servlet and owns the document
|
|
161 |
* @param groups the groups to which user belongs
|
|
162 |
*/
|
|
163 |
public AccessControlList( Connection conn, String aclid, String aclfilename,
|
|
164 |
String user, String[] groups )
|
|
165 |
throws SAXException, IOException, ClassNotFoundException,
|
|
166 |
Exception
|
|
167 |
{ |
|
168 |
this(conn, aclid, new FileReader(new File(aclfilename).toString()), |
|
169 |
user, groups, 1); |
|
170 |
} |
|
153 |
// NOT USED
|
|
154 |
// /**
|
|
155 |
// * Construct an instance of the AccessControlList class.
|
|
156 |
// * It parses eml-access file and loads acl data into db connection.
|
|
157 |
// * It is used from command line execution.
|
|
158 |
// *
|
|
159 |
// * @param conn the JDBC connection where acl data are loaded
|
|
160 |
// * @param docid the Accession# of the document with the acl data
|
|
161 |
// * @param aclfilename the name of acl file containing acl data
|
|
162 |
// * @param user the user connected to MetaCat servlet and owns the document
|
|
163 |
// * @param groups the groups to which user belongs
|
|
164 |
// */
|
|
165 |
// public AccessControlList( Connection conn, String aclid, String aclfilename,
|
|
166 |
// String user, String[] groups )
|
|
167 |
// throws SAXException, IOException, McdbException
|
|
168 |
// {
|
|
169 |
// this(conn, aclid, new FileReader(new File(aclfilename).toString()),
|
|
170 |
// user, groups, 1);
|
|
171 |
// }
|
|
171 | 172 |
|
172 | 173 |
/* Set up the SAX parser for reading the XML serialized ACL */ |
173 | 174 |
private XMLReader initializeParser() throws SAXException |
... | ... | |
203 | 204 |
//delete all previously submitted permissions @ relations |
204 | 205 |
//this happens only on UPDATE of the access file |
205 | 206 |
try { |
206 |
this.aclObjects = getACLObjects(aclid + sep + rev);
|
|
207 |
this.aclObjects = getACLObjects(aclid); |
|
207 | 208 |
|
209 |
//delete all permissions for resources related to @aclid if any |
|
208 | 210 |
if ( aclid != null ) { |
209 |
//delete all permissions for resources related to @aclid if any |
|
210 | 211 |
deletePermissionsForRelatedResources(aclid); |
211 |
// //then delete all relations with docid of @aclid if any |
|
212 |
// deleteRelations(aclid); |
|
213 | 212 |
} |
214 | 213 |
} catch (SQLException sqle) { |
215 | 214 |
throw new SAXException(sqle); |
Also available in: Unified diff
- when the Access file goes first before the Package file (eml-dataset-2.0)
relations are not available in xml_relation, thus updated the code
to check and run ACL also after the Package file is saved.
- cut out the rev# from subject and object in xml_relation as needed by ACL
- put missing pstmt.close in RelationHandler.