cancel
Showing results for 
Search instead for 
Did you mean: 

how can i set admin role for new user

arun_sira
Champ in-the-making
Champ in-the-making
Hi all,

i have created new user as guest in alfresco from my code. But i cont able to create user with admin Role, can you please give coding to create user with admin functionality

My mail id: arun_sira@hotmail.com

My Code:







<%


String username ="newuser1";
String password ="newuser1";
String oldusername ="admin";
String oldpassword="admin";
ArrayList datalist=new ArrayList();


username = request.getParameter("username");
password = request.getParameter("password");


// form.setPassword(password);
// form.setConfirm(password);

NewUserWizard newuserobject=new NewUserWizard();

/** AuthenticationService bean reference */
AuthenticationService authenticationService = null;
AuthenticationService authenticationServicenew = null;

/** NodeService bean reference */
NodeService nodeService = null;

FacesContext context = FacesContext.getCurrentInstance();
nodeService = Repository.getServiceRegistry(context).getNodeService();


WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

// get individual, required services


UserTransaction tx ;
//nodeService = (NodeService)serviceRegistry.getNodeService();
tx = serviceRegistry.getTransactionService().getUserTransaction();
tx.begin();

authenticationService=(AuthenticationService)ctx.getBean("authenticationService");
PersonService personService = (PersonService)ctx.getBean("personService");



try {

//logout first
//FacesContext context = FacesContext.getCurrentInstance();

// invalidate User ticket
User user = (User)session.getValue(AuthenticationHelper.AUTHENTICATION_USER);
if (user != null)
{
authenticationService.invalidateTicket(user.getTicket());

Enumeration em= session.getAttributeNames();
while(em.hasMoreElements()) {
String name=(String)em.nextElement();
session.removeAttribute(name);
}

}


authenticationService.authenticate(oldusername,oldpassword.toCharArray());

// setup User object and Home space ID

user = new User(authenticationService.getCurrentUserName(),authenticationService.getCurrentTicket(),personService.getPerson(oldusername));

String homeSpaceId = null;


//nothing but workspace guid


homeSpaceId ="de61ef7a-0ab9-11dc-a5ea-7b72135c349f";




// set the current user workspace

user.setHomeSpaceId(homeSpaceId);



//inintialize the authentication session

session.putValue(AuthenticationHelper.AUTHENTICATION_USER, user);

//get the noderep object form Noderef bean

NodeRef homeSpaceRef = new NodeRef(Repository.getStoreRef(), homeSpaceId);

String homeSpaceName = Repository.getNameForNode((NodeService)serviceRegistry.getNodeService(), homeSpaceRef);

authenticationServicenew=(AuthenticationService)ctx.getBean("authenticationService");

authenticationServicenew.createAuthentication(username,password.toCharArray());
System.out.println("after creating user " );





PermissionService permissionService = (PermissionService) ctx.getBean("permissionService");
permissionService.setPermission(homeSpaceRef, permissionService.getAllAuthorities(),PermissionService.ALL_PERMISSIONS, true);




authenticationService.authenticate(username, password.toCharArray());

// setup User object and Home space ID
user = new User(authenticationService.getCurrentUserName(), authenticationService.getCurrentTicket(),personService.getPerson(username));

homeSpaceId = null;


//nothing but workspace guid ,person



homeSpaceId ="de61ef7a-0ab9-11dc-a5ea-7b72135c349f";




// set the current user workspace

user.setHomeSpaceId(homeSpaceId);



//inintialize the authentication session

session.putValue(AuthenticationHelper.AUTHENTICATION_USER, user);

//get the noderep object form Noderef bean

NodeRef homeSpaceRef1 = new NodeRef(Repository.getStoreRef(), homeSpaceId);
homeSpaceName = Repository.getNameForNode((NodeService)serviceRegistry.getNodeService(), homeSpaceRef1);
// PermissionService.inheritPermissions(homeSpaceRef,homeSpaceRef1);

response.sendRedirect(request.getContextPath() +"/auto.jsp?eu="+username+"&dp="+password);
} catch (Exception ex) {
// System.out.println("something is error." + ex.getMessage());
//response.sendRedirect( request.getContextPath() +"OpenSesami/Dashboard.jsp");
out.println("something is error." + ex.getMessage());
// username="admin";
// password="admin";
// response.sendRedirect(request.getContextPath() +"/auto.jsp?username="+username+"&password="+password);
// response.sendRedirect(request.getContextPath() +"/auto.jsp?eu="+username+"&dp="+password);
//ex.printStackTrace();
}


%>
3 REPLIES 3

jonas
Champ in-the-making
Champ in-the-making
Hi,

You can not create user with admin Role. But you can do it in xml config  file.

Here is an example

<property name="adminUsers">
            <set>
             <value>admin</value>
             <value>administrator</value>
             <value>cdadmin</value>
          </set>
        </property>

arun_sira
Champ in-the-making
Champ in-the-making
Hi
        I update in XML file. but i cont able to create user with admin role.
can you please give breif. how can i achive my goal

janvg
Champ in-the-making
Champ in-the-making
Hi,

We want to create a new role "group administrator" giving members of this role the possibility to manage groups without managing users (create/delete)

We would only sync our users from the LDAP and keep the groupmanagement as a delegated admin in Alfresco.

Can this be done ? Are there better ways to achieve this ?

We would also like to synchronise "user-title" from our LDAP. And then we would like to create groups based on title (ex. staffmember) How can we do this ?

thx