cancel
Showing results for 
Search instead for 
Did you mean: 

Set Permission through REST API

dadamia
Champ on-the-rise
Champ on-the-rise

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 3

jayesh_prajapat
Star Contributor
Star Contributor

Hi


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

 

Hope this will be helpful to you.

fsck_awk
Champ on-the-rise
Champ on-the-rise

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

</shameless plug>

dadamia
Champ on-the-rise
Champ on-the-rise

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