1

Can someone please explain what is the difference between CreateUser(String) and CreateUser(User,Credential) in confluence. I want to create one user for confluence, if user is not there in the group. There is no information in confluence documentation. :(

I wrote code like this, but not sure whetehr it will accept createUser method twice in same line.

userAccessor.createUser(userAccessor.createUser(username), Credential.encrypted(password));

I am guesing, if inside createUser is executed,then it will throw an exception at outside parent createUser as it is trying to create same user again?

Please give me your thoughts

Thanks Samuel.

samuelebe
  • 149
  • 1
  • 3
  • 15

1 Answers1

0

The new createUser(User, Credential) method replaces the old createUser(String) method, so you should use the former and construct a user with all the details:

User user = userAccessor.createUser(new DefaultUser("mryall", "Matt Ryall", "matt@mattryall.net"),
    Credential.unencrypted("secret"));

The reason for having this API was to reduce the number of calls needed to create a user, and fix the potential race condition where you're creating a user with a username but with otherwise empty fields (name, email, password).

This entire API is very poorly documented. I work on the Confluence team at Atlassian - so mea culpa! We'll try to get this fixed.

Matt Ryall
  • 9,977
  • 5
  • 24
  • 20
  • I have used UserAccessor.addUser(uname, pwd, email, fullname, defaultgroup). It worked. Testing it now. Yeah, good documentation really helps first time users on this. thanks for your response. :) – samuelebe Jun 03 '13 at 20:07
  • Yeah, As you clearly explained in sample code, that internally createuser is taking only User object., Yeah, its working now. – samuelebe Jun 03 '13 at 20:11