Issue Details (XML | Word | Printable)

Key: XWIKI-2495
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Thomas Mortagne
Reporter: Denis Gervalle
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
XWiki Core

LDAP Authentication re-create global user locally

Created: 23/Jun/08 13:03   Updated: 03/Jul/08 15:40
Component/s: Auth Service - LDAP
Affects Version/s: 1.5 M1, 1.4.1
Fix Version/s: 1.5 RC1

File Attachments: 1. Text File ldap-1.4.1-local-global-auth.patch (20 kB)
2. Text File ldap-1.5M2-fix1-local-global-auth.patch (21 kB)
3. Text File ldap-1.5M2-local-global-auth.patch (21 kB)

Issue Links:
Dependency
 

keywords: ldap,group,user,patch,bugfixingday
Date of First Response: 26/Jun/08 15:07
Resolution Date: 03/Jul/08 15:36
Tests: Integration


 Description  « Hide
When a global user logs in locally, a new local user is created instead of updating the global user which has rights to the local xwiki. This seems to be related to the way findUser() search for existing user only the local database.

Moreover, restriction based on ldap.user_group applied locally, require global user to be also member of the locally defined ldap group to be able to log in. Do not know if this intended or not, but I do not feel this to be very practical since the only way I have got to avoid local user to login globally and create a user globally, is by restricting global and local login to different ldap group.



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Denis Gervalle added a comment - 26/Jun/08 14:23
Patch for appropriate two pass ldap authentication against local ldap config then main global wiki ldap config. This patch is for release 1.4.1

Denis Gervalle added a comment - 26/Jun/08 14:24
Patch for appropriate two pass ldap authentication against local ldap config then main global wiki ldap config. This patch is for release 1.5M2

Denis Gervalle added a comment - 26/Jun/08 14:55
The patch proposal has been prepared in collaboration with Thomas Mortagne for the technical approach that may be taken.

What is proposed is to use the same two pass authentication that is done in the original XWiki authentication against its DB, to the LDAP authentication. Therefore LDAP authentication is done that way:

  • Try current wiki ldap authentication
  • if failed, and not in Main Wiki, try ldap authentication based on the main wiki ldap config
  • if failed and try_local is enable, try local wiki DB and main wiki DB

This model has the advantage to be simple to understand and generic like the original authentication against xwiki DB. It has one drawback, the first matching ldap authentication will drive the creation of the user in the xwiki DB. Therefore, to avoind duplicating main xwiki users into local xwiki DB, it is important that main xwiki users failed to authenticate using the local xwiki ldap authentication, do that fallback to main ldap xwiki authentication occurs.

To help achieving this goal, the patch introduce an additional group filter, that worked as an exclusion group:

In xwiki.cfg: xwiki.authentication.ldap.exclude_group=groupDN
In WebPreferences: ldap_exclude_group=groupDN (This field should be added to the XWikiPreferences class)

When user pass the user_group filter successfully (if available), it is that check against the exclude_group and if a match is found, authentication failed.


Thomas Mortagne added a comment - 26/Jun/08 15:07
Thanks for the patch, I will review it and find some automated tests to write to validate this when I have time (at worst next Wednesday during the bugfixing day)

Thomas Mortagne added a comment - 01/Jul/08 11:50 - edited
Some comment:
  • in XWikiLDAPUtils#isUserInGroup :
    • you removed the complete Map<String, String> for Map
    • the debug log "Found user dn in user group:" + userDN is called even returned userDN is null (meaning not found in the group)
  • in XWikiLDAPAuthServiceImpl:
    • in #authenticate
      • possible null pointer exception:
        if (context != null) {
        [...]
        } else {
          context.put("message", "loginfailed");
          return null;
        }
        

        If the context is null you will get a NullPointer exception and anyway context should never be null so best is to remove this test as it was IMO (the default authenticator is old and maybe somewhere far in the past the context could be null )

      • you should not remove spaces from user name, it makes impossible to log in LDAP with user containing space so it's a regression.
    • if LDAP login fail and trylocal=0, no error message are stored in the context (which makes XWiki.XWikiLogin reloading without saying anything) or even logged

To summarize:

  • I don't agree with your copy/past from standard XWikiAuthServiceImpl (which contains old and sometimes wrong code). I think you should take the current XWikiLDAPAuthServiceImpl#authenticate and fix/change only what to be fixed for XWIKI-2495 and XWIKI-2515. Fix the empty user/password which does not print error in XWiki.XWikiLogin should be another jira issue and ideally a different patch.
  • Except for this all seems ok to me as first look.

Thomas Mortagne added a comment - 01/Jul/08 11:51
(I only looked at 1.5 branch patch)

Denis Gervalle added a comment - 02/Jul/08 23:45
Thanks for your detailed review, here is my comments:
  • In XWikiLDAPUtils#isUserInGroup
  • Sorry for the Map, it was a regression I have overlooked from 1.4.1 - FIXED
  • I have removed the debug log here because the caller better know what to say since this check is now used for exclude group as well, and since there is only one caller which also do its debug log, the debug message seems to me redundant and confusing when called for exclusion.
  • In XWikiLDAPAuthServiceImpl
  • in #authenticate
  • I have removed the check of a null context has you suggest, but it would be nice to also remove this from XwikiAuthServiceImpl - see below as well
  • You may have notice the comment and the FIXME, that said that the intended purpose was to remove space before and after the username, and my feel that it does more then that. I understand that you see it as a regression, so I have fix it has well, replacing replace by trim
  • if LDAP fail, trylocal=0 and warn logging is not enabled or ldap failed with exception, existing code does not store a message in the context, so this is a separate issue, I feel that my regression is more consistant, since having side effect from logging is very poor.

To summarize:

  • Until the standard, old, but not so poor original code is not improved, I feel that proposing something similar, with an initial cleaning phase, then a true authentication one, will help moving the cleaning phase upper, and simplify the whole thing at the end, since cleaning is redundant actually. This is a first step in that direction, maybe I will code the rest later, but you need to accept this patch first
  • Regarding the proper message reporting, I suggest that you open a new issue to improve that point, I do not see my patch as a regression.

In the hope that you agree, here is my fixed patch.


Thomas Mortagne added a comment - 03/Jul/08 11:34
  • I'm not sure about the trim, LDAP can't contains uid with spaces before and after ?

The general problem is that it's difficult to apply a patch doing so many modifications not related with the issue. I don't speaking about improvement or not, simply this patch change behaviors from user point of view that is not referenced anywhere. What you did specifically for XWIKI-2495 and XWIKI-2515 seems perfect to me.


Thomas Mortagne added a comment - 03/Jul/08 15:36
Applied patch from Denis Gervalle with some minor modifications.
Thanks