문제

I build web applications using alfresco-community-4.0.e, OpenCMIS, and primefaces as user interface.

I need to create users in alfresco programmatically. I tried to create a user using the following code:

Blockquote 
if (!personService.personExists("tuser1")) {
        personService.createPerson(createDefaultProperties("tuser1", "Test", "User1", "tuser1@localhost", "password"));
        if (logger.isDebugEnabled()) logger.debug("Created tuser1 person");
    }

    if (!personService.personExists("tuser1")) {
        personService.createPerson(createDefaultProperties("tuser1", "Test", "User1", "tuser1@localhost", "password"));
        if (logger.isDebugEnabled()) logger.debug("Created tuser1 person");
    } 

Blockquote

But I am facing problem with the authentication.

I made a class for alfresco authentication that throws the openCMIS and it works fine for creating my custom content and some other custom actions.

Any idea why it is now working with creating user or any other code to build the user programmatically?

도움이 되었습니까?

해결책

Your code is almost there, but missing one crucial line. As well as creating the person, you also need to create the associated Authentication for them

You probably want something like

if (this.authenticationService.authenticationExists(userName) == false)
{
   this.authenticationService.createAuthentication(userName, password.toCharArray());

   PropertyMap ppOne = new PropertyMap(4);
   ppOne.put(ContentModel.PROP_USERNAME, userName);
   ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
   ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
   ppOne.put(ContentModel.PROP_EMAIL, userName+"@example.com");
   ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");

   this.personService.createPerson(ppOne);
}        
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top