Finaly after reading source code ldap module around four hours i am found this bug.
My settings:
xwiki.authentication.ldap.remoteUserParser=(.+)@(.+)
xwiki.authentication.ldap.remoteUserMapping.1=uid
xwiki.authentication.ldap.remoteUserMapping.2=domain
xwiki.authentication.ldap.userPageName=${domain}-${uid}
xwiki.authentication.ldap.testLoginFor=${uid}@DOMAIN.NAME
LDAP Module start create new user proccess using this line:
userProfile = syncUser(userProfile, searchAttributes, ldapDn, trimedAuthInput, ldapUtils, context);
Its use trimedAuthInput instead of uid.
Two cases:
If user first login via username only (short format) and then second login via username@domain.name (full format) its create only one new user <<<— because first login trimedAuthInput.equals(uid) -> not run TestLoginFor function. Second login via full format !trimedAuthInput.equeals(uid) -> run TestLoginFor function. Found exist user. No create duplicate. ITS FINE.
If user first login via username@domain.name (full format) and then second login via username only (short format) its create two new user (double) <<<— because first login not found via function TestLoginFor(), and create user with trimedAuthInput as uid in full format. second login via short format not start TestLoginFor because trimedAuthInput.equals(uid) -> user not found -> new dupl user create with short uid. ITS BAD
Why not use: userProfile = syncUser(userProfile, searchAttributes, ldapDn, uid, ldapUtils, context); ?
Or maybe remove check for (!trimedAuthInput.equals(uid)):
...
XWikiDocument userProfile = ldapUtils.getUserProfileByUid(validXWikiUserName, trimedAuthInput, context);
if (userProfile == null) {
// Try to search just the UID (in case this user was created before a move to multidomain)
// if (!trimedAuthInput.equals(uid) && getConfiguration().getTestLoginFor().contains(trimedAuthInput)) {
if (getConfiguration().getTestLoginFor().contains(trimedAuthInput)) {
userProfile = ldapUtils.getUserProfileByUid(validXWikiUserName, uid, context);
}
}
Sorry for my Englist. Its not my native.