I’m working on a migration form an old wiki system to xwiki.
In xwiki a username cannot contain a dot.
But in the wiki system that I try to migrate, there are some usernames containing a dot.
Is there a reason xwiki doesn’t let a user using a dot in the username?
Is there a way to disable this restriction?
See Loading.... It used to be a technical limitation with page names (user ids are page names) which should be mostly resolved now. The only potential remaining problem is lazy code assuming that a user id never contains a dot since it’s been like this for a very long time.
which regex library are you guys using? I tried the following regex, which works in an online validator but I’m getting an MalFormedPerl5PatternException:
^[a-zA-Z0-9_\-\.]+$
Invalid regular expression for xwiki.validusername
org.apache.oro.text.perl.MalformedPerl5PatternException: Invalid expression: ^[a-zA-Z0-9_\-\.]+$
at org.apache.oro.text.perl.Perl5Util.__parseMatchExpression(Unknown Source)
at org.apache.oro.text.perl.Perl5Util.match(Unknown Source)
at org.apache.oro.text.perl.Perl5Util.match(Unknown Source)
at com.xpn.xwiki.util.Util.match(Util.java:97)
at com.xpn.xwiki.XWiki.createUser(XWiki.java:3921)
at com.xpn.xwiki.api.XWiki.createUser(XWiki.java:1538)
at com.xpn.xwiki.api.XWiki.createUser(XWiki.java:1502)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Hmm no idea why this code uses Perl5Util, it’s not like XWiki was older than standard Java Pattern. Should probably be changed.
To answer your question the name seems to suggest you should use perl regex syntax. The exact library seems to be Jakarta ORO - Jakarta ORO and the first line in that website comfort me in the idea to get rid of this…
So I think I figured out why it is not working.
I’m able to login if the username contains a dash but not if it contains a dot.
I think the problem is that dot’s are used to separate spaces from pages in the xwiki API.
I think the following code explains it:
I don’t know if it’s the only problem but yes you did guess right. That’s part of the “lazy code assuming that a user id never contains a dot since it’s been like this for a very long time” I was referring to.
There is actually two problems here:
the code assume that if there is a dot then it’s a complete reference and not a user id
concatenation is a very bad way to create a reference from escaping point of view, it should user something like new LocalDocumentReference("XWiki", username) to pass to getDocument.
If you feel like working on this a possibility which should be safe from retro compatibility point of view would be to keep the current code but if userDocument.isNew() is true (meaning the document does not exist) then also try in the “XWiki” space (if it’s not what we already tried of course).