Examples of LdapTemplate


Examples of org.springframework.ldap.core.LdapTemplate

    @org.junit.Test
    @org.junit.Ignore   
    public void testLdapTemplate() throws Exception {

        try {
            LdapTemplate ldap = (LdapTemplate)appContext.getBean("ldapTemplate");

            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");
            dn = (String)users.get(0);

            // get attributes
            AttributesMapper mapper2 =
                new AttributesMapper() {
                    public Object mapFromAttributes(Attributes attrs) throws NamingException {
                        Map<String, String> map = new HashMap<String, String>();
                        NamingEnumeration<? extends Attribute> attrEnum = attrs.getAll();
                        while (attrEnum.hasMore()) {
                            Attribute att = attrEnum.next();
                            System.out.println(att.toString());
                        }
   
                        map.put("cn", (String)attrs.get("cn").get());
                        map.put("mail", (String)attrs.get("mail").get());
                        map.put("sn", (String)attrs.get("sn").get());
                        map.put("givenName", (String)attrs.get("givenName").get());
                        return map;
                    }
                };
            ldap.lookup(dn, new String[] {"cn", "mail", "sn", "givenName", "c"}, mapper2);
        } catch (Exception e) {
            e.printStackTrace();
        }

View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

    @Override
    protected Endpoint createEndpoint(String uri, String remaining,
            Map<String, Object> parameters) throws Exception {
        CamelContext camelContext = getCamelContext();
        Registry registry = camelContext.getRegistry();
        LdapTemplate ldapTemplate = registry.lookupByNameAndType(remaining,
                LdapTemplate.class);

        Endpoint endpoint = new SpringLdapEndpoint(remaining, ldapTemplate);

        setProperties(endpoint, parameters);
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

     */
    @Override
    public List<Type> execute(final LdapLookupRequest inRequest)
    {
        // get ldap template.
        LdapTemplate template = ldapTemplateRetriever.getLdapTemplate(inRequest);

        // set up search controls.
        SearchControls searchControls = new SearchControls();
        searchControls.setCountLimit(inRequest.getSearchUpperBound());
        searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

    protected LdapTemplate retrieveLdapTemplate(final LdapLookupRequest inLdapLookupRequest)
    {
        String templateKey = inLdapLookupRequest.getTemplateKey();
        String searchString = inLdapLookupRequest.getQueryString();

        LdapTemplate result = null;

        if (searchString != null && searchString.contains("\\"))
        {
            String[] domainQueryArr = searchString.split("\\\\");

            // Example: "domain\attribute=foo" will give domain of "domain" and searchString of "attribute=foo".
            String domain = domainQueryArr[0].toLowerCase();
            searchString = domainQueryArr[1];

            // no matter what domain we get, modify search string to remove domain.
            inLdapLookupRequest.setQueryString(searchString);

            // if domain is not null/empty, try to use it for ldap template.
            if (domain != null && !domain.isEmpty())
            {
                result = getLdapTemplates().get(domain);
            }

            // no dice on domain from search string, try template key.
            if (result == null && templateKey != null)
            {
                result = getLdapTemplates().get(templateKey);
            }

            // if not found, give back default, but log as error.
            if (result == null)
            {
                result = getDefaultLdapTemplate();
                log.error("Domain specified (" + domain + "), but not found in list of templates. "
                        + "Attempting search on default template");
            }

            if (log.isDebugEnabled())
            {
                log.debug("Domain specified, searching only on "
                        + ((LdapContextSource) result.getContextSource()).getUrls()[0]
                        + " with base: " + ((LdapContextSource) result.getContextSource()).getBaseLdapPathAsString()
                        + " for : " + searchString);
            }
        }
        else
        {
            // no domain specified in search string, try template key.
            if (templateKey != null)
            {
                result = getLdapTemplates().get(templateKey);
            }

            // no dice with template key, use default.
            if (result == null)
            {
                result = getDefaultLdapTemplate();
            }

            if (log.isDebugEnabled())
            {
                log.debug("No domain specified, searching only on "
                        + ((LdapContextSource) result.getContextSource()).getUrls()[0] + " for : " + searchString);
            }
        }
        return result;
    }
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

                allowing(contextSource).getBaseLdapPathAsString();
                will(returnValue("dc=blah"));
            }
        });

        LdapTemplate result = sut.getLdapTemplate(ldapLookupRequest);
        assertEquals(defaultLdapTemplate, result);
        context.assertIsSatisfied();
    }
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

                allowing(contextSource).getBaseLdapPathAsString();
                will(returnValue("dc=blah"));
            }
        });

        LdapTemplate result = sut.getLdapTemplate(ldapLookupRequest);
        assertEquals(mappedLdapTemplate1, result);
        context.assertIsSatisfied();
    }
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

                allowing(contextSource).getBaseLdapPathAsString();
                will(returnValue("dc=blah"));
            }
        });

        LdapTemplate result = sut.getLdapTemplate(ldapLookupRequest);
        assertEquals(mappedLdapTemplate1, result);
        context.assertIsSatisfied();
    }
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

                allowing(contextSource).getBaseLdapPathAsString();
                will(returnValue("dc=blah"));
            }
        });

        LdapTemplate result = sut.getLdapTemplate(ldapLookupRequest);
        assertEquals(defaultLdapTemplate, result);
        context.assertIsSatisfied();
    }
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

                allowing(contextSource).getBaseLdapPathAsString();
                will(returnValue("dc=blah"));
            }
        });

        LdapTemplate result = sut.getLdapTemplate(ldapLookupRequest);
        assertEquals(mappedLdapTemplate1, result);
        context.assertIsSatisfied();
    }
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

                allowing(ldapLookupRequest).getQueryString();
                will(returnValue(""));
            }
        });

        LdapTemplate result = sut.getLdapTemplate(ldapLookupRequest);
        assertEquals(defaultLdapTemplate, result);
        context.assertIsSatisfied();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.