[xwiki-users] Authentication using LDAP and user names with dots

Eric ter Haar eric.ter.haar at altium.nl
Tue Jul 31 11:50:13 CEST 2007


Erin Schnabel wrote:
> On 7/30/07, Guillaume Lerouge <guillaume at xwiki.com> wrote:
>> Hi Eric,
>>
> 
> [snip..]
> 
>> On the other hand, XWiki Users are currently created in the XWiki space.
>> Your users are not created in that space because of the dots. One solution I
>> could see (though I'm definitely not on the tech side of things) would be to
>> write some kind of filter / adapter that would take the dots out of user
>> names before creating them (replacing eric.ter.haar with EricTerHaar) and
>> using that username for XWiki.
>>
>> Not sure this helps a lot, but good luck!
>>
> 
> I found (in my travails over the weekend) this handy code in
> com.xpn.xwiki.XWiki:
> 
>     public String getConvertingUserNameType(XWikiContext context)
>     {
>         if (context.getWiki().getXWikiPreference("convertmail", context) != null
>             && context.getWiki().getXWikiPreference("convertmail",
> context).length() > 0)
>             return context.getWiki().getXWikiPreference("convertmail",
> "0", context);
>         return context.getWiki().Param("xwiki.authentication.convertemail",
> "0");
>     }
> 
>     public String convertUsername(String username, XWikiContext context)
>     {
>         if (username == null)
>             return null;
>         if (getConvertingUserNameType(context).equals("1") &&
> (username.indexOf("@") != -1)) {
>             String id = "" + username.hashCode();
>             id = id.replaceAll("-", "");
>             if (username.length() > 1) {
>                 int i1 = username.indexOf('@');
>                 id =
>                     "" + username.charAt(0) + username.substring(i1 + 1, i1 + 2)
>                         + username.charAt(username.length() - 1) + id;
>             }
>             return id;
>         } else if (getConvertingUserNameType(context).equals("2"))
>             return username.replaceAll("[\\.\\@]", "_");
>         else
>             return username;
>     }
> 
> In theory, you could use this instead of rolling your own. Both of
> those are for converting
> email addresses.. but the second would replace either dots or @ with _...
> 
> if the converting type is 1: strip the username from in front of the @ sign
> if the converting type is 2: just replace @ and . with _
> 
> at least, that's how I read the code..
> 
> 
> convertUsername is already called by processLogin, checkLogin,
> getUserPage, inviteToGroup, and validateUser, so (in theory) you
> shouldn't even have to hack code to get this to work -- just set the
> right value in xwiki.cfg.
> 
> 

Thanks Erin, "xwiki.authentication.convertemail=2" did the trick!

--
Best regards,
Eric




More information about the users mailing list