Revision 7128
Added by ben leinfelder over 12 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
891 | 891 |
PrintWriter out = response.getWriter(); |
892 | 892 |
if ((userName != null) && !userName.equals("public")) { |
893 | 893 |
handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, params, userName, |
894 |
groupNames, true); |
|
894 |
groupNames, true, true);
|
|
895 | 895 |
} else { |
896 | 896 |
response.setContentType("text/xml"); |
897 | 897 |
out.println("<?xml version=\"1.0\"?>"); |
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
2555 | 2555 |
* the user that owns the document |
2556 | 2556 |
* @param groups |
2557 | 2557 |
* the groups to which user belongs |
2558 |
* @param writeAccessRules |
|
2558 | 2559 |
*/ |
2559 | 2560 |
/* |
2560 | 2561 |
* public static String write(DBConnection conn,String filename, String pub, |
... | ... | |
2569 | 2570 |
|
2570 | 2571 |
public static String write(DBConnection conn, String xmlString, String pub, |
2571 | 2572 |
Reader dtd, String action, String docid, String user, |
2572 |
String[] groups, String ruleBase, boolean needValidation) |
|
2573 |
String[] groups, String ruleBase, boolean needValidation, boolean writeAccessRules)
|
|
2573 | 2574 |
throws Exception |
2574 | 2575 |
{ |
2575 | 2576 |
//this method will be called in handleUpdateOrInsert method |
... | ... | |
2577 | 2578 |
// get server location for this doc |
2578 | 2579 |
int serverLocation = getServerLocationNumber(docid); |
2579 | 2580 |
return write(conn, xmlString, pub, dtd, action, docid, user, groups, |
2580 |
serverLocation, false, ruleBase, needValidation); |
|
2581 |
serverLocation, false, ruleBase, needValidation, writeAccessRules);
|
|
2581 | 2582 |
} |
2582 | 2583 |
|
2583 | 2584 |
/** |
... | ... | |
2608 | 2609 |
* checked upon update for a file lock. if override = false then |
2609 | 2610 |
* a document not from this server, upon update will be locked |
2610 | 2611 |
* and version checked. |
2612 |
* @param writeAccessRules |
|
2611 | 2613 |
*/ |
2612 | 2614 |
|
2613 | 2615 |
public static String write(DBConnection conn, String xmlString, String pub, |
2614 | 2616 |
Reader dtd, String action, String accnum, String user, |
2615 | 2617 |
String[] groups, int serverCode, boolean override, String ruleBase, |
2616 |
boolean needValidation) throws Exception |
|
2618 |
boolean needValidation, boolean writeAccessRules) throws Exception
|
|
2617 | 2619 |
{ |
2618 | 2620 |
// NEW - WHEN CLIENT ALWAYS PROVIDE ACCESSION NUMBER INCLUDING REV IN IT |
2619 | 2621 |
|
... | ... | |
2685 | 2687 |
logMetacat.debug("DocumentImpl.write - initializing parser"); |
2686 | 2688 |
parser = initializeParser(conn, action, docid, xmlReader, updaterev, |
2687 | 2689 |
user, groups, pub, serverCode, dtd, ruleBase, |
2688 |
needValidation, false, null, null, encoding); |
|
2690 |
needValidation, false, null, null, encoding, writeAccessRules);
|
|
2689 | 2691 |
// false means it is not a revision doc |
2690 | 2692 |
//null, null are createdate and updatedate |
2691 | 2693 |
//null will use current time as create date time |
... | ... | |
2775 | 2777 |
String encoding = xsr.getEncoding(); |
2776 | 2778 |
|
2777 | 2779 |
parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups, |
2778 |
pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding); |
|
2780 |
pub, serverCode, dtd, ruleBase, needValidation, false, null, null, encoding, writeAccessRules);
|
|
2779 | 2781 |
// null and null are createtime and updatetime |
2780 | 2782 |
// null will create current time |
2781 | 2783 |
//false means it is not a revision doc |
... | ... | |
2962 | 2964 |
// detect encoding |
2963 | 2965 |
XmlStreamReader xsr = new XmlStreamReader(new ByteArrayInputStream(xmlString.getBytes())); |
2964 | 2966 |
String encoding = xsr.getEncoding(); |
2967 |
|
|
2968 |
// no need to write the EML-contained access rules for replication |
|
2969 |
boolean writeAccessRules = false; |
|
2965 | 2970 |
|
2966 | 2971 |
parser = initializeParser(conn, action, docid, xmlReader, rev, user, groups, |
2967 | 2972 |
pub, serverCode, dtd, ruleBase, needValidation, |
2968 |
isRevision, createDate, updateDate, encoding); |
|
2973 |
isRevision, createDate, updateDate, encoding, writeAccessRules);
|
|
2969 | 2974 |
|
2970 | 2975 |
conn.setAutoCommit(false); |
2971 | 2976 |
parser.parse(new InputSource(xmlReader)); |
... | ... | |
3460 | 3465 |
|
3461 | 3466 |
/** |
3462 | 3467 |
* Set up the parser handlers for writing the document to the database |
3468 |
* @param writeAccessRules |
|
3463 | 3469 |
*/ |
3464 | 3470 |
private static XMLReader initializeParser(DBConnection dbconn, |
3465 | 3471 |
String action, String docid, Reader xml, String rev, String user, |
3466 | 3472 |
String[] groups, String pub, int serverCode, Reader dtd, |
3467 | 3473 |
String ruleBase, boolean needValidation, boolean isRevision, |
3468 |
Date createDate, Date updateDate, String encoding) throws Exception |
|
3474 |
Date createDate, Date updateDate, String encoding, boolean writeAccessRules) throws Exception
|
|
3469 | 3475 |
{ |
3470 | 3476 |
XMLReader parser = null; |
3471 | 3477 |
try { |
... | ... | |
3480 | 3486 |
if (ruleBase != null && ruleBase.equals(EML200)) { |
3481 | 3487 |
logMetacat.info("DocumentImpl.initalizeParser - Using eml 2.0.0 parser"); |
3482 | 3488 |
chandler = new Eml200SAXHandler(dbconn, action, docid, rev, |
3483 |
user, groups, pub, serverCode, createDate, updateDate); |
|
3489 |
user, groups, pub, serverCode, createDate, updateDate, writeAccessRules);
|
|
3484 | 3490 |
chandler.setIsRevisionDoc(isRevision); |
3485 | 3491 |
chandler.setEncoding(encoding); |
3486 | 3492 |
parser.setContentHandler((ContentHandler) chandler); |
... | ... | |
3507 | 3513 |
} else if (ruleBase != null && ruleBase.equals(EML210)) { |
3508 | 3514 |
logMetacat.info("DocumentImpl.initalizeParser - Using eml 2.1.0 parser"); |
3509 | 3515 |
chandler = new Eml210SAXHandler(dbconn, action, docid, rev, |
3510 |
user, groups, pub, serverCode, createDate, updateDate); |
|
3516 |
user, groups, pub, serverCode, createDate, updateDate, writeAccessRules);
|
|
3511 | 3517 |
chandler.setIsRevisionDoc(isRevision); |
3512 | 3518 |
chandler.setEncoding(encoding); |
3513 | 3519 |
parser.setContentHandler((ContentHandler) chandler); |
... | ... | |
3534 | 3540 |
//create a DBSAXHandler object which has the revision |
3535 | 3541 |
// specification |
3536 | 3542 |
chandler = new DBSAXHandler(dbconn, action, docid, rev, user, |
3537 |
groups, pub, serverCode, createDate, updateDate); |
|
3543 |
groups, pub, serverCode, createDate, updateDate, writeAccessRules);
|
|
3538 | 3544 |
chandler.setIsRevisionDoc(isRevision); |
3539 | 3545 |
chandler.setEncoding(encoding); |
3540 | 3546 |
parser.setContentHandler((ContentHandler) chandler); |
src/edu/ucsb/nceas/metacat/DocumentImplWrapper.java | ||
---|---|---|
44 | 44 |
/* Attributes */ |
45 | 45 |
private String ruleBase = null; |
46 | 46 |
private boolean needValidation = false; |
47 |
private boolean writeAccessRules = true; |
|
47 | 48 |
|
48 | 49 |
/** |
49 | 50 |
* Constructor of DocumentImpleWrapper |
50 | 51 |
* @param myRuleBase the xml is base on DTD or Schema |
51 | 52 |
* @param validation if the xml document need to be validated |
52 | 53 |
*/ |
53 |
public DocumentImplWrapper(String myRuleBase, boolean validation) { |
|
54 |
public DocumentImplWrapper(String myRuleBase, boolean validation, boolean writeAccessRules) {
|
|
54 | 55 |
ruleBase = myRuleBase; |
55 | 56 |
needValidation = validation; |
57 |
this.writeAccessRules = writeAccessRules; |
|
56 | 58 |
|
57 | 59 |
}//Constructor |
58 | 60 |
|
59 | 61 |
public String write(DBConnection conn, String xml, String pub, Reader dtd, |
60 | 62 |
String action, String docid, String user, String[] groups) throws Exception { |
61 | 63 |
return DocumentImpl.write(conn, xml, pub, dtd, action, docid, user, groups, |
62 |
ruleBase, needValidation); |
|
64 |
ruleBase, needValidation, writeAccessRules);
|
|
63 | 65 |
} |
64 | 66 |
|
65 | 67 |
public String writeReplication(DBConnection conn, String xml, String pub, Reader dtd, |
src/edu/ucsb/nceas/metacat/MetacatHandler.java | ||
---|---|---|
1630 | 1630 |
*/ |
1631 | 1631 |
public String handleInsertOrUpdateAction(String ipAddress, String userAgent, |
1632 | 1632 |
HttpServletResponse response, PrintWriter out, Hashtable<String, String[]> params, |
1633 |
String user, String[] groups, boolean generateSystemMetadata) { |
|
1633 |
String user, String[] groups, boolean generateSystemMetadata, boolean writeAccessRules) {
|
|
1634 | 1634 |
Logger logMetacat = Logger.getLogger(MetacatHandler.class); |
1635 | 1635 |
DBConnection dbConn = null; |
1636 | 1636 |
int serialNumber = -1; |
... | ... | |
1733 | 1733 |
if (validate) { |
1734 | 1734 |
// set a dtd base validation parser |
1735 | 1735 |
String rule = DocumentImpl.DTD; |
1736 |
documentWrapper = new DocumentImplWrapper(rule, validate); |
|
1736 |
documentWrapper = new DocumentImplWrapper(rule, validate, writeAccessRules);
|
|
1737 | 1737 |
} else { |
1738 | 1738 |
|
1739 | 1739 |
namespace = XMLSchemaService.findDocumentNamespace(xmlReader); |
... | ... | |
1747 | 1747 |
// using emlparser to check id validation |
1748 | 1748 |
@SuppressWarnings("unused") |
1749 | 1749 |
EMLParser parser = new EMLParser(doctext[0]); |
1750 |
documentWrapper = new DocumentImplWrapper(rule, true); |
|
1750 |
documentWrapper = new DocumentImplWrapper(rule, true, writeAccessRules);
|
|
1751 | 1751 |
} else if ( |
1752 | 1752 |
namespace.compareTo(DocumentImpl.EML2_1_0NAMESPACE) == 0 |
1753 | 1753 |
|| namespace.compareTo(DocumentImpl.EML2_1_1NAMESPACE) == 0) { |
... | ... | |
1756 | 1756 |
// using emlparser to check id validation |
1757 | 1757 |
@SuppressWarnings("unused") |
1758 | 1758 |
EMLParser parser = new EMLParser(doctext[0]); |
1759 |
documentWrapper = new DocumentImplWrapper(rule, true); |
|
1759 |
documentWrapper = new DocumentImplWrapper(rule, true, writeAccessRules);
|
|
1760 | 1760 |
} else { |
1761 | 1761 |
// set schema base validation parser |
1762 | 1762 |
String rule = DocumentImpl.SCHEMA; |
1763 |
documentWrapper = new DocumentImplWrapper(rule, true); |
|
1763 |
documentWrapper = new DocumentImplWrapper(rule, true, writeAccessRules);
|
|
1764 | 1764 |
} |
1765 | 1765 |
} else { |
1766 |
documentWrapper = new DocumentImplWrapper("", false); |
|
1766 |
documentWrapper = new DocumentImplWrapper("", false, writeAccessRules);
|
|
1767 | 1767 |
} |
1768 | 1768 |
} |
1769 | 1769 |
|
... | ... | |
2865 | 2865 |
String[] doctextArr = new String[1]; |
2866 | 2866 |
doctextArr[0] = doctext; |
2867 | 2867 |
params.put("doctext", doctextArr); |
2868 |
boolean writeAccessRules = true; |
|
2868 | 2869 |
//call the insert routine |
2869 | 2870 |
handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), response, out, |
2870 |
params, username, groupnames, true); |
|
2871 |
params, username, groupnames, true, writeAccessRules);
|
|
2871 | 2872 |
} |
2872 | 2873 |
catch(Exception e) |
2873 | 2874 |
{ |
src/edu/ucsb/nceas/metacat/util/EMLVersionsTransformer.java | ||
---|---|---|
151 | 151 |
String rule = DocumentImpl.EML210; |
152 | 152 |
// using emlparser to check id validation |
153 | 153 |
EMLParser parser = new EMLParser(eml210Content); |
154 |
DocumentImplWrapper documentWrapper = new DocumentImplWrapper(rule, true); |
|
154 |
DocumentImplWrapper documentWrapper = new DocumentImplWrapper(rule, true, true);
|
|
155 | 155 |
// StringReader xml = new StringReader(eml210Content); |
156 | 156 |
String doAction = "UPDATE"; |
157 | 157 |
String pub = null; |
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java | ||
---|---|---|
1128 | 1128 |
// do the insert or update action |
1129 | 1129 |
handler = new MetacatHandler(new Timer()); |
1130 | 1130 |
String result = handler.handleInsertOrUpdateAction(request.getRemoteAddr(), request.getHeader("User-Agent"), null, |
1131 |
null, params, username, groupnames, false); |
|
1131 |
null, params, username, groupnames, false, false);
|
|
1132 | 1132 |
|
1133 | 1133 |
if(result.indexOf("<error>") != -1) { |
1134 | 1134 |
String detailCode = ""; |
src/edu/ucsb/nceas/metacat/DBSAXHandler.java | ||
---|---|---|
141 | 141 |
boolean startParseTriple = false; |
142 | 142 |
|
143 | 143 |
boolean hasTriple = false; |
144 |
|
|
145 |
protected boolean writeAccessRules = true; |
|
144 | 146 |
|
147 |
|
|
145 | 148 |
public static final String ECOGRID = "ecogrid://"; |
146 | 149 |
|
147 | 150 |
private Logger logMetacat = Logger.getLogger(DBSAXHandler.class); |
... | ... | |
212 | 215 |
*/ |
213 | 216 |
public DBSAXHandler(DBConnection conn, String action, String docid, |
214 | 217 |
String revision, String user, String[] groups, String pub, |
215 |
int serverCode, Date createDate, Date updateDate) |
|
218 |
int serverCode, Date createDate, Date updateDate, boolean writeAccessRules)
|
|
216 | 219 |
{ |
217 | 220 |
this(conn, createDate, updateDate); |
218 | 221 |
this.action = action; |
... | ... | |
222 | 225 |
this.groups = groups; |
223 | 226 |
this.pub = pub; |
224 | 227 |
this.serverCode = serverCode; |
228 |
this.writeAccessRules = writeAccessRules; |
|
225 | 229 |
} |
226 | 230 |
|
227 | 231 |
/** SAX Handler that receives notification of beginning of the document */ |
src/edu/ucsb/nceas/metacat/Eml200SAXHandler.java | ||
---|---|---|
331 | 331 |
*/ |
332 | 332 |
public Eml200SAXHandler(DBConnection conn, String action, String docid, |
333 | 333 |
String revision, String user, String[] groups, String pub, |
334 |
int serverCode, Date createDate, Date updateDate) throws SAXException |
|
334 |
int serverCode, Date createDate, Date updateDate, boolean writeAccessRules) throws SAXException
|
|
335 | 335 |
{ |
336 | 336 |
super(conn, action, docid, revision, user, groups, pub, |
337 |
serverCode, createDate, updateDate); |
|
337 |
serverCode, createDate, updateDate, writeAccessRules);
|
|
338 | 338 |
// Get the unchangable subtrees (user doesn't have write permission) |
339 | 339 |
try |
340 | 340 |
{ |
... | ... | |
1690 | 1690 |
// info into xml_accesssubtree about the top access, additional access |
1691 | 1691 |
// and some third place access modules which are referenced by top |
1692 | 1692 |
// level or additional level |
1693 |
writeAccessRuleToDB(); |
|
1693 |
if (writeAccessRules ) { |
|
1694 |
writeAccessRuleToDB(); |
|
1695 |
} |
|
1694 | 1696 |
|
1695 | 1697 |
//delete relation table |
1696 | 1698 |
deleteRelations(); |
src/edu/ucsb/nceas/metacat/Eml210SAXHandler.java | ||
---|---|---|
191 | 191 |
*/ |
192 | 192 |
public Eml210SAXHandler(DBConnection conn, String action, String docid, |
193 | 193 |
String revision, String user, String[] groups, String pub, int serverCode, |
194 |
Date createDate, Date updateDate) throws SAXException { |
|
194 |
Date createDate, Date updateDate, boolean writeAccessRules) throws SAXException {
|
|
195 | 195 |
super(conn, action, docid, revision, user, groups, pub, serverCode, createDate, |
196 |
updateDate); |
|
196 |
updateDate, writeAccessRules);
|
|
197 | 197 |
// Get the unchangeable subtrees (user doesn't have write permission) |
198 | 198 |
try { |
199 | 199 |
|
... | ... | |
1180 | 1180 |
// This maybe cause user change the subtree id |
1181 | 1181 |
if (!super.getIsRevisionDoc()) { |
1182 | 1182 |
// write access rule to db |
1183 |
writeAccessRuleToDB(); |
|
1183 |
if (writeAccessRules) { |
|
1184 |
writeAccessRuleToDB(); |
|
1185 |
} |
|
1184 | 1186 |
// delete relation table |
1185 | 1187 |
deleteRelations(); |
1186 | 1188 |
// write relations |
src/edu/ucsb/nceas/metacat/replication/ReplicationHandler.java | ||
---|---|---|
443 | 443 |
parserBase = DocumentImpl.EML210; |
444 | 444 |
} |
445 | 445 |
// Write the document into local host |
446 |
DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false); |
|
446 |
DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false, false);
|
|
447 | 447 |
String newDocid = wrapper.writeReplication(dbConn, |
448 | 448 |
newxmldoc, |
449 | 449 |
docinfoHash.get("public_access"), |
src/edu/ucsb/nceas/metacat/replication/ReplicationService.java | ||
---|---|---|
569 | 569 |
.getDBConnection("MetacatReplication.handleForceReplicateRequest"); |
570 | 570 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
571 | 571 |
// write the document to local database |
572 |
DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false); |
|
572 |
DocumentImplWrapper wrapper = new DocumentImplWrapper(parserBase, false, false);
|
|
573 | 573 |
//try this independently so we can set access even if the update action is invalid (i.e docid has not changed) |
574 | 574 |
try { |
575 | 575 |
wrapper.writeReplication(dbConn, xmldoc, null, null, |
Also available in: Unified diff
add a parameter for optionally writing EML-embedded access control rules to the Metacat DB.
https://redmine.dataone.org/issues/2584
https://redmine.dataone.org/issues/2583