@Test public void testQueryEmptyString() throws Exception { Session session = getLDAPDirectory("userDirectory").getSession(); Map<String, Serializable> filter = new HashMap<String, Serializable>(); filter.put("cn", ""); List<DocumentModel> docs = session.query(filter); assertNotNull(docs); }
public DocumentModelList query(Map<String, Serializable> filter, Set<String> fulltext, boolean fetchReferences, Map<String, String> orderBy) throws DirectoryException { try { String[] filters = new String[filter.size()]; String[] filterArgs = new String[filter.size()]; if (fulltext == null) { fulltext = Collections.emptySet(); } int index = 0; for (String fieldName : filter.keySet()) { if (directory.isReference(fieldName)) { log.warn(fieldName + " is a reference and will be ignored as a query criterion"); continue; } String backendFieldName = directory.getFieldMapper().getBackendField( fieldName); Object fieldValue = filter.get(fieldName); StringBuilder currentFilter = new StringBuilder(); currentFilter.append("("); if (fieldValue == null) { currentFilter.append("!(" + backendFieldName + "=*)"); } else if ("".equals(fieldValue)) { if (fulltext.contains(fieldName)) { currentFilter.append(backendFieldName + "=*"); } else { currentFilter.append("!(" + backendFieldName + "=*)"); } } else { currentFilter.append(backendFieldName + "="); if (fulltext.contains(fieldName)) { if (LDAPSubstringMatchType.SUBFINAL.equals(substringMatchType)) { currentFilter.append("*{" + index + "}"); } else if (LDAPSubstringMatchType.SUBANY.equals(substringMatchType)) { currentFilter.append("*{" + index + "}*"); } else { currentFilter.append("{" + index + "}*"); } } else { currentFilter.append("{" + index + "}"); } } currentFilter.append(")"); filters[index] = currentFilter.toString(); if (fieldValue != null && !"".equals(fieldValue)) { if (fieldValue instanceof Blob) { log.warn("Binary search is not supported"); } else { filterArgs[index] = fieldValue.toString(); } } index++; } String filterExpr = "(&" + directory.getBaseFilter() + StringUtils.join(filters) + ')'; SearchControls scts = directory.getSearchControls(); if (log.isDebugEnabled()) { log.debug(String.format( "LDAPSession.query(...): LDAP search base='%s' filter='%s' args='%s' scope='%s' [%s]", searchBaseDn, filterExpr, StringUtils.join(filterArgs, ","), scts.getSearchScope(), this)); } try { NamingEnumeration<SearchResult> results = dirContext.search( searchBaseDn, filterExpr, filterArgs, scts); DocumentModelList entries = ldapResultsToDocumentModels( results, fetchReferences); if (orderBy != null && !orderBy.isEmpty()) { directory.orderEntries(entries, orderBy); } return entries; } catch (NameNotFoundException nnfe) { log.error( "Unexpected response from server while performing query: " + nnfe.getMessage(), nnfe); return new DocumentModelListImpl(); } } catch (LimitExceededException e) { throw new org.nuxeo.ecm.directory.SizeLimitExceededException(e); } catch (NamingException e) { throw new DirectoryException("executeQuery failed", e); } }
LDAPSession extends BaseSession implements EntrySource { public DocumentModelList query(Map<String, Serializable> filter, Set<String> fulltext, boolean fetchReferences, Map<String, String> orderBy) throws DirectoryException { try { String[] filters = new String[filter.size()]; String[] filterArgs = new String[filter.size()]; if (fulltext == null) { fulltext = Collections.emptySet(); } int index = 0; for (String fieldName : filter.keySet()) { if (directory.isReference(fieldName)) { log.warn(fieldName + " is a reference and will be ignored as a query criterion"); continue; } String backendFieldName = directory.getFieldMapper().getBackendField( fieldName); Object fieldValue = filter.get(fieldName); StringBuilder currentFilter = new StringBuilder(); currentFilter.append("("); if (fieldValue == null) { currentFilter.append("!(" + backendFieldName + "=*)"); } else if ("".equals(fieldValue)) { if (fulltext.contains(fieldName)) { currentFilter.append(backendFieldName + "=*"); } else { currentFilter.append("!(" + backendFieldName + "=*)"); } } else { currentFilter.append(backendFieldName + "="); if (fulltext.contains(fieldName)) { if (LDAPSubstringMatchType.SUBFINAL.equals(substringMatchType)) { currentFilter.append("*{" + index + "}"); } else if (LDAPSubstringMatchType.SUBANY.equals(substringMatchType)) { currentFilter.append("*{" + index + "}*"); } else { currentFilter.append("{" + index + "}*"); } } else { currentFilter.append("{" + index + "}"); } } currentFilter.append(")"); filters[index] = currentFilter.toString(); if (fieldValue != null && !"".equals(fieldValue)) { if (fieldValue instanceof Blob) { log.warn("Binary search is not supported"); } else { filterArgs[index] = fieldValue.toString(); } } index++; } String filterExpr = "(&" + directory.getBaseFilter() + StringUtils.join(filters) + ')'; SearchControls scts = directory.getSearchControls(); if (log.isDebugEnabled()) { log.debug(String.format( "LDAPSession.query(...): LDAP search base='%s' filter='%s' args='%s' scope='%s' [%s]", searchBaseDn, filterExpr, StringUtils.join(filterArgs, ","), scts.getSearchScope(), this)); } try { NamingEnumeration<SearchResult> results = dirContext.search( searchBaseDn, filterExpr, filterArgs, scts); DocumentModelList entries = ldapResultsToDocumentModels( results, fetchReferences); if (orderBy != null && !orderBy.isEmpty()) { directory.orderEntries(entries, orderBy); } return entries; } catch (NameNotFoundException nnfe) { log.error( "Unexpected response from server while performing query: " + nnfe.getMessage(), nnfe); return new DocumentModelListImpl(); } } catch (LimitExceededException e) { throw new org.nuxeo.ecm.directory.SizeLimitExceededException(e); } catch (NamingException e) { throw new DirectoryException("executeQuery failed", e); } } }
LDAPSession extends BaseSession implements EntrySource { public DocumentModelList query(Map<String, Serializable> filter, Set<String> fulltext, boolean fetchReferences, Map<String, String> orderBy) throws DirectoryException { try { String[] filters = new String[filter.size()]; String[] filterArgs = new String[filter.size()]; if (fulltext == null) { fulltext = Collections.emptySet(); } int index = 0; for (String fieldName : filter.keySet()) { if (directory.isReference(fieldName)) { log.warn(fieldName + " is a reference and will be ignored as a query criterion"); continue; } String backendFieldName = directory.getFieldMapper().getBackendField( fieldName); Object fieldValue = filter.get(fieldName); StringBuilder currentFilter = new StringBuilder(); currentFilter.append("("); if (fieldValue == null) { currentFilter.append("!(" + backendFieldName + "=*)"); } else if ("".equals(fieldValue)) { if (fulltext.contains(fieldName)) { currentFilter.append(backendFieldName + "=*"); } else { currentFilter.append("!(" + backendFieldName + "=*)"); } } else { currentFilter.append(backendFieldName + "="); if (fulltext.contains(fieldName)) { if (LDAPSubstringMatchType.SUBFINAL.equals(substringMatchType)) { currentFilter.append("*{" + index + "}"); } else if (LDAPSubstringMatchType.SUBANY.equals(substringMatchType)) { currentFilter.append("*{" + index + "}*"); } else { currentFilter.append("{" + index + "}*"); } } else { currentFilter.append("{" + index + "}"); } } currentFilter.append(")"); filters[index] = currentFilter.toString(); if (fieldValue != null && !"".equals(fieldValue)) { if (fieldValue instanceof Blob) { log.warn("Binary search is not supported"); } else { filterArgs[index] = fieldValue.toString(); } } index++; } String filterExpr = "(&" + directory.getBaseFilter() + StringUtils.join(filters) + ')'; SearchControls scts = directory.getSearchControls(); if (log.isDebugEnabled()) { log.debug(String.format( "LDAPSession.query(...): LDAP search base='%s' filter='%s' args='%s' scope='%s' [%s]", searchBaseDn, filterExpr, StringUtils.join(filterArgs, ","), scts.getSearchScope(), this)); } try { NamingEnumeration<SearchResult> results = dirContext.search( searchBaseDn, filterExpr, filterArgs, scts); DocumentModelList entries = ldapResultsToDocumentModels( results, fetchReferences); if (orderBy != null && !orderBy.isEmpty()) { directory.orderEntries(entries, orderBy); } return entries; } catch (NameNotFoundException nnfe) { log.error( "Unexpected response from server while performing query: " + nnfe.getMessage(), nnfe); return new DocumentModelListImpl(); } } catch (LimitExceededException e) { throw new org.nuxeo.ecm.directory.SizeLimitExceededException(e); } catch (NamingException e) { throw new DirectoryException("executeQuery failed", e); } } LDAPSession(LDAPDirectory directory, DirContext dirContext); }
LDAPSession extends BaseSession implements EntrySource { public DocumentModelList query(Map<String, Serializable> filter, Set<String> fulltext, boolean fetchReferences, Map<String, String> orderBy) throws DirectoryException { try { String[] filters = new String[filter.size()]; String[] filterArgs = new String[filter.size()]; if (fulltext == null) { fulltext = Collections.emptySet(); } int index = 0; for (String fieldName : filter.keySet()) { if (directory.isReference(fieldName)) { log.warn(fieldName + " is a reference and will be ignored as a query criterion"); continue; } String backendFieldName = directory.getFieldMapper().getBackendField( fieldName); Object fieldValue = filter.get(fieldName); StringBuilder currentFilter = new StringBuilder(); currentFilter.append("("); if (fieldValue == null) { currentFilter.append("!(" + backendFieldName + "=*)"); } else if ("".equals(fieldValue)) { if (fulltext.contains(fieldName)) { currentFilter.append(backendFieldName + "=*"); } else { currentFilter.append("!(" + backendFieldName + "=*)"); } } else { currentFilter.append(backendFieldName + "="); if (fulltext.contains(fieldName)) { if (LDAPSubstringMatchType.SUBFINAL.equals(substringMatchType)) { currentFilter.append("*{" + index + "}"); } else if (LDAPSubstringMatchType.SUBANY.equals(substringMatchType)) { currentFilter.append("*{" + index + "}*"); } else { currentFilter.append("{" + index + "}*"); } } else { currentFilter.append("{" + index + "}"); } } currentFilter.append(")"); filters[index] = currentFilter.toString(); if (fieldValue != null && !"".equals(fieldValue)) { if (fieldValue instanceof Blob) { log.warn("Binary search is not supported"); } else { filterArgs[index] = fieldValue.toString(); } } index++; } String filterExpr = "(&" + directory.getBaseFilter() + StringUtils.join(filters) + ')'; SearchControls scts = directory.getSearchControls(); if (log.isDebugEnabled()) { log.debug(String.format( "LDAPSession.query(...): LDAP search base='%s' filter='%s' args='%s' scope='%s' [%s]", searchBaseDn, filterExpr, StringUtils.join(filterArgs, ","), scts.getSearchScope(), this)); } try { NamingEnumeration<SearchResult> results = dirContext.search( searchBaseDn, filterExpr, filterArgs, scts); DocumentModelList entries = ldapResultsToDocumentModels( results, fetchReferences); if (orderBy != null && !orderBy.isEmpty()) { directory.orderEntries(entries, orderBy); } return entries; } catch (NameNotFoundException nnfe) { log.error( "Unexpected response from server while performing query: " + nnfe.getMessage(), nnfe); return new DocumentModelListImpl(); } } catch (LimitExceededException e) { throw new org.nuxeo.ecm.directory.SizeLimitExceededException(e); } catch (NamingException e) { throw new DirectoryException("executeQuery failed", e); } } LDAPSession(LDAPDirectory directory, DirContext dirContext); void setSubStringMatchType(String type); Directory getDirectory(); DirContext getContext(); @Override @SuppressWarnings("unchecked") DocumentModel createEntry(Map<String, Object> fieldMap); @Override DocumentModel getEntry(String id); @Override DocumentModel getEntry(String id, boolean fetchReferences); @Override DocumentModel getEntryFromSource(String id, boolean fetchReferences); @Override boolean hasEntry(String id); @Override DocumentModelList getEntries(); @Override @SuppressWarnings("unchecked") void updateEntry(DocumentModel docModel); @Override void deleteEntry(DocumentModel dm); @Override void deleteEntry(String id); @Override void deleteEntry(String id, Map<String, String> map); DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, boolean fetchReferences,
            Map<String, String> orderBy); @Override DocumentModelList query(Map<String, Serializable> filter); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, Map<String, String> orderBy); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, Map<String, String> orderBy,
            boolean fetchReferences); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext); @Override void close(); @Override List<String> getProjection(Map<String, Serializable> filter,
            String columnName); @Override List<String> getProjection(Map<String, Serializable> filter,
            Set<String> fulltext, String columnName); @Override boolean authenticate(String username, String password); @Override String getIdField(); @Override String getPasswordField(); @Override boolean isAuthenticating(); @Override boolean isReadOnly(); boolean rdnMatchesIdField(); @Override // useful for the log function String toString(); @Override DocumentModel createEntry(DocumentModel entry); }
