Changeset 29936

Show
Ignore:
Timestamp:
02/07/08 13:34:29 (2 years ago)
Author:
atchertchian
Message:

NXP-2051: make it possible to query an ldap directory with substring search subfinal or subany (fwd from r29934)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • org.nuxeo.ecm.platform/trunk/nuxeo-platform-directory-ldap/examples/default-ldap-users-directory-bundle.xml

    r26973 r29936  
    6565      <searchScope>onelevel</searchScope> 
    6666 
     67      <!-- using 'subany', search will match *toto*. use 'subfinal' to 
     68        match *toto and 'subinitial' to match toto*. subinitial is the 
     69        default  behaviour--> 
     70      <substringMatchType>subany</substringMatchType> 
     71 
    6772      <readOnly>false</readOnly> 
    6873 
  • org.nuxeo.ecm.platform/trunk/nuxeo-platform-directory-ldap/src/main/java/org/nuxeo/ecm/directory/ldap/LDAPDirectoryDescriptor.java

    r25319 r29936  
    2828 
    2929import org.apache.commons.lang.StringUtils; 
     30import org.apache.commons.logging.Log; 
     31import org.apache.commons.logging.LogFactory; 
    3032import org.nuxeo.common.xmap.annotation.XNode; 
    3133import org.nuxeo.common.xmap.annotation.XNodeList; 
     
    3941public class LDAPDirectoryDescriptor { 
    4042 
     43    public static final Log log = LogFactory.getLog(LDAPDirectoryDescriptor.class); 
     44 
    4145    public static final int defaultSearchScope = SearchControls.ONELEVEL_SCOPE; 
    4246 
     
    7478 
    7579    public int searchScope; 
     80 
     81    public String substringMatchType; 
    7682 
    7783    @XNode("creationBaseDn") 
     
    195201    } 
    196202 
     203    public String getSubstringMatchType() { 
     204        return substringMatchType; 
     205    } 
     206 
     207    @XNode("substringMatchType") 
     208    public void setSubstringMatchType(String substringMatchType) { 
     209        if (substringMatchType == null) { 
     210            // default behaviour 
     211            this.substringMatchType = LDAPSubstringMatchType.SUBINITIAL; 
     212        } else if (LDAPSubstringMatchType.SUBINITIAL.equals(substringMatchType) 
     213                || LDAPSubstringMatchType.SUBFINAL.equals(substringMatchType) 
     214                || LDAPSubstringMatchType.SUBANY.equals(substringMatchType)) { 
     215            this.substringMatchType = substringMatchType; 
     216        } else { 
     217            log.error("Invalid substring match type: " + substringMatchType 
     218                    + ". Valid options: subinitial, subfinal, subany"); 
     219            this.substringMatchType = LDAPSubstringMatchType.SUBINITIAL; 
     220        } 
     221    } 
     222 
    197223    public String getName() { 
    198224        return name; 
  • org.nuxeo.ecm.platform/trunk/nuxeo-platform-directory-ldap/src/main/java/org/nuxeo/ecm/directory/ldap/LDAPSession.java

    r29584 r29936  
    9696    protected final Map<String, Field> schemaFieldMap; 
    9797 
     98    protected final String substringMatchType; 
     99 
    98100    public LDAPSession(LDAPDirectory directory, DirContext dirContext) { 
    99101        this.directory = directory; 
     
    105107        sid = String.valueOf(SIDGenerator.next()); 
    106108        searchBaseDn = directory.getConfig().getSearchBaseDn(); 
     109        substringMatchType = directory.getConfig().getSubstringMatchType(); 
    107110    } 
    108111 
     
    376379            String[] filterArgs = new String[filter.size()]; 
    377380 
     381            if (fulltext == null) { 
     382                fulltext = Collections.emptySet(); 
     383            } 
     384 
    378385            int index = 0; 
    379386            for (String fieldName : filter.keySet()) { 
     
    393400                    currentFilter.append("!(" + backendFieldName + "=*)"); 
    394401                } else if ("".equals(fieldValue)) { 
     402                    if (fulltext.contains(fieldName)) { 
     403                        currentFilter.append(backendFieldName + "=*"); 
     404                    } else { 
     405                        currentFilter.append(backendFieldName + "="); 
     406                    } 
     407                } else { 
    395408                    currentFilter.append(backendFieldName + "="); 
    396                 } else { 
    397                     currentFilter.append(backendFieldName + "={" + index + "}"); 
    398                 } 
    399                 if (fieldValue != null && fulltext.contains(fieldName)) { 
    400                     currentFilter.append("*"); 
     409                    if (fulltext.contains(fieldName)) { 
     410                        if (LDAPSubstringMatchType.SUBFINAL.equals(substringMatchType)) { 
     411                            currentFilter.append("*{" + index + "}"); 
     412                        } else if (LDAPSubstringMatchType.SUBANY.equals(substringMatchType)) { 
     413                            currentFilter.append("*{" + index + "}*"); 
     414                        } else { 
     415                            // default behavior: subinitial 
     416                            currentFilter.append("{" + index + "}*"); 
     417                        } 
     418                    } else { 
     419                        currentFilter.append("{" + index + "}"); 
     420                    } 
    401421                } 
    402422                currentFilter.append(")");