org.springframework.ldap.filter.Filter Java Examples
The following examples show how to use
org.springframework.ldap.filter.Filter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapUtil.java From zstack with Apache License 2.0 | 5 votes |
public boolean validateDnExist(LdapTemplateContextSource ldapTemplateContextSource, String fullDn, Filter filter){ try { String dn = fullDn.replace("," + ldapTemplateContextSource.getLdapContextSource().getBaseLdapPathAsString(), ""); List<Object> result = ldapTemplateContextSource.getLdapTemplate().search(dn, filter.toString(), new AbstractContextMapper<Object>() { @Override protected Object doMapFromContext(DirContextOperations ctx) { return ctx.getNameInNamespace(); } }); return result.contains(fullDn); }catch (Exception e){ logger.warn(String.format("validateDnExist[dn=%s, filter=%s] fail", fullDn, filter.toString()), e); return false; } }
Example #2
Source File: LdapTemplate.java From spring-ldap with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public <T> List<T> find(Name base, Filter filter, SearchControls searchControls, final Class<T> clazz) { Filter finalFilter = odm.filterFor(clazz, filter); // Search from the root if we are not told where to search from Name localBase = base; if (base == null || base.size() == 0) { localBase = LdapUtils.emptyLdapName(); } // extend search controls with the attributes to return String[] attributes = odm.manageClass(clazz); searchControls.setReturningAttributes(attributes); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Searching - base=%1$s, finalFilter=%2$s, scope=%3$s", base, finalFilter, searchControls)); } List<T> result = search(localBase, finalFilter.encode(), searchControls, new ContextMapper<T>() { @Override public T mapFromContext(Object ctx) throws javax.naming.NamingException { return odm.mapFromLdapDataEntry((DirContextOperations) ctx, clazz); } }); result.remove(null); if (LOG.isDebugEnabled()) { LOG.debug(String.format("Found %1$s Entries - %2$s", result.size(), result)); } return result; }
Example #3
Source File: LdapUtils.java From cxf with Apache License 2.0 | 5 votes |
public static List<String> getAttributeOfEntries( LdapTemplate ldapTemplate, String baseDN, String objectClass, String filterAttributeName, String filterAttributeValue, String searchAttribute) { List<Filter> filters = Collections.singletonList(new EqualsFilter(filterAttributeName, filterAttributeValue)); return getAttributeOfEntries(ldapTemplate, baseDN, objectClass, filters, searchAttribute); }
Example #4
Source File: LdapUtils.java From cxf with Apache License 2.0 | 5 votes |
public static List<String> getAttributeOfEntries( LdapTemplate ldapTemplate, String baseDN, String objectClass, List<Filter> filters, String searchAttribute) { List<String> ldapAttributes = null; AttributesMapper<Object> mapper = new AttributesMapper<Object>() { public Object mapFromAttributes(Attributes attrs) throws NamingException { NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { return attrEnum.next().get(); } return null; } }; String[] searchAttributes = new String[] {searchAttribute}; List<?> result = null; AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", objectClass)); if (filters != null) { for (Filter f : filters) { filter.and(f); } } result = ldapTemplate.search((baseDN == null) ? "" : baseDN, filter.toString(), SearchControls.SUBTREE_SCOPE, searchAttributes, mapper); if (result != null && !result.isEmpty()) { ldapAttributes = CastUtils.cast((List<?>)result); } return ldapAttributes; }
Example #5
Source File: LdapQueryBuilder.java From spring-ldap with Apache License 2.0 | 5 votes |
@Override public Filter filter() { if(rootContainer == null) { throw new IllegalStateException("No filter conditions have been specified specified"); } return rootContainer.filter(); }
Example #6
Source File: DefaultContainerCriteria.java From spring-ldap with Apache License 2.0 | 5 votes |
@Override public Filter filter() { if(filters.size() == 1) { // No need to wrap in And/OrFilter if there's just one condition. return filters.iterator().next(); } return type.constructFilter().appendAll(filters); }
Example #7
Source File: DefaultConditionCriteria.java From spring-ldap with Apache License 2.0 | 5 votes |
private Filter negateIfApplicable(Filter myFilter) { if (negated) { return new NotFilter(myFilter); } return myFilter; }
Example #8
Source File: DefaultObjectDirectoryMapper.java From spring-ldap with Apache License 2.0 | 5 votes |
@Override public Filter filterFor(Class<?> clazz, Filter baseFilter) { Filter ocFilter = getEntityData(clazz).ocFilter; if(baseFilter == null) { return ocFilter; } AndFilter andFilter = new AndFilter(); return andFilter.append(ocFilter).append(baseFilter); }
Example #9
Source File: LdapGroupClaimsHandler.java From cxf with Apache License 2.0 | 4 votes |
public List<Filter> getCustomFilters() { return customFilters; }
Example #10
Source File: DefaultContainerCriteria.java From spring-ldap with Apache License 2.0 | 4 votes |
@Override public DefaultContainerCriteria append(Filter filter) { this.filters.add(filter); return this; }
Example #11
Source File: DefaultConditionCriteria.java From spring-ldap with Apache License 2.0 | 4 votes |
private ContainerCriteria appendToParent(Filter filter) { return parent.append(negateIfApplicable(filter)); }
Example #12
Source File: DefaultObjectDirectoryMapper.java From spring-ldap with Apache License 2.0 | 4 votes |
private EntityData(ObjectMetaData metaData, Filter ocFilter) { this.metaData=metaData; this.ocFilter=ocFilter; }
Example #13
Source File: HardcodedFilterIntegrationTest.java From spring-ldap with Apache License 2.0 | 4 votes |
@Test public void verifyThatFilterEditorWorks() { Filter filter = dummyFilterConsumer.getFilter(); assertThat(filter instanceof HardcodedFilter).isTrue(); assertThat(filter.toString()).isEqualTo("(&(objectclass=person)(!(objectclass=computer))"); }
Example #14
Source File: DummyFilterConsumer.java From spring-ldap with Apache License 2.0 | 4 votes |
public void setFilter(Filter filter) { this.filter = filter; }
Example #15
Source File: DummyFilterConsumer.java From spring-ldap with Apache License 2.0 | 4 votes |
public Filter getFilter() { return filter; }
Example #16
Source File: LdapQuery.java From spring-ldap with Apache License 2.0 | 2 votes |
/** * Get the filter. * * @return the filter. */ Filter filter();
Example #17
Source File: ObjectDirectoryMapper.java From spring-ldap with Apache License 2.0 | 2 votes |
/** * Use the specified search filter and return a new one that only applies to entries of the specified class. * In effect this means padding the original filter with an objectclass condition. * * @param clazz the class. * @param baseFilter the filter we want to use. * @return the original filter, modified so that it only applies to entries of the specified class. * @throws org.springframework.ldap.NamingException on error. */ Filter filterFor(Class<?> clazz, Filter baseFilter);
Example #18
Source File: LdapGroupClaimsHandler.java From cxf with Apache License 2.0 | 2 votes |
/** * Define some custom filters to use in retrieving group membership information. This allows you to restrict * the groups that are returned based on some attribute value, for example. * @param customFilters */ public void setCustomFilters(List<Filter> customFilters) { this.customFilters = customFilters; }
Example #19
Source File: LdapOperations.java From spring-ldap with Apache License 2.0 | 2 votes |
/** * Find all entries in the LDAP directory of a given type that matches the specified filter. * The referenced class must have object-directory mapping metadata specified using * {@link org.springframework.ldap.odm.annotations.Entry} and associated annotations. * * @param <T> The Java type to return * @param base The root of the sub-tree at which to begin the search. * @param filter The search filter. * @param searchControls The search controls of the search. Note that the 'returned attributes' parameter should * typically not be tampered with, since that may affect the attributes populated in returned entries. * @param clazz The Java type to return * @return All entries that are of the type represented by the given * Java class * * @throws org.springframework.ldap.NamingException on error. * @since 2.0 */ <T> List<T> find(Name base, Filter filter, SearchControls searchControls, Class<T> clazz);
Example #20
Source File: AppendableContainerCriteria.java From spring-ldap with Apache License 2.0 | votes |
ContainerCriteria append(Filter filter);