cancel
Showing results for 
Search instead for 
Did you mean: 

How to create users in alfresco...

k4sourabh
Champ in-the-making
Champ in-the-making
1. How to create user in alfresco using Alfresco Java Api or JCR.

2. How to create groups and assign user to a group using Alfresco Java Api or JCR.


PLease reply..

Thanks in advance.
22 REPLIES 22

rivetlogic
Champ on-the-rise
Champ on-the-rise
Hi,

Taking a look at Alfresco source code and the test cases will give a better idea of how to use various API's.

Creating an user.

            HashMap<QName, Serializable> properties = new HashMap<QName, Serializable>();
            properties.put(ContentModel.PROP_USERNAME, "testUser");
            properties.put(ContentModel.PROP_HOMEFOLDER, userNodeRef);
            properties.put(ContentModel.PROP_FIRSTNAME, "Test");
            properties.put(ContentModel.PROP_LASTNAME, "User");
            properties.put(ContentModel.PROP_EMAIL, "testUser@localhost.com");

            personService.createPerson(properties);


userNodeRef is  of type org.alfresco.service.cmr.repository.NodeRef. Other properties are strings.

Creating a group



authorityService.createAuthority(AuthorityType.GROUP, null, "myGroup");


Adding testUser to myGroup


authorityService.addAuthority(authorityService.getName(AuthorityType.GROUP,"myGroup"),"testUser");


Also you could search the forum for "createPerson" , "createAuthority" etc. and find more posts on these topics

Best Regards,
Shagul

k4sourabh
Champ in-the-making
Champ in-the-making
Thanks for the clue.. I am able to create user by following  your instructions..

k4sourabh
Champ in-the-making
Champ in-the-making
Hi,
I am able to create user by using above reference.. But I cannot log in as created user, as the password is not recognized.

can u provide the reference for this.



Thanks in  Advance

k4sourabh
Champ in-the-making
Champ in-the-making
Hi,
i am getting following errors , when i tried to login with the new user created.
I am not getting the way to solve this problem.
Kindly help me out…

javax.faces.FacesException: Error calling action method of component with id loginForm:submit 
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:109)
at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.alfresco.web.app.servlet.AuthenticationFilter.doFilter(AuthenticationFilter.java:94)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
at java.lang.Thread.run(Thread.java:619)
Caused by: javax.faces.el.EvaluationException: Exception while invoking expression #{LoginBean.login}
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:156)
at org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:61)
… 24 more
Caused by: org.alfresco.repo.security.permissions.AccessDeniedException: Access Denied. You do not have the appropriate permissions to perform this operation.
at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:53)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at org.alfresco.repo.audit.AuditComponentImpl.auditImpl(AuditComponentImpl.java:256)
at org.alfresco.repo.audit.AuditComponentImpl.audit(AuditComponentImpl.java:191)
at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:69)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
at $Proxy2.createNode(Unknown Source)
at org.alfresco.web.bean.repository.User.getUserPreferencesRef(User.java:216)
at org.alfresco.web.bean.repository.User.getPreferences(User.java:168)
at org.alfresco.web.bean.repository.PreferencesService.getPreferences(PreferencesService.java:69)
at org.alfresco.web.bean.repository.PreferencesService.getPreferences(PreferencesService.java:60)
at org.alfresco.web.bean.repository.PreferencesService.getPreferences(PreferencesService.java:50)
at org.alfresco.web.bean.UserPreferencesBean.getStartLocation(UserPreferencesBean.java:283)
at org.alfresco.web.bean.LoginBean.login(LoginBean.java:295)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
… 25 more
Caused by: net.sf.acegisecurity.AccessDeniedException: Access is denied.
at net.sf.acegisecurity.vote.AffirmativeBased.decide(AffirmativeBased.java:86)
at net.sf.acegisecurity.intercept.AbstractSecurityInterceptor.beforeInvocation(AbstractSecurityInterceptor.java:394)
at net.sf.acegisecurity.intercept.method.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:77)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:49)
… 46 more

Thanks in Advance…

rivetlogic
Champ on-the-rise
Champ on-the-rise
Hi,

Once the user is created, createAuthentication for the user and also give all permission to the person node.

  //create the node to represent the Person
   NodeRef newPerson = this.personService.createPerson(props);
           
    // ensure the user can access their own Person object
    permissionService.setPermission(newPerson,"testUser", permissionService.getAllPermission(), true);
           
           
   // create the ACEGI Authentication instance for the new user
   authenticationService.createAuthentication("testUser","testUser".toCharArray());
         

Regards,
Shagul

eduandres01
Champ in-the-making
Champ in-the-making
Hi!!
what is the steps before to create the new group, how Authenticate?
thanks!!

witho
Champ on-the-rise
Champ on-the-rise
To create Users you can use an open source project called RAAR (CMA), more information this topic: http://forums.alfresco.com/en/viewtopic.php?f=35&t=14628

I need some help with my code to create Alfresco user. The thing is that I want to create a user indicating its home Folder but when the user is created the user home is empty, here is my code, thanks for any help:


   QName firstNameQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}firstName");
   QName lastNameQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}lastName");
   QName passwordQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}password");
   QName emailQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}email");
   QName homeFolderQName = QName.createQName("{http://www.alfresco.org/model/content/1.0}homeFolder");
      
   Map<QName, Serializable> props = null;
   props = new HashMap<QName, Serializable>(4);
      
   props.put(firstNameQName, firstName);
   props.put(lastNameQName, lastName);
   props.put(passwordQName, passwd);
   props.put(emailQName, email);   
   
   try{      
      configurationApplicationContext=WebApplicationContextUtils.getWebApplicationContext(this.getServlet().getServletContext());
               
      authenticationService = (AuthenticationServiceImpl) configurationApplicationContext.getBean("authenticationService");
      peopleService = (PeopleServiceImpl) configurationApplicationContext.getBean("peopleService");
      nodeService = (NodeServiceImpl) configurationApplicationContext.getBean("nodeService");         
         
      ticket = authenticationService.authenticate(repositoryUri, userid, password.toCharArray());   
         
      [b]NodeRef homeFolder= nodeService.getRootNode(ticket, new StoreRef("workspace://SpacesStore"));[/b]
                     
      props.put(homeFolderQName, homeFolder);
         
      NodeRef userRef = peopleService.createPerson(ticket, userName, passwd.toCharArray(), props);

I want to set the folder "Company Home" as the user folder home, if anyone knows a better way to get the nodeRef of "Company Home" and how to set the property homeFolder as "Company Home" y will apreciate any help.

Thanks!!!

rivetlogic
Champ on-the-rise
Champ on-the-rise
Hello,

You can now find a dedicated thread for RAAr here:
http://forums.alfresco.com/en/viewtopic.php?f=32&t=15360

And a homepage for RAAr here:
http://wiki.rivetlogic.org/display/RAAR/

Cheers.

–Sumer

faisal
Champ in-the-making
Champ in-the-making
Hi

I am new in alfresco. I was trying to create a user in alfresco. I was able to d that following the instruction in the above thread. But the problem is I cannot log in as the new user. But if I log in as admin and change the passwd of the newly created user then log out and try to log in again. It logs me in fine…

Can anybody please tell me Why is it so and if someone can tell me how to fix it that will be really nice

Thanking you in advance

Faisal