07-21-2011 01:13 AM
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.alfresco.webservice.administration.NewUserDetails;
import org.alfresco.webservice.administration.AdministrationServiceSoapBindingStub;
import org.alfresco.webservice.types.NamedValue;
import org.alfresco.webservice.types.Store;
import org.alfresco.webservice.util.AuthenticationUtils;
import org.alfresco.webservice.util.Constants;
import org.alfresco.webservice.util.WebServiceFactory;
import org.alfresco.webservice.types.Query;
import org.alfresco.webservice.repository.QueryResult;
/**
*
* @author sundar
*/
public class CreateUserCommand {
public CreateUserCommand() {
}
public static void main(String a[]) {
try {
CreateUserCommand c = new CreateUserCommand();
AuthenticationUtils.startSession("admin", "admin");
// WebServiceFactory.getAdministrationService().changePassword("", "", "");
Store s = new Store(Constants.WORKSPACE_STORE, "Spacesstore");
AdministrationServiceSoapBindingStub ad = WebServiceFactory.getAdministrationService();
String username="sundarpx";
String password="sundarpx";
String firstname="sundar";
String midlename="p";
String lastname="rajan";
String email="sundar.p@demo.com";
String regid="1";
// check the user
boolean existUser = false;
try {
// test before the user
Query query = new Query("lucene", "+TYPE:\"cm:person\" AND +@cm\\:userName:\"" + username + "\"");
QueryResult results = WebServiceFactory.getRepositoryService().query(s, query, true);
if (results != null&&results.getResultSet()!=null) {
if (results.getResultSet().getRows().length > 0) {
existUser = true;
} else {
existUser = false;
}
} else {
existUser = false;
}
} catch (Exception e) {
existUser = false;
}
if(existUser){
System.out.println("This user already exists");
}else{
NamedValue[] properties = c.createUserProperties(s.getScheme() + "://" + s.getAddress() + "/", firstname, midlename, lastname, email, regid);
NewUserDetails dc[] = new NewUserDetails[]{new NewUserDetails(username, password, properties)};
ad.createUsers(dc);
}
AuthenticationUtils.endSession();
} catch (RemoteException ex) {
Logger.getLogger(CreateUserCommand.class.getName()).log(Level.SEVERE, null, ex);
}
}
public NamedValue[] createUserProperties(String homefolder, String firstname, String midlename, String lastname, String email, String orgid) {
return new NamedValue[]{
new NamedValue(Constants.PROP_USER_HOMEFOLDER, false, homefolder, null),
new NamedValue(Constants.PROP_USER_FIRSTNAME, false, firstname, null),
new NamedValue(Constants.PROP_USER_MIDDLENAME, false, midlename, null),
new NamedValue(Constants.PROP_USER_LASTNAME, false, lastname, null),
new NamedValue(Constants.PROP_USER_EMAIL, false, email, null),
new NamedValue(Constants.PROP_USER_ORGID, false, orgid, null)
};
}
}
07-21-2011 05:25 AM
07-21-2011 05:41 AM
07-21-2011 06:31 AM
07-21-2011 07:11 AM
07-21-2011 08:16 AM
07-22-2011 02:59 AM
07-22-2011 03:36 AM
07-22-2011 07:33 AM
07-22-2011 08:05 AM
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.