01-28-2010 06:01 AM
01-29-2010 01:31 AM
/**
* This method creates a group authority in the authority parent of Alfresco.
* @param name: The new user's name
* @param parent a Valid Group's name you have to concat a group prefix: "GROUP_"
*/
public void addUser(String name, String parent) {
AccessControlServiceSoapBindingStub accessControlService = WebServiceFactory.getAccessControlService();
try {
String[] result = accessControlService.addChildAuthorities(parent, new String[]{name});
for (String string : result) {
System.out.println("User added: "+ string);
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
01-29-2010 06:16 AM
01-29-2010 11:18 AM
Thanks mdavid.cu !
But i want to create a group which can read all contents node only,but no administrator right.Still don't know how to grant permission to group.And i search throught internet,it seems no such WS api doing that.
package org.my.self.test;
import java.rmi.RemoteException;
import org.alfresco.webservice.accesscontrol.ACE;
import org.alfresco.webservice.accesscontrol.ACL;
import org.alfresco.webservice.accesscontrol.AccessControlFault;
import org.alfresco.webservice.accesscontrol.AccessControlServiceSoapBindingStub;
import org.alfresco.webservice.accesscontrol.AccessStatus;
import org.alfresco.webservice.accesscontrol.NewAuthority;
import org.alfresco.webservice.authentication.AuthenticationFault;
import org.alfresco.webservice.types.Predicate;
import org.alfresco.webservice.types.Reference;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.WebServiceFactory;
public class RoleAssigment {
/**
* This method creates a group authority in the authority root of Alfresco.
*
* @param name
* :The group's name
*/
public void createGroup(String name) {
AccessControlServiceSoapBindingStub accessControlService = WebServiceFactory
.getAccessControlService();
NewAuthority authority = new NewAuthority("GROUP", name);
try {
String[] result = accessControlService.createAuthorities(null,
new NewAuthority[] { authority });
for (String string : result) {
System.out.println("Created group: " + string);
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
public void createAssigment(String grupName, String permission,
String pathTo) {
Predicate predicate = new Predicate(new Reference[] { new Reference(
new Store("workspace", "SpacesStore"), null, pathTo) }, null,
null);
AccessControlServiceSoapBindingStub accessControlService = WebServiceFactory
.getAccessControlService();
try {
accessControlService.addACEs(predicate, new ACE[] { new ACE(
grupName, permission, AccessStatus.acepted) });
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
final String repositoryPath = "http://10.7.16.199:8080/alfresco/api";
final String userName = "mdavid";
final String passwd = "xxxxxxxxx";
RoleAssigment roleAssigment = new RoleAssigment();
WebServiceFactory.setEndpointAddress(repositoryPath);
AuthenticationUtils.startSession(userName, passwd);
roleAssigment.createGroup("NODE_READER_ONLY");
roleAssigment.createAssigment("GROUP_NODE_READER_ONLY", "Read", "/app:company_home");
System.out.println("Task Completed !!!");
} catch (AuthenticationFault e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
AuthenticationUtils.endSession();
}
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.