Package org.springframework.ldap.filter

Examples of org.springframework.ldap.filter.AndFilter


            String user = props.getProperty("claimUser");
            Assert.notNull(user, "Property 'claimUser' not configured");

            String dn = null;

            AndFilter filter = new AndFilter();
            filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("cn", user));

            //find DN of user
            AttributesMapper mapper =
                new AttributesMapper() {
                    public Object mapFromAttributes(Attributes attrs) throws NamingException {
                        return attrs.get("distinguishedName").get();
                    }
                };
            @SuppressWarnings("rawtypes")
            List users =
                ldap.search(
                            "OU=users,DC=emea,DC=mycompany,DC=com",
                            filter.toString(),
                            SearchControls.SUBTREE_SCOPE,
                            mapper
                );

            Assert.isTrue(users.size() == 1, "Only one user expected");
View Full Code Here


        if (index == -1)
        {
            throw new IllegalArgumentException("Malformed arg");
        }

        AndFilter filter;

        filter = new AndFilter();
        for (Filter filterObject : filterList)
        {
            filter.and(filterObject);
        }
        filter.and(new LikeFilter(searchString.substring(0, index), searchString.substring(index + 1, searchString
                .length())));

        return filter;
    }
View Full Code Here

public class SearchUtil
{

    public static Filter andFilters(Filter... filters)
    {
        AndFilter andFilter = new AndFilter();
        for (Filter filter : filters)
        {
            andFilter.and(filter);
        }
        return andFilter;
    }
View Full Code Here

    }

    public static Filter constructMatchingFieldsFilter(Filter baseFilter,
            String[]... fieldNamesAndValues)
    {
        AndFilter filter = new AndFilter();
        for (String[] nameAndValues : fieldNamesAndValues)
        {
            if (nameAndValues.length > 1)
            {
                String name = nameAndValues[0];
                OrFilter fieldFilter = new OrFilter();
                for (int i = 1; i < nameAndValues.length; i++)
                {
                    fieldFilter.or(new EqualsFilter(name, nameAndValues[i]));
                }
                filter.and(fieldFilter);
            }
        }
        return baseFilter != null ? andFilters(baseFilter, filter) : filter;
    }
View Full Code Here

            if (LOG.isLoggable(Level.FINEST)) {
                LOG.finest("Retrieve claims for user " + user);
            }
        }
       
        AndFilter filter = new AndFilter();
        filter.and(
                new EqualsFilter("objectclass", this.getObjectClass())).and(
                        new EqualsFilter(this.getUserNameAttribute(), user));

        List<String> searchAttributeList = new ArrayList<String>();
        for (RequestClaim claim : claims) {
            if (getClaimsLdapAttributeMapping().keySet().contains(claim.getClaimType().toString())) {
                searchAttributeList.add(
                    getClaimsLdapAttributeMapping().get(claim.getClaimType().toString())
                );
            } else {
                if (LOG.isLoggable(Level.FINER)) {
                    LOG.finer("Unsupported claim: " + claim.getClaimType());
                }
            }
        }

        String[] searchAttributes = null;
        searchAttributes = searchAttributeList.toArray(new String[searchAttributeList.size()]);

        AttributesMapper mapper =
            new AttributesMapper() {
                public Object mapFromAttributes(Attributes attrs) throws NamingException {
                    Map<String, Attribute> map = new HashMap<String, Attribute>();
                    NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll();
                    while (attrEnum.hasMore()) {
                        Attribute att = attrEnum.next();
                        map.put(att.getID(), att);
                    }
                    return map;
                }
            };
       
       
        List<?> result = ldap.search((this.userBaseDn == null) ? "" : this.userBaseDn, filter.toString(),
                SearchControls.SUBTREE_SCOPE, searchAttributes, mapper);
     
        Map<String, Attribute> ldapAttributes = null;
        if (result != null && result.size() > 0) {
            ldapAttributes = CastUtils.cast((Map<?, ?>)result.get(0));
View Full Code Here

            String user = props.getProperty("claimUser");
            Assert.notNull(user, "Property 'claimUser' not configured");

            String dn = null;

            AndFilter filter = new AndFilter();
            filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("cn", user));

            //find DN of user
            AttributesMapper mapper =
                new AttributesMapper() {
                    public Object mapFromAttributes(Attributes attrs) throws NamingException {
                        return attrs.get("distinguishedName").get();
                    }
                };
            @SuppressWarnings("rawtypes")
            List users =
                ldap.search(
                            "OU=users,DC=emea,DC=mycompany,DC=com",
                            filter.toString(),
                            SearchControls.SUBTREE_SCOPE,
                            mapper
                );

            Assert.isTrue(users.size() == 1, "Only one user expected");
View Full Code Here

            if (LOG.isLoggable(Level.FINEST)) {
                LOG.finest("Retrieve claims for user " + user);
            }
        }
       
        AndFilter filter = new AndFilter();
        filter.and(
                new EqualsFilter("objectclass", this.getObjectClass())).and(
                        new EqualsFilter(this.getUserNameAttribute(), user));

        List<String> searchAttributeList = new ArrayList<String>();
        for (RequestClaim claim : claims) {
            if (getClaimsLdapAttributeMapping().keySet().contains(claim.getClaimType().toString())) {
                searchAttributeList.add(
                    getClaimsLdapAttributeMapping().get(claim.getClaimType().toString())
                );
            } else {
                if (LOG.isLoggable(Level.FINER)) {
                    LOG.finer("Unsupported claim: " + claim.getClaimType());
                }
            }
        }

        String[] searchAttributes = null;
        searchAttributes = searchAttributeList.toArray(new String[] {});

        AttributesMapper mapper =
            new AttributesMapper() {
                public Object mapFromAttributes(Attributes attrs) throws NamingException {
                    Map<String, Attribute> map = new HashMap<String, Attribute>();
                    NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll();
                    while (attrEnum.hasMore()) {
                        Attribute att = attrEnum.next();
                        map.put(att.getID(), att);
                    }
                    return map;
                }
            };
       
       
        List<?> result = ldap.search((this.userBaseDn == null) ? "" : this.userBaseDn, filter.toString(),
                SearchControls.SUBTREE_SCOPE, searchAttributes, mapper);
     
        Map<String, Attribute> ldapAttributes = null;
        if (result != null && result.size() > 0) {
            ldapAttributes = CastUtils.cast((Map<?, ?>)result.get(0));
View Full Code Here

        try
        {
            Filter filter = new EqualsFilter(userEntryPrefix, userName);
            if (userFilter != null)
            {
                filter = new AndFilter().and(userFilter).and(filter);
            }
            ctx = poolingContextsource.getReadOnlyContext();
            NamingEnumeration<SearchResult> results = ctx.search(userSearchPath, filter.encode(), searchControls);
           
            String dn = null;        
View Full Code Here

            {
                filter = configuration.getSearchFilter();
            }
            else
            {
                filter = new AndFilter().and(configuration.getSearchFilter()).and(filter);
            }
        }
        String filterStr = filter != null ? filter.encode() : "";
        if (StringUtils.isEmpty(filterStr))
        {
View Full Code Here

        try
        {
            Filter filter = new EqualsFilter(userEntryPrefix, userName);
            if (userFilter != null)
            {
                filter = new AndFilter().and(userFilter).and(filter);
            }
            ctx = poolingContextsource.getReadOnlyContext();
            NamingEnumeration<SearchResult> results = ctx.search(userSearchPath, filter.encode(), searchControls);
           
            String dn = null;        
View Full Code Here

TOP

Related Classes of org.springframework.ldap.filter.AndFilter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.