LDAPSession extends BaseSession implements EntrySource { public DocumentModelList query(Map<String, Serializable> filter, Set<String> fulltext, boolean fetchReferences, Map<String, String> orderBy) throws DirectoryException { try { String[] filters = new String[filter.size()]; String[] filterArgs = new String[filter.size()]; if (fulltext == null) { fulltext = Collections.emptySet(); } int index = 0; for (String fieldName : filter.keySet()) { if (directory.isReference(fieldName)) { log.warn(fieldName + " is a reference and will be ignored as a query criterion"); continue; } String backendFieldName = directory.getFieldMapper().getBackendField( fieldName); Object fieldValue = filter.get(fieldName); StringBuilder currentFilter = new StringBuilder(); currentFilter.append("("); if (fieldValue == null) { currentFilter.append("!(" + backendFieldName + "=*)"); } else if ("".equals(fieldValue)) { if (fulltext.contains(fieldName)) { currentFilter.append(backendFieldName + "=*"); } else { currentFilter.append("!(" + backendFieldName + "=*)"); } } else { currentFilter.append(backendFieldName + "="); if (fulltext.contains(fieldName)) { if (LDAPSubstringMatchType.SUBFINAL.equals(substringMatchType)) { currentFilter.append("*{" + index + "}"); } else if (LDAPSubstringMatchType.SUBANY.equals(substringMatchType)) { currentFilter.append("*{" + index + "}*"); } else { currentFilter.append("{" + index + "}*"); } } else { currentFilter.append("{" + index + "}"); } } currentFilter.append(")"); filters[index] = currentFilter.toString(); if (fieldValue != null && !"".equals(fieldValue)) { if (fieldValue instanceof Blob) { log.warn("Binary search is not supported"); } else { filterArgs[index] = fieldValue.toString(); } } index++; } String filterExpr = "(&" + directory.getBaseFilter() + StringUtils.join(filters) + ')'; SearchControls scts = directory.getSearchControls(); if (log.isDebugEnabled()) { log.debug(String.format( "LDAPSession.query(...): LDAP search base='%s' filter='%s' args='%s' scope='%s' [%s]", searchBaseDn, filterExpr, StringUtils.join(filterArgs, ","), scts.getSearchScope(), this)); } try { NamingEnumeration<SearchResult> results = dirContext.search( searchBaseDn, filterExpr, filterArgs, scts); DocumentModelList entries = ldapResultsToDocumentModels( results, fetchReferences); if (orderBy != null && !orderBy.isEmpty()) { directory.orderEntries(entries, orderBy); } return entries; } catch (NameNotFoundException nnfe) { log.error( "Unexpected response from server while performing query: " + nnfe.getMessage(), nnfe); return new DocumentModelListImpl(); } } catch (LimitExceededException e) { throw new org.nuxeo.ecm.directory.SizeLimitExceededException(e); } catch (NamingException e) { throw new DirectoryException("executeQuery failed", e); } } LDAPSession(LDAPDirectory directory, DirContext dirContext); void setSubStringMatchType(String type); Directory getDirectory(); DirContext getContext(); @Override @SuppressWarnings("unchecked") DocumentModel createEntry(Map<String, Object> fieldMap); @Override DocumentModel getEntry(String id); @Override DocumentModel getEntry(String id, boolean fetchReferences); @Override DocumentModel getEntryFromSource(String id, boolean fetchReferences); @Override boolean hasEntry(String id); @Override DocumentModelList getEntries(); @Override @SuppressWarnings("unchecked") void updateEntry(DocumentModel docModel); @Override void deleteEntry(DocumentModel dm); @Override void deleteEntry(String id); @Override void deleteEntry(String id, Map<String, String> map); DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, boolean fetchReferences,
            Map<String, String> orderBy); @Override DocumentModelList query(Map<String, Serializable> filter); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, Map<String, String> orderBy); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext, Map<String, String> orderBy,
            boolean fetchReferences); @Override DocumentModelList query(Map<String, Serializable> filter,
            Set<String> fulltext); @Override void close(); @Override List<String> getProjection(Map<String, Serializable> filter,
            String columnName); @Override List<String> getProjection(Map<String, Serializable> filter,
            Set<String> fulltext, String columnName); @Override boolean authenticate(String username, String password); @Override String getIdField(); @Override String getPasswordField(); @Override boolean isAuthenticating(); @Override boolean isReadOnly(); boolean rdnMatchesIdField(); @Override // useful for the log function String toString(); @Override DocumentModel createEntry(DocumentModel entry);  }