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.browser;
20
21 import org.apache.chemistry.opencmis.commons.data.Acl;
22 import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
23 import org.apache.chemistry.opencmis.commons.impl.Constants;
24 import org.apache.chemistry.opencmis.commons.impl.JSONConverter;
25 import org.apache.chemistry.opencmis.commons.impl.json.JSONObject;
26 import org.apache.chemistry.opencmis.commons.server.CallContext;
27 import org.apache.chemistry.opencmis.commons.server.CmisService;
28 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.CONTEXT_OBJECT_ID;
29 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createAddAcl;
30 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.createRemoveAcl;
31 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.setStatus;
32 import static org.apache.chemistry.opencmis.server.impl.browser.BrowserBindingUtils.writeJSON;
33 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
34 import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getEnumParameter;
35
36 import javax.servlet.http.HttpServletRequest;
37 import javax.servlet.http.HttpServletResponse;
38
39
40
41
42
43 public class AclService
44 {
45
46
47
48 public static void getACL( CallContext context, CmisService service, String repositoryId,
49 HttpServletRequest request, HttpServletResponse response )
50 throws Exception
51 {
52
53 String objectId = (String) context.get( CONTEXT_OBJECT_ID );
54 Boolean onlyBasicPermissions = getBooleanParameter( request, Constants.PARAM_ONLY_BASIC_PERMISSIONS );
55
56
57 Acl acl = service.getAcl( repositoryId, objectId, onlyBasicPermissions, null );
58
59
60 response.setStatus( HttpServletResponse.SC_OK );
61
62 JSONObject jsonObject = JSONConverter.convert( acl );
63
64 if ( jsonObject == null )
65 {
66 jsonObject = new JSONObject( );
67 }
68
69 writeJSON( jsonObject, request, response );
70 }
71
72
73
74
75 public static void applyACL( CallContext context, CmisService service, String repositoryId,
76 HttpServletRequest request, HttpServletResponse response )
77 throws Exception
78 {
79
80 String objectId = (String) context.get( CONTEXT_OBJECT_ID );
81 AclPropagation aclPropagation = getEnumParameter( request, Constants.PARAM_ACL_PROPAGATION, AclPropagation.class );
82
83
84 ControlParser cp = new ControlParser( request );
85
86 Acl acl = service.applyAcl( repositoryId, objectId, createAddAcl( cp ), createRemoveAcl( cp ), aclPropagation,
87 null );
88
89
90 setStatus( request, response, HttpServletResponse.SC_CREATED );
91
92 JSONObject jsonObject = JSONConverter.convert( acl );
93
94 if ( jsonObject == null )
95 {
96 jsonObject = new JSONObject( );
97 }
98
99 writeJSON( jsonObject, request, response );
100 }
101 }