Revision 645
Added by bojilova almost 24 years ago
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
49 | 49 |
private String action = null; |
50 | 50 |
private String docid = null; |
51 | 51 |
private String user = null; |
52 |
private String group = null; |
|
52 | 53 |
private Thread xmlIndex; |
53 | 54 |
private boolean endDocument = false; |
54 | 55 |
private int serverCode = 1; |
... | ... | |
74 | 75 |
} |
75 | 76 |
} |
76 | 77 |
|
77 |
public DBSAXHandler(Connection conn,String action,String docid,String user,
|
|
78 |
int serverCode) |
|
78 |
public DBSAXHandler(Connection conn, String action, String docid,
|
|
79 |
String user, String group, int serverCode)
|
|
79 | 80 |
{ |
80 | 81 |
this(conn); |
81 | 82 |
this.action = action; |
82 | 83 |
this.docid = docid; |
83 | 84 |
this.user = user; |
85 |
this.group = group; |
|
84 | 86 |
this.xmlIndex = new Thread(this); |
85 | 87 |
this.serverCode = serverCode; |
86 | 88 |
} |
... | ... | |
92 | 94 |
* @param docid to be inserted or updated into JDBC connection |
93 | 95 |
* @param user the user connected to MetaCat servlet |
94 | 96 |
*/ |
95 |
public DBSAXHandler(Connection conn,String action,String docid,String user) |
|
97 |
public DBSAXHandler(Connection conn,String action,String docid, |
|
98 |
String user, String group) |
|
96 | 99 |
{ |
97 | 100 |
this(conn); |
98 | 101 |
this.action = action; |
99 | 102 |
this.docid = docid; |
100 | 103 |
this.user = user; |
104 |
this.group = group; |
|
101 | 105 |
this.xmlIndex = new Thread(this); |
102 | 106 |
//this.xmlIndex.setPriority(Thread.MIN_PRIORITY); |
103 | 107 |
} |
... | ... | |
223 | 227 |
{ |
224 | 228 |
DocumentImpl xmldoc = new DocumentImpl(dbconn, docid); |
225 | 229 |
String xml = xmldoc.toString(); |
226 |
AccessControlList aclobj = |
|
227 |
new AccessControlList(dbconn,docid,null,new StringReader(xml)); |
|
228 |
dbconn.commit(); |
|
230 |
try { |
|
231 |
AccessControlList aclobj = |
|
232 |
new AccessControlList(dbconn, docid, new StringReader(xml), |
|
233 |
user, group); |
|
234 |
dbconn.commit(); |
|
235 |
} catch (SAXException e) { |
|
236 |
try { |
|
237 |
dbconn.rollback(); |
|
238 |
dbconn.close(); |
|
239 |
} catch (SQLException sqle) {} |
|
240 |
System.out.println("Error writing ACL. " + e.getMessage()); |
|
241 |
} |
|
229 | 242 |
} |
230 | 243 |
|
231 | 244 |
|
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
799 | 799 |
String group, int serverCode, boolean override) |
800 | 800 |
throws Exception |
801 | 801 |
{ |
802 |
if(action.equals("UPDATE")) |
|
803 |
{ |
|
804 |
RelationHandler.deleteRelations(docid); |
|
805 |
} |
|
802 |
//MOVED DOWN IN RelationHandler obj before write of relations |
|
803 |
//if(action.equals("UPDATE")) |
|
804 |
//{ |
|
805 |
// RelationHandler.deleteRelations(docid); |
|
806 |
//} |
|
806 | 807 |
|
807 | 808 |
int updaterev; |
808 | 809 |
MetaCatUtil util = new MetaCatUtil(); |
... | ... | |
837 | 838 |
{ |
838 | 839 |
MetacatReplication.replLog("lock granted for " + docid + " from " + |
839 | 840 |
server); |
840 |
XMLReader parser = initializeParser(conn, action, newdocid, user,
|
|
841 |
serverCode, dtd); |
|
841 |
XMLReader parser = initializeParser(conn, action, newdocid, |
|
842 |
user, group, serverCode, dtd);
|
|
842 | 843 |
conn.setAutoCommit(false); |
843 | 844 |
parser.parse(new InputSource(xml)); |
844 | 845 |
conn.commit(); |
845 |
|
|
846 |
// if acltext is provided for @xml, store acl info into db |
|
847 |
if ( acl != null ) |
|
848 |
{ |
|
849 |
AccessControlList aclobj=new AccessControlList(conn,null,newdocid,acl); |
|
850 |
conn.commit(); |
|
851 |
} |
|
852 |
|
|
853 | 846 |
conn.setAutoCommit(true); |
854 | 847 |
} |
855 | 848 |
catch (Exception e) |
... | ... | |
907 | 900 |
|
908 | 901 |
try |
909 | 902 |
{ |
910 |
XMLReader parser=initializeParser(conn,action,newdocid,user,serverCode,dtd); |
|
903 |
XMLReader parser = initializeParser(conn, action, newdocid, |
|
904 |
user, group, serverCode, dtd); |
|
911 | 905 |
conn.setAutoCommit(false); |
912 | 906 |
parser.parse(new InputSource(xml)); |
913 | 907 |
conn.commit(); |
914 |
|
|
915 |
// if acltext is provided for @xml, store acl info into db |
|
916 |
if ( acl != null ) |
|
917 |
{ |
|
918 |
AccessControlList aclobj=new AccessControlList(conn,null,newdocid,acl); |
|
919 |
conn.commit(); |
|
920 |
} |
|
921 |
|
|
922 | 908 |
conn.setAutoCommit(true); |
923 |
|
|
924 | 909 |
} |
925 | 910 |
catch (Exception e) |
926 | 911 |
{ |
... | ... | |
977 | 962 |
Statement stmt = conn.createStatement(); |
978 | 963 |
stmt.execute("DELETE FROM xml_index WHERE docid = '" + docid + "'"); |
979 | 964 |
stmt.execute("DELETE FROM xml_documents WHERE docid = '" + docid + "'"); |
965 |
stmt.execute("DELETE FROM xml_access WHERE docid = '" + docid + "'"); |
|
966 |
stmt.execute("DELETE FROM xml_access WHERE accessfileid = '" + docid + "'"); |
|
967 |
stmt.execute("DELETE FROM xml_relation WHERE docid = '" + docid + "'"); |
|
980 | 968 |
stmt.close(); |
981 | 969 |
conn.commit(); |
982 | 970 |
conn.setAutoCommit(true); |
... | ... | |
984 | 972 |
//delete all of the relations that this document created. |
985 | 973 |
//if the deleted document is a package document its relations should |
986 | 974 |
//no longer be active if it has been deleted from the system. |
987 |
RelationHandler.deleteRelations(docid); |
|
975 |
|
|
976 |
// MOVED UP IN THE TRANSACTION |
|
977 |
// RelationHandler.deleteRelations(docid); |
|
988 | 978 |
} |
989 | 979 |
|
990 | 980 |
/** |
... | ... | |
1014 | 1004 |
* Set up the parser handlers for writing the document to the database |
1015 | 1005 |
*/ |
1016 | 1006 |
private static XMLReader initializeParser(Connection conn, String action, |
1017 |
String docid, String user,
|
|
1018 |
int serverCode, Reader dtd)
|
|
1007 |
String docid, String user, String group,
|
|
1008 |
int serverCode, Reader dtd) |
|
1019 | 1009 |
throws Exception |
1020 | 1010 |
{ |
1021 | 1011 |
XMLReader parser = null; |
... | ... | |
1023 | 1013 |
// Set up the SAX document handlers for parsing |
1024 | 1014 |
// |
1025 | 1015 |
try { |
1026 |
ContentHandler chandler = new DBSAXHandler(conn,action,docid,user,serverCode); |
|
1027 |
EntityResolver eresolver= new DBEntityResolver(conn,(DBSAXHandler)chandler,dtd); |
|
1016 |
ContentHandler chandler = new DBSAXHandler(conn, action, docid, |
|
1017 |
user, group, serverCode); |
|
1018 |
EntityResolver eresolver= new DBEntityResolver(conn, |
|
1019 |
(DBSAXHandler)chandler, dtd); |
|
1028 | 1020 |
DTDHandler dtdhandler = new DBDTDHandler(conn); |
1029 | 1021 |
|
1030 | 1022 |
// Get an instance of the parser |
src/edu/ucsb/nceas/metacat/RelationHandler.java | ||
---|---|---|
57 | 57 |
*/ |
58 | 58 |
public void run() |
59 | 59 |
{ |
60 |
String docid = xmldoc.getDocID(); |
|
61 |
|
|
62 |
// deletes all of the relations with a docid of @docid. |
|
63 |
deleteRelations(docid); |
|
64 |
|
|
60 | 65 |
//pseudo-code algorithm |
61 | 66 |
//for each new relation r in xml_nodes |
62 | 67 |
// put r into xml_relation |
... | ... | |
65 | 70 |
// add a new row to xml_relation that represents this new relation |
66 | 71 |
try |
67 | 72 |
{ |
68 |
String docid = xmldoc.getDocID(); |
|
69 | 73 |
PreparedStatement pstmt = conn.prepareStatement( |
70 | 74 |
QuerySpecification.printPackageSQL(docid)); |
71 | 75 |
pstmt.execute(); |
... | ... | |
195 | 199 |
* Deletes all of the relations with a docid of 'docid'. |
196 | 200 |
* @param docid the docid to delete. |
197 | 201 |
*/ |
198 |
public static void deleteRelations(String docid)
|
|
202 |
public void deleteRelations(String docid) |
|
199 | 203 |
{ |
200 | 204 |
try |
201 | 205 |
{ |
202 |
MetaCatUtil util2 = new MetaCatUtil(); |
|
203 |
Connection conn = util2.openDBConnection(); |
|
204 | 206 |
PreparedStatement pstmt = conn.prepareStatement("delete from " + |
205 | 207 |
"xml_relation where docid like '" + docid + "'"); |
206 | 208 |
pstmt.execute(); |
209 |
pstmt.close(); |
|
207 | 210 |
} |
208 | 211 |
catch(Exception e) |
209 | 212 |
{ |
213 |
try |
|
214 |
{ |
|
215 |
conn.rollback(); |
|
216 |
} |
|
217 |
catch (SQLException sqle) {} |
|
210 | 218 |
System.out.println("error in deleteRelations(): " + e.getMessage()); |
211 | 219 |
e.printStackTrace(System.out); |
212 | 220 |
} |
src/edu/ucsb/nceas/metacat/AccessControlList.java | ||
---|---|---|
44 | 44 |
private Connection conn; |
45 | 45 |
private String parserName; |
46 | 46 |
private Stack elementStack; |
47 |
private String server; |
|
47 | 48 |
|
48 | 49 |
private boolean processingDTD; |
50 |
private String user; |
|
51 |
private String group; |
|
49 | 52 |
private String aclid; |
50 |
private String docid; |
|
51 | 53 |
private String docname; |
52 | 54 |
private String doctype; |
53 | 55 |
private String systemid; |
... | ... | |
81 | 83 |
* @param docid the Accession# of the document with the acl data |
82 | 84 |
* @param acl the acl file containing acl data |
83 | 85 |
*/ |
84 |
public AccessControlList(Connection conn,String aclid,String docid,Reader acl) |
|
86 |
public AccessControlList(Connection conn, String aclid, Reader acl, |
|
87 |
String user, String group) |
|
85 | 88 |
throws SAXException, IOException, ClassNotFoundException |
86 | 89 |
{ |
87 | 90 |
// Get an instance of the parser |
88 | 91 |
MetaCatUtil util = new MetaCatUtil(); |
89 | 92 |
String parserName = util.getOption("saxparser"); |
93 |
this.server = util.getOption("server"); |
|
90 | 94 |
|
91 | 95 |
this.conn = conn; |
92 | 96 |
this.parserName = parserName; |
93 | 97 |
this.processingDTD = false; |
94 | 98 |
this.elementStack = new Stack(); |
95 | 99 |
|
100 |
this.user = user; |
|
101 |
this.group = group; |
|
96 | 102 |
this.aclid = aclid; |
97 |
this.docid = docid; |
|
98 | 103 |
this.principalName = new Vector(); |
99 | 104 |
this.permission = 0; |
100 | 105 |
this.ticketCount = 0; |
... | ... | |
113 | 118 |
* @param docid the Accession# of the document with the acl data |
114 | 119 |
* @param aclfilename the name of acl file containing acl data |
115 | 120 |
*/ |
116 |
public AccessControlList( Connection conn, String aclid, |
|
117 |
String docid, String aclfilename )
|
|
121 |
public AccessControlList( Connection conn, String aclid, String aclfilename,
|
|
122 |
String user, String group )
|
|
118 | 123 |
throws SAXException, IOException, ClassNotFoundException |
119 | 124 |
{ |
120 |
this(conn, aclid, docid, new FileReader(new File(aclfilename).toString())); |
|
125 |
this(conn, aclid, new FileReader(new File(aclfilename).toString()), |
|
126 |
user, group); |
|
121 | 127 |
} |
122 | 128 |
|
123 | 129 |
/** |
... | ... | |
149 | 155 |
} |
150 | 156 |
|
151 | 157 |
/** |
158 |
* callback method used by the SAX Parser when beginning of the document |
|
159 |
*/ |
|
160 |
public void startDocument() throws SAXException |
|
161 |
{ |
|
162 |
//delete all previously submitted permissions @ relations |
|
163 |
//this happens only on UPDATE of the access file |
|
164 |
try { |
|
165 |
if ( aclid != null ) { |
|
166 |
//first delete all permissions for resources related to @aclid if any |
|
167 |
deletePermissionsForRelatedResources(aclid); |
|
168 |
//then delete all relations with docid of @aclid if any |
|
169 |
deleteRelations(aclid); |
|
170 |
} |
|
171 |
} catch (SQLException sqle) { |
|
172 |
throw new SAXException(sqle); |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
152 | 177 |
* callback method used by the SAX Parser when the start tag of an |
153 | 178 |
* element is detected. Used in this context to parse and store |
154 | 179 |
* the acl information in class variables. |
... | ... | |
183 | 208 |
String currentTag = currentNode.getTagName(); |
184 | 209 |
|
185 | 210 |
if (currentTag.equals("resourceIdentifier")) { |
186 |
if ( docid != null ) { |
|
187 |
resourceId = docid; |
|
188 |
} else { |
|
189 |
resourceURL = inputString; |
|
190 |
resourceId = getDocID(inputString); |
|
191 |
// here should be ProtocolHandler.get("docid"); |
|
211 |
|
|
212 |
resourceURL = inputString; |
|
213 |
resourceId = getDocID(inputString); |
|
214 |
// check permissions for @user on resourceId first |
|
215 |
// @user must have permission "all" on resourceId |
|
216 |
boolean hasPermission = false; |
|
217 |
try { |
|
218 |
hasPermission = hasPermission("ALL",user,resourceId); |
|
219 |
if ( !hasPermission && group != null ) { |
|
220 |
hasPermission = hasPermission("ALL",group,resourceId); |
|
221 |
} |
|
222 |
} catch (SQLException e) { |
|
223 |
throw new SAXException(e.getMessage()); |
|
192 | 224 |
} |
225 |
if ( !hasPermission ) { |
|
226 |
throw new SAXException( |
|
227 |
"Permission denied for setting access control on " + resourceId); |
|
228 |
} |
|
229 |
// end of check for "all" perm on resourceId |
|
230 |
|
|
193 | 231 |
} else if (currentTag.equals("principalName")) { |
232 |
|
|
194 | 233 |
principalName.addElement(new String(inputString)); |
234 |
|
|
195 | 235 |
} else if (currentTag.equals("permission")) { |
236 |
|
|
196 | 237 |
if ( inputString.trim().toUpperCase().equals("READ") ) { |
197 | 238 |
permission = permission | READ; |
198 | 239 |
} else if ( inputString.trim().toUpperCase().equals("WRITE") ) { |
... | ... | |
200 | 241 |
} else if ( inputString.trim().toUpperCase().equals("ALL") ) { |
201 | 242 |
permission = permission | ALL; |
202 | 243 |
} |
244 |
|
|
203 | 245 |
} else if (currentTag.equals("duration") && |
204 | 246 |
beginTime == null && endTime == null ) { |
205 | 247 |
try { |
... | ... | |
208 | 250 |
} catch (StringIndexOutOfBoundsException se) { |
209 | 251 |
beginTime = inputString; |
210 | 252 |
} |
253 |
|
|
211 | 254 |
} else if (currentTag.equals("ticketCount") && ticketCount == 0 ) { |
212 | 255 |
ticketCount = (new Integer(inputString.trim())).intValue(); |
213 | 256 |
} |
... | ... | |
225 | 268 |
if ( leaving.getTagName().equals("resourceIdentifier") ) { |
226 | 269 |
|
227 | 270 |
try { |
228 |
// delete all acl records for resourceId first if any |
|
229 |
deletePermissions(); |
|
230 |
// make a relationship for acl file on resourceId |
|
271 |
// make a relationship for @aclid on @resourceId |
|
231 | 272 |
if ( aclid != null ) { |
232 |
insertRelation(); |
|
273 |
insertRelation(aclid, resourceURL);
|
|
233 | 274 |
} |
234 | 275 |
} catch (SQLException sqle) { |
235 | 276 |
throw new SAXException(sqle); |
... | ... | |
322 | 363 |
return processingDTD; |
323 | 364 |
} |
324 | 365 |
|
325 |
/** Delete from db all permission for resourceId if any */
|
|
326 |
private void deletePermissions()
|
|
366 |
/** Delete from db all permission for resources related to @aclid if any */
|
|
367 |
private void deletePermissionsForRelatedResources(String aclid)
|
|
327 | 368 |
throws SQLException |
328 | 369 |
{ |
329 |
// delete all acl records for resourceId if any
|
|
370 |
// delete all acl records for resources related to @aclid if any
|
|
330 | 371 |
Statement stmt = conn.createStatement(); |
331 |
stmt.execute("DELETE FROM xml_access WHERE docid='" + resourceId +"'"); |
|
372 |
// String docURL = "metacat://" + server + "/?docid="; |
|
373 |
// stmt.execute("DELETE FROM xml_access WHERE '" + docURL + "'||docid IN " + |
|
374 |
// "(SELECT object FROM xml_relation" + |
|
375 |
// " WHERE docid = '" + aclid + "'" + |
|
376 |
// " AND relationship = 'isaclfor')" ); |
|
377 |
stmt.execute("DELETE FROM xml_access WHERE accessfileid = '" + aclid + "'"); |
|
332 | 378 |
stmt.close(); |
333 | 379 |
} |
334 | 380 |
|
335 |
/** Insert relationship into db for aclid on resourceId */ |
|
336 |
private void insertRelation() |
|
381 |
/** |
|
382 |
* Deletes all of the relations with a docid of @docid. |
|
383 |
* @param docid the docid to delete. |
|
384 |
*/ |
|
385 |
public void deleteRelations(String docid) |
|
337 | 386 |
throws SQLException |
338 | 387 |
{ |
339 |
MetaCatUtil util = new MetaCatUtil(); |
|
340 |
String server = util.getOption("server"); |
|
341 |
String aclURL = "metacat://" + server + "?docid=" + aclid; |
|
388 |
Statement stmt = conn.createStatement(); |
|
389 |
stmt.execute("DELETE FROM xml_relation WHERE docid='" + docid + "'"); |
|
390 |
stmt.close(); |
|
391 |
} |
|
392 |
|
|
393 |
/** Insert relationship into db for @aclid on @resourceURL */ |
|
394 |
private void insertRelation(String aclid, String resourceURL) |
|
395 |
throws SQLException |
|
396 |
{ |
|
397 |
String aclURL = "metacat://" + server + "/?docid=" + aclid; |
|
342 | 398 |
|
343 | 399 |
// insert relationship |
344 | 400 |
PreparedStatement pstmt; |
... | ... | |
363 | 419 |
try { |
364 | 420 |
pstmt = conn.prepareStatement( |
365 | 421 |
"INSERT INTO xml_access " + |
366 |
"(docid,principal_name,permission,perm_type,perm_order," +
|
|
367 |
"begin_time,end_time,ticket_count) VALUES " + |
|
368 |
"(?,?,?,?,?,to_date(?,'mm/dd/yy'),to_date(?,'mm/dd/yy'),?)"); |
|
422 |
"(docid, principal_name, permission, perm_type, perm_order," +
|
|
423 |
"begin_time,end_time,ticket_count, accessfileid) VALUES " +
|
|
424 |
"(?,?,?,?,?,to_date(?,'mm/dd/yy'),to_date(?,'mm/dd/yy'),?,?)");
|
|
369 | 425 |
// Bind the values to the query |
370 | 426 |
pstmt.setString(1, resourceId); |
371 | 427 |
pstmt.setInt(3, permission); |
... | ... | |
373 | 429 |
pstmt.setString(5, permOrder); |
374 | 430 |
pstmt.setString(6, beginTime); |
375 | 431 |
pstmt.setString(7, endTime); |
432 |
pstmt.setString(9, aclid); |
|
376 | 433 |
if ( ticketCount > 0 ) { |
377 | 434 |
pstmt.setString(8, "" + ticketCount); |
378 | 435 |
} else { |
Also available in: Unified diff
- appling acl through access files only
- clearing around update/delete of access files - to delete the related records from both xml_access and xml_relation tables
- included check for user permissions for setting acl on the resources in the access file
- moved RelationHandler.deleteRelations(docid) down in RelationHandler obj just before the write of the new relations