Revision 4419
Added by ben leinfelder about 16 years ago
src/edu/ucsb/nceas/metacat/MetacatReplication.java | ||
---|---|---|
682 | 682 |
dbaction, docid, user, null, homeServer, |
683 | 683 |
server, createdDate, updatedDate); |
684 | 684 |
|
685 |
//process extra access rules |
|
686 |
Vector accessControlList = (Vector) docinfoHash.get("accessControl"); |
|
687 |
if (accessControlList != null) { |
|
688 |
for (int i = 0; i < accessControlList.size(); i++) { |
|
689 |
AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i); |
|
690 |
acfsf.insertPermissions(); |
|
691 |
} |
|
692 |
} |
|
693 |
|
|
685 | 694 |
MetacatReplication.replLog("document " + docid + " added to DB with " + |
686 | 695 |
"action " + dbaction); |
687 | 696 |
EventLog.getInstance().log(request.getRemoteAddr(), REPLICATIONUSER, docid, dbaction); |
... | ... | |
832 | 841 |
DocumentImpl.writeDataFileInReplication(url.openStream(), datafilePath, |
833 | 842 |
docName, docType, docid, user,docHomeServer,server, |
834 | 843 |
DocumentImpl.DOCUMENTTABLE, false, createdDate, updatedDate); |
844 |
//process extra access rules |
|
845 |
Vector accessControlList = (Vector) docinfoHash.get("accessControl"); |
|
846 |
if (accessControlList != null) { |
|
847 |
for (int i = 0; i < accessControlList.size(); i++) { |
|
848 |
AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i); |
|
849 |
acfsf.insertPermissions(); |
|
850 |
} |
|
851 |
} |
|
852 |
|
|
835 | 853 |
//false means non-timed replication |
836 | 854 |
MetacatReplication.replLog("datafile " + docid + " added to DB with " + |
837 | 855 |
"action " + dbaction); |
... | ... | |
945 | 963 |
sb.append("</home_server>"); |
946 | 964 |
sb.append("<public_access>").append(doc.getPublicaccess()); |
947 | 965 |
sb.append("</public_access><rev>").append(doc.getRev()); |
948 |
sb.append("</rev></documentinfo>"); |
|
966 |
sb.append("</rev>"); |
|
967 |
|
|
968 |
//permissions on the document |
|
969 |
PermissionController permController = new PermissionController(docid); |
|
970 |
Vector accessControlList = permController.getAccessControl(); |
|
971 |
sb.append("<accessControl>"); |
|
972 |
for (int i = 0; i < accessControlList.size(); i++) { |
|
973 |
AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i); |
|
974 |
sb.append(acfsf.getAccessString()); |
|
975 |
} |
|
976 |
sb.append("</accessControl>"); |
|
977 |
|
|
978 |
sb.append("</documentinfo>"); |
|
949 | 979 |
response.setContentType("text/xml"); |
950 | 980 |
out.println(sb.toString()); |
951 | 981 |
|
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
3589 | 3589 |
continue; |
3590 | 3590 |
} |
3591 | 3591 |
} |
3592 |
|
|
3593 |
//force replication when this action is called |
|
3594 |
boolean isXml = true; |
|
3595 |
if (publicId.equalsIgnoreCase("BIN")) { |
|
3596 |
isXml = false; |
|
3597 |
} |
|
3598 |
ForceReplicationHandler frh = |
|
3599 |
new ForceReplicationHandler(accessionNumber, isXml, null); |
|
3600 |
|
|
3592 | 3601 |
} |
3593 | 3602 |
outputResponse(successList, errorList, out); |
3594 | 3603 |
} |
src/edu/ucsb/nceas/metacat/PermissionController.java | ||
---|---|---|
646 | 646 |
|
647 | 647 |
}//isAllowFirst |
648 | 648 |
|
649 |
/** |
|
650 |
* Check if the permission order for user at that documents is allowFirst |
|
651 |
* @param principals, list of names of principals to check for |
|
652 |
* @param docid, document identifier to check for |
|
653 |
*/ |
|
654 |
public Vector getAccessControl() |
|
655 |
throws SQLException, Exception |
|
656 |
{ |
|
657 |
Vector accessControl = new Vector(); |
|
658 |
boolean hasRow; |
|
659 |
PreparedStatement pStmt = null; |
|
660 |
DBConnection conn = null; |
|
661 |
int serialNumber = -1; |
|
662 |
String sql = null; |
|
663 |
boolean topLever =false; |
|
664 |
sql = "SELECT principal_name, permission, perm_type, perm_order FROM xml_access "; |
|
665 |
|
|
666 |
//TODO, need this? |
|
667 |
long startId = 0; |
|
668 |
if (startId == TOPLEVELSTARTNODEID) |
|
669 |
{ |
|
670 |
//top level |
|
671 |
topLever = true; |
|
672 |
sql += "WHERE docid = ? AND startnodeid is NULL"; |
|
673 |
} |
|
674 |
else |
|
675 |
{ |
|
676 |
//sub tree level |
|
677 |
sql += "WHERE docid = ? AND startnodeid = ?"; |
|
678 |
} |
|
679 |
|
|
680 |
try |
|
681 |
{ |
|
682 |
//check out DBConnection |
|
683 |
conn=DBConnectionPool.getDBConnection("AccessControlList.getPermissions"); |
|
684 |
serialNumber=conn.getCheckOutSerialNumber(); |
|
685 |
|
|
686 |
//select permission order from database |
|
687 |
pStmt = conn.prepareStatement(sql); |
|
688 |
|
|
689 |
//bind value |
|
690 |
pStmt.setString(1, docId);//docid |
|
691 |
|
|
692 |
// if subtree, we need set subtree id |
|
693 |
if (!topLever) |
|
694 |
{ |
|
695 |
pStmt.setLong(2, startId); |
|
696 |
} |
|
697 |
|
|
698 |
pStmt.execute(); |
|
699 |
ResultSet rs = pStmt.getResultSet(); |
|
700 |
while (rs.next()) |
|
701 |
{ |
|
702 |
//get the permission order from data base |
|
703 |
String principalName=rs.getString(1); |
|
704 |
String permission=rs.getString(2); |
|
705 |
String permType=rs.getString(3); |
|
706 |
String permOrder=rs.getString(4); |
|
707 |
|
|
708 |
//make it into an object |
|
709 |
AccessControlForSingleFile acfsf = |
|
710 |
new AccessControlForSingleFile(docId, principalName, permission, permType, permOrder); |
|
711 |
accessControl.add(acfsf); |
|
712 |
} |
|
713 |
pStmt.close(); |
|
714 |
}//try |
|
715 |
catch (SQLException e) |
|
716 |
{ |
|
717 |
throw e; |
|
718 |
} |
|
719 |
finally |
|
720 |
{ |
|
721 |
try |
|
722 |
{ |
|
723 |
pStmt.close(); |
|
724 |
} |
|
725 |
finally |
|
726 |
{ |
|
727 |
DBConnectionPool.returnDBConnection(conn, serialNumber); |
|
728 |
} |
|
729 |
} |
|
730 |
|
|
731 |
return accessControl; |
|
732 |
|
|
733 |
}//getPermissions |
|
734 |
|
|
649 | 735 |
/** |
650 | 736 |
* Check if the users array has allow rules for given users, docid and |
651 | 737 |
* permission. |
src/edu/ucsb/nceas/metacat/ReplicationHandler.java | ||
---|---|---|
365 | 365 |
remoteserver, tableName, true,// true is for time replication |
366 | 366 |
createdDate, |
367 | 367 |
updatedDate); |
368 |
|
|
369 |
//process extra access rules |
|
370 |
Vector accessControlList = (Vector) docinfoHash.get("accessControl"); |
|
371 |
if (accessControlList != null) { |
|
372 |
for (int i = 0; i < accessControlList.size(); i++) { |
|
373 |
AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i); |
|
374 |
acfsf.insertPermissions(); |
|
375 |
} |
|
376 |
} |
|
377 |
|
|
368 | 378 |
logMetacat.info("Successfully replicated doc " + accNumber); |
369 | 379 |
if (tableName.equals(DocumentImpl.DOCUMENTTABLE)) |
370 | 380 |
{ |
... | ... | |
481 | 491 |
createdDate, |
482 | 492 |
updatedDate); |
483 | 493 |
|
494 |
//process extra access rules |
|
495 |
Vector accessControlList = (Vector) docinfoHash.get("accessControl"); |
|
496 |
if (accessControlList != null) { |
|
497 |
for (int i = 0; i < accessControlList.size(); i++) { |
|
498 |
AccessControlForSingleFile acfsf = (AccessControlForSingleFile) accessControlList.get(i); |
|
499 |
acfsf.insertPermissions(); |
|
500 |
} |
|
501 |
} |
|
502 |
|
|
484 | 503 |
logMetacat.info("Successfully to write datafile " + accNumber); |
485 | 504 |
/*MetacatReplication.replLog("wrote datafile " + accNumber + " from " + |
486 | 505 |
remoteserver);*/ |
src/edu/ucsb/nceas/metacat/AccessControlForSingleFile.java | ||
---|---|---|
184 | 184 |
} |
185 | 185 |
|
186 | 186 |
} |
187 |
|
|
188 |
public String getAccessString() { |
|
189 |
StringBuffer sb = new StringBuffer(); |
|
190 |
sb.append("<access>"); |
|
191 |
|
|
192 |
sb.append("<permOrder>"); |
|
193 |
sb.append(this.permOrder); |
|
194 |
sb.append("</permOrder>"); |
|
195 |
|
|
196 |
sb.append("<permType>"); |
|
197 |
sb.append(this.permType); |
|
198 |
sb.append("</permType>"); |
|
199 |
|
|
200 |
sb.append("<permission>"); |
|
201 |
sb.append(this.permission); |
|
202 |
sb.append("</permission>"); |
|
203 |
|
|
204 |
sb.append("<principal>"); |
|
205 |
sb.append(this.principal); |
|
206 |
sb.append("</principal>"); |
|
187 | 207 |
|
208 |
sb.append("</access>"); |
|
209 |
|
|
210 |
return sb.toString(); |
|
211 |
|
|
212 |
} |
|
188 | 213 |
|
214 |
|
|
189 | 215 |
} |
src/edu/ucsb/nceas/metacat/DocInfoHandler.java | ||
---|---|---|
49 | 49 |
private Hashtable docinfo = new Hashtable(); |
50 | 50 |
private String currentTag = null; |
51 | 51 |
|
52 |
private Vector acccessControlList = new Vector(); |
|
53 |
|
|
52 | 54 |
public DocInfoHandler() |
53 | 55 |
{ |
54 | 56 |
} |
... | ... | |
62 | 64 |
currentTag = localName; |
63 | 65 |
} |
64 | 66 |
|
67 |
public void endElement (String uri, String localName, String qName) |
|
68 |
throws SAXException |
|
69 |
{ |
|
70 |
if (currentTag.equals("access")) { |
|
71 |
//harvest the latest values from the Map |
|
72 |
String docid = (String) docinfo.get("docid"); |
|
73 |
String principal = (String) docinfo.get("principal"); |
|
74 |
String permission = (String) docinfo.get("permission"); |
|
75 |
String permType = (String) docinfo.get("permType"); |
|
76 |
String permOrder = (String) docinfo.get("permOrder"); |
|
77 |
AccessControlForSingleFile acfsf = null; |
|
78 |
try { |
|
79 |
acfsf = new AccessControlForSingleFile(docid, principal, permission, permType, permOrder); |
|
80 |
} catch (Exception e) { |
|
81 |
// TODO Auto-generated catch block |
|
82 |
e.printStackTrace(); |
|
83 |
} |
|
84 |
acccessControlList.add(acfsf); |
|
85 |
} |
|
86 |
//save the list when we are done |
|
87 |
if (currentTag.equals("acccessControl")) { |
|
88 |
docinfo.put("acccessControl", acccessControlList); |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
65 | 92 |
/** |
66 | 93 |
* put the content and the name of the tag into the hashtable. the name of |
67 | 94 |
* the tag is the key. |
Also available in: Unified diff
replicate xml_access entries across servers.
see: http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3464
note: still needs to be tested...but needed to be checked in for other metacat installations to be updated....