Revision 5098
Added by daigle over 14 years ago
MetaCatServlet.java | ||
---|---|---|
73 | 73 |
import com.oreilly.servlet.multipart.ParamPart; |
74 | 74 |
import com.oreilly.servlet.multipart.Part; |
75 | 75 |
|
76 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlException; |
|
76 | 77 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlForSingleFile; |
77 | 78 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlInterface; |
78 | 79 |
import edu.ucsb.nceas.metacat.accesscontrol.AccessControlList; |
... | ... | |
89 | 90 |
import edu.ucsb.nceas.metacat.service.ServiceService; |
90 | 91 |
import edu.ucsb.nceas.metacat.service.SessionService; |
91 | 92 |
import edu.ucsb.nceas.metacat.service.XMLSchemaService; |
93 |
import edu.ucsb.nceas.metacat.shared.ServiceException; |
|
92 | 94 |
import edu.ucsb.nceas.metacat.shared.BaseException; |
93 | 95 |
import edu.ucsb.nceas.metacat.shared.HandlerException; |
94 | 96 |
import edu.ucsb.nceas.metacat.shared.MetacatUtilException; |
95 |
import edu.ucsb.nceas.metacat.shared.ServiceException;
|
|
97 |
//import edu.ucsb.nceas.metacat.shared.AccessException;
|
|
96 | 98 |
import edu.ucsb.nceas.metacat.spatial.SpatialHarvester; |
97 | 99 |
import edu.ucsb.nceas.metacat.spatial.SpatialQuery; |
98 | 100 |
import edu.ucsb.nceas.metacat.util.AuthUtil; |
... | ... | |
2722 | 2724 |
} |
2723 | 2725 |
|
2724 | 2726 |
try { |
2725 |
|
|
2726 |
// get connection from the pool |
|
2727 |
dbConn = DBConnectionPool |
|
2728 |
.getDBConnection("MetaCatServlet.handleGetAccessControlAction"); |
|
2729 |
serialNumber = dbConn.getCheckOutSerialNumber(); |
|
2730 |
AccessControlList aclobj = new AccessControlList(dbConn); |
|
2731 |
String acltext = aclobj.getACL(docid, username, groupnames); |
|
2727 |
AccessControlForSingleFile acfsf = new AccessControlForSingleFile(docid); |
|
2728 |
String acltext = acfsf.getACL(username, groupnames, true); |
|
2732 | 2729 |
if (qformat.equals("xml")) { |
2733 | 2730 |
response.setContentType("text/xml"); |
2734 | 2731 |
out.println(acltext); |
... | ... | |
3508 | 3505 |
private void handleSetAccessAction(PrintWriter out, Hashtable<String, String[]> params, |
3509 | 3506 |
String username, HttpServletRequest request, HttpServletResponse response) { |
3510 | 3507 |
Logger logMetacat = Logger.getLogger(MetaCatServlet.class); |
3511 |
String[] docList = null; |
|
3512 |
String[] principalList = null; |
|
3513 |
String[] permissionList = null; |
|
3514 |
String[] permTypeList = null; |
|
3515 |
String[] permOrderList = null; |
|
3516 |
String[] qformatList = null; |
|
3508 |
|
|
3517 | 3509 |
String permission = null; |
3518 | 3510 |
String permType = null; |
3519 | 3511 |
String permOrder = null; |
... | ... | |
3523 | 3515 |
String success = null; |
3524 | 3516 |
boolean isEmlPkgMember = false; |
3525 | 3517 |
|
3526 |
// Get parameters |
|
3527 |
if (params.containsKey("docid")) { |
|
3528 |
docList = params.get("docid"); |
|
3529 |
} |
|
3530 |
if (params.containsKey("principal")) { |
|
3531 |
principalList = params.get("principal"); |
|
3532 |
} |
|
3533 |
if (params.containsKey("permission")) { |
|
3534 |
permissionList = params.get("permission"); |
|
3535 |
|
|
3536 |
} |
|
3537 |
if (params.containsKey("permType")) { |
|
3538 |
permTypeList = params.get("permType"); |
|
3539 |
|
|
3540 |
} |
|
3541 |
if (params.containsKey("permOrder")) { |
|
3542 |
permOrderList = params.get("permOrder"); |
|
3543 |
|
|
3544 |
} |
|
3518 |
String[] docList = params.get("docid"); |
|
3519 |
String[] principalList = params.get("principal"); |
|
3520 |
String[] permissionList = params.get("permission"); |
|
3521 |
String[] permTypeList = params.get("permType"); |
|
3522 |
String[] permOrderList = params.get("permOrder"); |
|
3523 |
String[] qformatList = params.get("qformat"); |
|
3524 |
String[] accessBlock = params.get("accessBlock"); |
|
3545 | 3525 |
|
3546 |
if (params.containsKey("qformat")) { |
|
3547 |
qformatList = params.get("qformat"); |
|
3548 |
|
|
3526 |
if(accessBlock != null) { |
|
3527 |
if (docList == null) { |
|
3528 |
errorList.addElement("MetaCatServlet.handleSetAccessAction - Please check your parameter list, it should look like: " |
|
3529 |
+ "?action=setaccess&docid=<doc_id>&accessBlock=<access_section>"); |
|
3530 |
outputResponse(successList, errorList, out); |
|
3531 |
return; |
|
3532 |
} |
|
3533 |
|
|
3534 |
try { |
|
3535 |
AccessControlForSingleFile accessControl = |
|
3536 |
new AccessControlForSingleFile(docList[0]); |
|
3537 |
accessControl.insertPermissions(accessBlock[0]); |
|
3538 |
} catch(AccessControlException ace) { |
|
3539 |
errorList.addElement("MetaCatServlet.handleSetAccessAction - access control error when setting " + |
|
3540 |
"access block: " + ace.getMessage()); |
|
3541 |
} |
|
3542 |
outputResponse(successList, errorList, out); |
|
3543 |
return; |
|
3549 | 3544 |
} |
3550 | 3545 |
|
3551 | 3546 |
// Make sure the parameter is not null |
... | ... | |
3606 | 3601 |
} catch (Exception e) { |
3607 | 3602 |
logMetacat.error("MetaCatServlet.handleSetAccessAction - Error in handleSetAccessAction: " |
3608 | 3603 |
+ e.getMessage()); |
3609 |
error = "Error in set access control for document - " |
|
3610 |
+ accessionNumber + e.getMessage(); |
|
3604 |
error = "Error in set access control for document - " + accessionNumber + e.getMessage(); |
|
3611 | 3605 |
errorList.addElement(error); |
3612 | 3606 |
continue; |
3613 | 3607 |
} |
3614 | 3608 |
//check if user is the owner. Only owner can do owner |
3615 | 3609 |
if (username == null || owner == null || !username.equals(owner)) { |
3616 |
error = "User - " + username |
|
3617 |
+ " does not have permission to set " |
|
3610 |
error = "User - " + username + " does not have permission to set " |
|
3618 | 3611 |
+ "access control for docid - " + accessionNumber; |
3619 | 3612 |
errorList.addElement(error); |
3620 | 3613 |
continue; |
... | ... | |
3626 | 3619 |
if (isEmlPkgMember == false) |
3627 | 3620 |
isEmlPkgMember = (DBUtil.findDataSetDocIdForGivenDocument(accessionNumber) != null); |
3628 | 3621 |
|
3629 |
// If docid publicid is BIN data file or other beta4, 6 package |
|
3630 |
// document |
|
3631 |
// we could not do set access control. Because we don't want |
|
3632 |
// inconsistent |
|
3622 |
// If docid publicid is BIN data file or other beta4, 6 package document |
|
3623 |
// we could not do set access control. Because we don't want inconsistent |
|
3633 | 3624 |
// to its access docuemnt |
3634 | 3625 |
if (publicId != null && packageSet != null |
3635 | 3626 |
&& packageSet.contains(publicId) && isEmlPkgMember) { |
3636 |
error = "Could not set access control to document " |
|
3637 |
+ accessionNumber |
|
3627 |
error = "Could not set access control to document " + accessionNumber |
|
3638 | 3628 |
+ "because it is in a pakcage and it has a access file for it"; |
3639 | 3629 |
errorList.addElement(error); |
3640 | 3630 |
continue; |
... | ... | |
3645 | 3635 |
String principal = principalList[j]; |
3646 | 3636 |
try { |
3647 | 3637 |
//insert permission |
3648 |
AccessControlForSingleFile accessControl = new AccessControlForSingleFile(
|
|
3649 |
accessionNumber, principal, permission, permType, permOrder);
|
|
3650 |
accessControl.insertPermissions(); |
|
3638 |
AccessControlForSingleFile accessControl = |
|
3639 |
new AccessControlForSingleFile(accessionNumber);
|
|
3640 |
accessControl.insertPermissions(principal, Long.valueOf(permission), permType, permOrder);
|
|
3651 | 3641 |
} catch (Exception ee) { |
3652 | 3642 |
logMetacat.error("MetaCatServlet.handleSetAccessAction - Error inserting permission: " |
3653 | 3643 |
+ ee.getMessage()); |
Also available in: Unified diff
change AccessControlForSingleFile to only be instantiated for one file. move ACL methods to AccessControlForSingleFile. Change format of access sections returned to EML 2.1.0.