AnsweredAssumed Answered

Error while Creating users Using Java

Question asked by vamsi25 on Nov 9, 2012
Latest reply on Nov 28, 2012 by nikes
Hi,

ive written a code to create user but iam getting null ptr exception.Below is my code.Please help me where iam going wrong.
Do i need any more configuration to be done.





import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.MutableAuthenticationServiceImpl;
import org.alfresco.repo.security.person.PersonServiceImpl;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.namespace.QName;

import org.alfresco.util.PropertyMap;


public class CreateUserToRepository {

   public CreateUserToRepository() {
   }

   private PersonService personService;
   private MutableAuthenticationService authenticationService;
   

      public void createUser(String userName, String password, String firstName,
         String lastName)  {

      
      
         authenticationService = new MutableAuthenticationServiceImpl();
         
         
         if (this.authenticationService.authenticationExists(userName) == false) {

            this.authenticationService.createAuthentication(userName,
                  password.toCharArray());

            PropertyMap personProps = new PropertyMap();
            personProps.put(ContentModel.PROP_USERNAME, userName);
            personProps.put(ContentModel.PROP_FIRSTNAME, firstName);
            personProps.put(ContentModel.PROP_LASTNAME, lastName);
            personProps.put(ContentModel.PROP_EMAIL, userName
                  + "@localhost.com");
            personProps.put(ContentModel.PROP_JOBTITLE, "myJobTitle");
            personProps.put(ContentModel.PROP_JOBTITLE, "myOrganisation");

            personService = new PersonServiceImpl();
            this.personService.createPerson(personProps);

      }
                  
      
   }
   

}


Outcomes