AnsweredAssumed Answered

Person-/Authentication Service - Create User

Question asked by alfrescot3ster on Jun 9, 2015
Hello guys!

I need your help, because I don't know what to do.

I want to create a Person and login with this user via …/api/login.
The problem is, it does not work at all.

public boolean createExtendedPerson(ExtendedPerson person) {
      Map<QName,Serializable> properties = new HashMap<QName,Serializable>();

      properties.put(ContentModel.PROP_USERNAME, person.getUserName());
      properties.put(ContentModel.PROP_PASSWORD, person.getPassword());
      properties.put(ContentModel.PROP_FIRSTNAME, person.getFirstName());
      properties.put(ContentModel.PROP_LASTNAME, person.getLastName());
      properties.put(ContentModel.PROP_EMAIL, person.getEmail());
      properties.put(ContentModel.PROP_TELEPHONE, person.getTelephone());
      properties.put(ContentModel.PROP_COMPANYFAX, person.getCompanyfax());

      
      NodeRef user_nodeRef = personService.createPerson(props);

      return true;
   }


The person exists (node-browser shows me the person with all properties) and all works great, my login works with admin, but not with the self-created person.

The password is stored via ContentModel.PROP_PASSWORD in plain text.

Anyone got an idea? I have found an old solution with 'authenticationService.createAuthentication()', but it's not there anymore.

Other question:
How can I check valid username/password combination in the backend? authenticationService.authentication() would be my choice. Is that right?

#edit

found the solutions, FINALLY:

permissionService.setPermission(user_nodeRef, person.getUserName(), permissionService.getAllPermission(), true);
      
      if(!mutableAuthenticationService.authenticationExists(person.getUserName())){
         mutableAuthenticationService.createAuthentication(person.getUserName(), person.getPassword().toCharArray());
      }

Outcomes