View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * ACL Service operations.
42   */
43  public class AclService
44  {
45      /**
46       * getACL.
47       */
48      public static void getACL( CallContext context, CmisService service, String repositoryId,
49          HttpServletRequest request, HttpServletResponse response )
50          throws Exception
51      {
52          // get parameters
53          String objectId = (String) context.get( CONTEXT_OBJECT_ID );
54          Boolean onlyBasicPermissions = getBooleanParameter( request, Constants.PARAM_ONLY_BASIC_PERMISSIONS );
55  
56          // execute
57          Acl acl = service.getAcl( repositoryId, objectId, onlyBasicPermissions, null );
58  
59          // return ACL
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       * applyACL.
74       */
75      public static void applyACL( CallContext context, CmisService service, String repositoryId,
76          HttpServletRequest request, HttpServletResponse response )
77          throws Exception
78      {
79          // get parameters
80          String objectId = (String) context.get( CONTEXT_OBJECT_ID );
81          AclPropagation aclPropagation = getEnumParameter( request, Constants.PARAM_ACL_PROPAGATION, AclPropagation.class );
82  
83          // execute
84          ControlParser cp = new ControlParser( request );
85  
86          Acl acl = service.applyAcl( repositoryId, objectId, createAddAcl( cp ), createRemoveAcl( cp ), aclPropagation,
87                  null );
88  
89          // return ACL
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 }