Set Permission through REST API

cancel
Showing results for 
Search instead for 
Did you mean: 
dadamia
Active Member

Set Permission through REST API

Dear friends

How can I set permission by using update Node API

Can I Do this directly by HttpClient and HttpPost methods?

PLEASE, can You give me some code example?

Thank You

3 Replies
jayesh_prajapat
Established Member

Re: Set Permission through REST API

Hi


There is similar thread for what you are looking for, check out this link,

 

Hope this will be helpful to you.

fsck_awk
Active Member

Re: Set Permission through REST API

Hello
<shameless plug>
I think you are looking for alfSetPermissions.sh from alfresco-shell-tools

</shameless plug>

dadamia
Active Member

Re: Set Permission through REST API

Dear friends

I solve this problem by via Put Method

NameValuePair nvp = new BasicNameValuePair("include", "premissions");
builder.setScheme("http").setHost("localhost").setPort(8080).setPath("/alfresco/api/-default-/public/alfresco/versions/1/nodes/" + nodeId).setParameters(nvp);
HttpClient httpClient = HttpClientBuilder.create().build();
HttpPut put = new HttpPut(builder.build());

String alfrescoUser = "admin";
String pass = "admin";
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(alfrescoUser, pass);
List<PermissionElementRepresentation> userPermissions = new ArrayList<PermissionElementRepresentation>();
PermissionElementRepresentation newPermission = new PermissionElementRepresentation();
newPermission.setAuthorityId("dato");
newPermission.setName("Read");
newPermission.setAccessStatus(AccessStatusEnum.ALLOWED);
userPermissions.add(newPermission);
PermissionsBodyUpdate permission = new PermissionsBodyUpdate(false, userPermissions);
NodeBodyUpdate permissionRequest = new NodeBodyUpdate(permission);
Gson gson = new Gson();
String jsonInString = gson.toJson(permissionRequest);
StringEntity se;
se = new StringEntity(jsonInString);
put.setEntity(se);
put.setHeader("Accept", "application/json");
put.setHeader("Content-type", "application/json");
put.addHeader(new BasicScheme().authenticate(creds, put, null));
HttpResponse httpResponse = httpClient.execute(put);

Thank you