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 org.apache.chemistry.opencmis.commons.data.Acl;
22  import org.apache.chemistry.opencmis.commons.enums.AclPropagation;
23  import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
24  import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
25  import org.apache.chemistry.opencmis.commons.impl.Constants;
26  import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
27  import org.apache.chemistry.opencmis.commons.impl.JaxBHelper;
28  import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisAccessControlListType;
29  import org.apache.chemistry.opencmis.commons.server.CallContext;
30  import org.apache.chemistry.opencmis.commons.server.CmisService;
31  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getBooleanParameter;
32  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getEnumParameter;
33  import static org.apache.chemistry.opencmis.server.shared.HttpUtils.getStringParameter;
34  
35  import javax.servlet.http.HttpServletRequest;
36  import javax.servlet.http.HttpServletResponse;
37  
38  import javax.xml.bind.JAXBElement;
39  import javax.xml.bind.Unmarshaller;
40  
41  
42  
43  
44  
45  public class AclService
46  {
47      private AclService(  )
48      {
49      }
50  
51      
52  
53  
54      public static void getAcl( CallContext context, CmisService service, String repositoryId,
55          HttpServletRequest request, HttpServletResponse response )
56          throws Exception
57      {
58          
59          String objectId = getStringParameter( request, Constants.PARAM_ID );
60          Boolean onlyBasicPermissions = getBooleanParameter( request, Constants.PARAM_ONLY_BASIC_PERMISSIONS );
61  
62          
63          Acl acl = service.getAcl( repositoryId, objectId, onlyBasicPermissions, null );
64  
65          if ( acl == null )
66          {
67              throw new CmisRuntimeException( "ACL is null!" );
68          }
69  
70          
71          response.setStatus( HttpServletResponse.SC_OK );
72          response.setContentType( Constants.MEDIATYPE_ACL );
73  
74          
75          AclDocument aclDocument = new AclDocument(  );
76          aclDocument.writeAcl( acl, response.getOutputStream(  ) );
77      }
78  
79      
80  
81  
82      public static void applyAcl( CallContext context, CmisService service, String repositoryId,
83          HttpServletRequest request, HttpServletResponse response )
84          throws Exception
85      {
86          
87          String objectId = getStringParameter( request, Constants.PARAM_ID );
88          AclPropagation aclPropagation = getEnumParameter( request, Constants.PARAM_ACL_PROPAGATION, AclPropagation.class );
89  
90          Object aclRequest = null;
91  
92          try
93          {
94              Unmarshaller u = JaxBHelper.createUnmarshaller(  );
95              aclRequest = u.unmarshal( request.getInputStream(  ) );
96          }
97          catch ( Exception e )
98          {
99              throw new CmisInvalidArgumentException( "Invalid ACL request: " + e, e );
100         }
101 
102         if ( !( aclRequest instanceof JAXBElement<?> ) )
103         {
104             throw new CmisInvalidArgumentException( "Not an ACL document!" );
105         }
106 
107         if ( !( ( (JAXBElement<?>) aclRequest ).getValue(  ) instanceof CmisAccessControlListType ) )
108         {
109             throw new CmisInvalidArgumentException( "Not an ACL document!" );
110         }
111 
112         Acl aces = convert( (CmisAccessControlListType) ( (JAXBElement<?>) aclRequest ).getValue(  ), null );
113 
114         
115         Acl acl = service.applyAcl( repositoryId, objectId, aces, aclPropagation );
116 
117         
118         response.setStatus( HttpServletResponse.SC_CREATED );
119         response.setContentType( Constants.MEDIATYPE_ACL );
120 
121         
122         AclDocument aclDocument = new AclDocument(  );
123         aclDocument.writeAcl( acl, response.getOutputStream(  ) );
124     }
125 }