cancel
Showing results for 
Search instead for 
Did you mean: 

custom configuration for consumer role to a site

nareshvy
Champ in-the-making
Champ in-the-making

Hi , 

In my site all user require Collaborative role actually its consumer , so i added a configuration like this 

<permissionSet type="st:site" expose="selected">

<permissionGroup name="SiteManager" allowFullControl="true" expose="true" />

<permissionGroup name="SiteCollaborator" allowFullControl="false" expose="true">
<includePermissionGroup permissionGroup="Collaborator" type="cm:cmobject" />
</permissionGroup>

<permissionGroup name="SiteContributor" allowFullControl="false" expose="true">
<includePermissionGroup permissionGroup="Contributor" type="cm:cmobject" />
</permissionGroup>

<permissionGroup name="SiteConsumer" allowFullControl="false" expose="true">
<includePermissionGroup permissionGroup="Collaborator" type="cm:cmobject" />
</permissionGroup>

<permissionGroup name="SiteCommentator" allowFullControl="false" expose="true">
<includePermissionGroup permissionGroup="Consumer" type="cm:cmobject" />
<includePermissionGroup permissionGroup="ReadPermissions" type="sys:base" />
</permissionGroup>

</permissionSet>

in  alfresco-community\tomcat\shared\classes\alfresco\extension\sitePermissionDefinitions.xml

but its still access denied for some operations.

or if there is any other way, please let me know with sample codes

Thank you

23 REPLIES 23

kaynezhang
World-Class Innovator
World-Class Innovator

Your sitePermissionDefinitions.xml is not an invalid xml file

Caused by: org.dom4j.DocumentException: Error on line 6 of document : Invalid byte 1 of 1-byte UTF-8 sequence. Nested exception: Invalid byte 1 of 1-byte UTF-8 sequence.

nareshvy
Champ in-the-making
Champ in-the-making

Thank you I fixed the issue...

please provide sample code for create a group and assign user to the group using java related

kaynezhang
World-Class Innovator
World-Class Innovator

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.json.JSONObject;

public static void main(String[] args) {
WebScriptExample exmple = new WebScriptExample();
HttpClient client = exmple.getHttpClient();

exmple.addGroupOrUserToGroup(client);
}

private void addGroupOrUserToGroup(HttpClient client) {
String apiurl ="http://localhost:8080/alfresco/s/api/groups/{parent group name}/children/{user name or sub group name}";
PostMethod post = new PostMethod(apiurl);
try {

post.setDoAuthentication(true);
post.setRequestHeader("Content-Type", "application/json");

int status = client.executeMethod(post);
if (status != HttpStatus.SC_OK) {
System.err.println("Method failed: " + post.getStatusLine());
}
String resultString = post.getResponseBodyAsString();
System.out.println(resultString);
} catch (Exception e) {
e.printStackTrace();
} finally {
post.releaseConnection();
}
}


private HttpClient getHttpClient() {
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("localhost", 8080, "Alfresco"),
new UsernamePasswordCredentials("admin", "admin"));
return client;
}

Please note that if add sub group ,it's name should be prefix with GROUP_

for example add a sub group named subGroup1 to parent group named parentGroup,you url should be 

String apiurl ="http://localhost:8080/alfresco/s/api/groups/parentGroup/children/GROUP_subGroup1 ";

nareshvy
Champ in-the-making
Champ in-the-making

Thank you,I am trying  this example, but i got this errors

Method failed: HTTP/1.1 405 Method Not Allowed

Web Script Status 405 - Method Not Allowed

Script url /api/groups/CBGroupTest does not support the method POST

the url: String apiurl = "http://127.0.0.1:8090/alfresco/s/api/groups/CBGroupTest";

I gave like this.

kaynezhang
World-Class Innovator
World-Class Innovator

Your url is not complete :

if you want to add an user to group CBGroupTest,the url should be like this

String apiurl = "http://127.0.0.1:8090/alfresco/s/api/groups/CBGroupTest/children/{userName}";

if you want to add an subgroup to group CBGroupTest,the url should be like this

String apiurl = "http://127.0.0.1:8090/alfresco/s/api/groups/CBGroupTest/children/{GROUP_groupName}";

nareshvy
Champ in-the-making
Champ in-the-making

thank you kayne,

I trying to create group ,once then later while creating user i have to add user to group , this is my scenario,

now i am trying to create group.

String apiurl = "http://127.0.0.1:8090/alfresco/s/api/groups/CBGroupTest/children/Group_CBGroupTest";

right now no user to that group

so its getting error 

"The group :CBGroupTest, does not exist.

kaynezhang
World-Class Innovator
World-Class Innovator

If you want to add sub group(CBGroupTest) to a parent group (CBGroupTest) , parent group CBGroupTest should exist.

Ifyou want to add root group please use 

   String apiurl ="http://localhost:8090/alfresco/s/api/rootgroups/{your root group name}";

nareshvy
Champ in-the-making
Champ in-the-making

thank you kayne

getting error

private void addGroupOrUserToGroup(HttpClient client) throws JSONException {
String apiurl = "http://127.0.0.1:8090/alfresco/s/api/rootgroups/CBGroup";
PostMethod post = new PostMethod(apiurl);
try {
post.setDoAuthentication(true);
post.setRequestHeader("Content-Type", "application/json");
int status = client.executeMethod(post);
if (status != HttpStatus.SC_OK) {
System.err.println("Method failed: " + post.getStatusLine());
}
String resultString = post.getResponseBodyAsString();
System.out.println(resultString);
} catch (Exception e) {
e.printStackTrace();
} finally {
post.releaseConnection();
}
}

"status" :
{
code" : 500,
"name" : "Internal Error",
"description" : "An error inside the HTTP server which prevented it from fulfilling the request."
},

kaynezhang
World-Class Innovator
World-Class Innovator

Try to add following line in bold to your code

private void addGroupOrUserToGroup(HttpClient client) throws JSONException {
String apiurl = "http://127.0.0.1:8090/alfresco/s/api/rootgroups/CBGroup";
PostMethod post = new PostMethod(apiurl);
try {
JSONObject body = new JSONObject();
body.put("displayName", "CBGroup");

post.setDoAuthentication(true);
post.setRequestHeader("Content-Type", "application/json");
post.setRequestEntity(new StringRequestEntity(body.toString(),"application/json", "UTF-8"));
int status = client.executeMethod(post);
if (status != HttpStatus.SC_OK) {
System.err.println("Method failed: " + post.getStatusLine());
}
String resultString = post.getResponseBodyAsString();
System.out.println(resultString);
} catch (Exception e) {
e.printStackTrace();
} finally {
post.releaseConnection();
}
}

nareshvy
Champ in-the-making
Champ in-the-making

Thank You Very Much, Kayne