This project has retired. For details please refer to its
Attic page.
AclService xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.server.impl.atompub;
20
21 import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
22 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
23 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getEnumParameter;
24 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
25
26 import javax.servlet.http.HttpServletRequest;
27 import javax.servlet.http.HttpServletResponse;
28 import javax.xml.bind.JAXBElement;
29 import javax.xml.bind.Unmarshaller;
30
31 import org.apache.chemistry.opencmis.commons.data.Acl;
32 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
33 import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
34 import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
35 import org.apache.chemistry.opencmis.commons.impl.Constants;
36 import org.apache.chemistry.opencmis.commons.impl.JaxBHelper;
37 import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisAccessControlListType;
38 import org.apache.chemistry.opencmis.commons.server.CallContext;
39 import org.apache.chemistry.opencmis.commons.server.CmisService;
40
41
42
43
44 public class AclService {
45
46 private AclService() {
47 }
48
49
50
51
52 public static void getAcl(CallContext context, CmisService service, String repositoryId,
53 HttpServletRequest request, HttpServletResponse response) throws Exception {
54
55 String objectId = getStringParameter(request, Constants.PARAM_ID);
56 Boolean onlyBasicPermissions = getBooleanParameter(request, Constants.PARAM_ONLY_BASIC_PERMISSIONS);
57
58
59 Acl acl = service.getAcl(repositoryId, objectId, onlyBasicPermissions, null);
60
61 if (acl == null) {
62 throw new CmisRuntimeException("ACL is null!");
63 }
64
65
66 response.setStatus(HttpServletResponse.SC_OK);
67 response.setContentType(Constants.MEDIATYPE_ACL);
68
69
70 AclDocument aclDocument = new AclDocument();
71 aclDocument.writeAcl(acl, response.getOutputStream());
72 }
73
74
75
76
77 public static void applyAcl(CallContext context, CmisService service, String repositoryId,
78 HttpServletRequest request, HttpServletResponse response) throws Exception {
79
80 String objectId = getStringParameter(request, Constants.PARAM_ID);
81 AclPropagation aclPropagation = getEnumParameter(request, Constants.PARAM_ACL_PROPAGATION, AclPropagation.class);
82
83 Object aclRequest = null;
84 try {
85 Unmarshaller u = JaxBHelper.createUnmarshaller();
86 aclRequest = u.unmarshal(request.getInputStream());
87 } catch (Exception e) {
88 throw new CmisInvalidArgumentException("Invalid ACL request: " + e, e);
89 }
90
91 if (!(aclRequest instanceof JAXBElement<?>)) {
92 throw new CmisInvalidArgumentException("Not an ACL document!");
93 }
94
95 if (!(((JAXBElement<?>) aclRequest).getValue() instanceof CmisAccessControlListType)) {
96 throw new CmisInvalidArgumentException("Not an ACL document!");
97 }
98
99 Acl aces = convert((CmisAccessControlListType) ((JAXBElement<?>) aclRequest).getValue(), null);
100
101
102 Acl acl = service.applyAcl(repositoryId, objectId, aces, aclPropagation);
103
104
105 response.setStatus(HttpServletResponse.SC_CREATED);
106 response.setContentType(Constants.MEDIATYPE_ACL);
107
108
109 AclDocument aclDocument = new AclDocument();
110 aclDocument.writeAcl(acl, response.getOutputStream());
111 }
112 }