HardcodedFilter hardcodedFilter = new HardcodedFilter(filter); if(validateDnExist(ldapTemplateContextSource, ldapDn, hardcodedFilter)){ accountUuidList.add(ldapAccRefVO.getAccountUuid());
private void handle(APIGetCandidateLdapEntryForBindingMsg msg) { APIGetLdapEntryReply reply = new APIGetLdapEntryReply(); AndFilter andFilter = new AndFilter(); andFilter.and(new HardcodedFilter(msg.getLdapFilter())); List<String> boundLdapEntryList = Q.New(LdapAccountRefVO.class) .select(LdapAccountRefVO_.ldapUid) .listValues(); List<Object> result = this.searchLdapEntry(andFilter.toString(), msg.getLimit(), new ResultFilter() { @Override boolean needSelect(String dn) { return !boundLdapEntryList.contains(dn); } }); reply.setInventories(result); bus.reply(msg, reply); }
public void setAsText(String text) throws IllegalArgumentException { setValue(new HardcodedFilter(text)); } }
public <T> List<T> search(Class<T> managedClass, Name base, String filter, SearchControls scope) { Filter searchFilter = null; if(StringUtils.hasText(filter)) { searchFilter = new HardcodedFilter(filter); } return ldapTemplate.find(base, searchFilter, scope, managedClass); }
public <T> List<T> search(Class<T> managedClass, Name base, String filter, SearchControls scope) { Filter searchFilter = null; if(StringUtils.hasText(filter)) { searchFilter = new HardcodedFilter(filter); } return ldapTemplate.find(base, searchFilter, scope, managedClass); }
public <T> List<T> search(Class<T> managedClass, Name base, String filter, SearchControls scope) { Filter searchFilter = null; if(StringUtils.hasText(filter)) { searchFilter = new HardcodedFilter(filter); } return ldapTemplate.find(base, searchFilter, scope, managedClass); }
public void setAsText(String text) throws IllegalArgumentException { setValue(new HardcodedFilter(text)); } }
public <T> List<T> search(Class<T> managedClass, Name base, String filter, SearchControls scope) { Filter searchFilter = null; if(StringUtils.hasText(filter)) { searchFilter = new HardcodedFilter(filter); } return ldapTemplate.find(base, searchFilter, scope, managedClass); }
public void setAsText(String text) throws IllegalArgumentException { setValue(new HardcodedFilter(text)); } }
public void setAsText(String text) throws IllegalArgumentException { setValue(new HardcodedFilter(text)); } }
@Test public void testEquals() { String attribute = "(foo=a*b)"; HardcodedFilter originalObject = new HardcodedFilter(attribute); HardcodedFilter identicalObject = new HardcodedFilter(attribute); HardcodedFilter differentObject = new HardcodedFilter("(bar=a*b)"); HardcodedFilter subclassObject = new HardcodedFilter(attribute) { }; new EqualsTester(originalObject, identicalObject, differentObject, subclassObject); } }
public LdapAuthenticationProvider(String providerName, String providerDescription, String loginConfig, UserPasswordCredentialManager upcm, UserManager manager, JetspeedSecuritySynchronizer synchronizer, PoolingContextSource poolingContextSource, String userSearchBase, String userFilter, String userEntryPrefix, String searchScope) { super(providerName, providerDescription, loginConfig); this.upcm = upcm; this.manager = manager; this.synchronizer = synchronizer; this.poolingContextsource = poolingContextSource; this.userEntryPrefix = userEntryPrefix; this.userSearchPath = new DistinguishedName(userSearchBase); if (!StringUtils.isEmpty(userFilter)) { this.userFilter = new HardcodedFilter(userFilter); } this.searchControls = new SearchControls(); this.searchControls.setReturningAttributes(new String[]{}); this.searchControls.setReturningObjFlag(true); this.searchControls.setSearchScope(Integer.parseInt(searchScope)); }
/** * Specify a hardcoded filter. Please note that using this method, the filter string will not be * validated or escaped in any way. <b>Never</b> use direct user input and use it concatenating strings * to use as LDAP filters. Doing so opens up for "LDAP injection", where malicious user * may inject specifically constructed data to form filters at their convenience. When user input is used * consider using {@link #where(String)} or {@link #filter(String, Object...)} instead. * * @param hardcodedFilter The hardcoded filter string to use in the search. * @return this instance. * @throws IllegalStateException if a filter has already been specified. */ public LdapQuery filter(String hardcodedFilter) { initRootContainer(); rootContainer.append(new HardcodedFilter(hardcodedFilter)); return this; }
/** * Specify a hardcoded filter. Please note that using this method, the filter string will not be * validated or escaped in any way. <b>Never</b> use direct user input and use it concatenating strings * to use as LDAP filters. Doing so opens up for "LDAP injection", where malicious user * may inject specifically constructed data to form filters at their convenience. When user input is used * consider using {@link #where(String)} or {@link #filter(String, Object...)} instead. * * @param hardcodedFilter The hardcoded filter string to use in the search. * @return this instance. * @throws IllegalStateException if a filter has already been specified. */ public LdapQuery filter(String hardcodedFilter) { initRootContainer(); rootContainer.append(new HardcodedFilter(hardcodedFilter)); return this; }
/** * Specify a hardcoded filter. Please note that using this method, the filter string will not be * validated or escaped in any way. <b>Never</b> use direct user input and use it concatenating strings * to use as LDAP filters. Doing so opens up for "LDAP injection", where malicious user * may inject specifically constructed data to form filters at their convenience. When user input is used * consider using {@link #where(String)} or {@link #filter(String, Object...)} instead. * * @param hardcodedFilter The hardcoded filter string to use in the search. * @return this instance. * @throws IllegalStateException if a filter has already been specified. */ public LdapQuery filter(String hardcodedFilter) { initRootContainer(); rootContainer.append(new HardcodedFilter(hardcodedFilter)); return this; }
/** * Specify a hardcoded filter. Please note that using this method, the filter string will not be * validated or escaped in any way. <b>Never</b> use direct user input and use it concatenating strings * to use as LDAP filters. Doing so opens up for "LDAP injection", where malicious user * may inject specifically constructed data to form filters at their convenience. When user input is used * consider using {@link #where(String)} or {@link #filter(String, Object...)} instead. * * @param hardcodedFilter The hardcoded filter string to use in the search. * @return this instance. * @throws IllegalStateException if a filter has already been specified. */ public LdapQuery filter(String hardcodedFilter) { initRootContainer(); rootContainer.append(new HardcodedFilter(hardcodedFilter)); return this; }
public LdapUserPasswordCredentialManagerImpl(UserPasswordCredentialStorageManager upcsm, UserPasswordCredentialAccessManager upcam, UserPasswordCredentialPolicyManager upcpm, CredentialPasswordEncoder cpe, PoolingContextSource poolingContextSource, String userSearchBase, String userFilter, String userEntryPrefix, String searchScope) { this.upcsm = upcsm; this.upcam = upcam; this.upcpm = upcpm; this.cpe = cpe != null && (upcpm == null || upcpm.getCredentialPasswordEncoder() != cpe) ? cpe : null; this.poolingContextsource = poolingContextSource; this.userEntryPrefix = userEntryPrefix; this.userSearchPath = new DistinguishedName(userSearchBase); if (!StringUtils.isEmpty(userFilter)) { this.userFilter = new HardcodedFilter(userFilter); } this.searchControls = new SearchControls(); this.searchControls.setReturningAttributes(new String[]{}); this.searchControls.setReturningObjFlag(false); this.searchControls.setSearchScope(Integer.parseInt(searchScope)); }
@Test public void testHardcodedFilter() { HardcodedFilter filter = new HardcodedFilter("(foo=a*b)"); assertThat(filter.encode()).isEqualTo("(foo=a*b)"); NotFilter notFilter = new NotFilter(new HardcodedFilter("(foo=a*b)")); assertThat(notFilter.encode()).isEqualTo("(!(foo=a*b))"); AndFilter andFilter = new AndFilter(); andFilter.and(new HardcodedFilter("(foo=a*b)")); andFilter.and(new HardcodedFilter("(bar=a*b)")); assertThat(andFilter.encode()).isEqualTo("(&(foo=a*b)(bar=a*b))"); andFilter = new AndFilter(); andFilter.and(new HardcodedFilter("(foo=a*b)")); andFilter.and(new NotFilter(new HardcodedFilter("(bar=a*b)"))); assertThat(andFilter.encode()).isEqualTo("(&(foo=a*b)(!(bar=a*b)))"); }
@Test public void verifyThatWildcardsAreUnescaped() { HardcodedFilter filter = new HardcodedFilter("cn=Some*"); CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler(); ldapTemplate.search(LdapUtils.emptyLdapName(), filter.encode(), handler); int hits = handler.getNoOfRows(); assertThat(hits > 1).isTrue(); } }
private static Map<String, Attribute> getAttributesOfEntry(LdapTemplate ldapTemplate, String baseDN, String objectClass, String searchFilter, String[] searchAttributes) { Map<String, Attribute> ldapAttributes = null; AttributesMapper<Map<String, Attribute>> mapper = new AttributesMapper<Map<String, Attribute>>() { public Map<String, Attribute> mapFromAttributes(Attributes attrs) throws NamingException { Map<String, Attribute> map = new HashMap<>(); NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll(); while (attrEnum.hasMore()) { Attribute att = attrEnum.next(); map.put(att.getID(), att); } return map; } }; AndFilter filter = new AndFilter(); filter.and(new EqualsFilter("objectclass", objectClass)).and(new HardcodedFilter(searchFilter)); List<?> result = ldapTemplate.search((baseDN == null) ? "" : baseDN, filter.toString(), SearchControls.SUBTREE_SCOPE, searchAttributes, mapper); if (result != null && !result.isEmpty()) { ldapAttributes = CastUtils.cast((Map<?, ?>)result.get(0)); } return ldapAttributes; }