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

    @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

     * Method to set the datasource and generate a LDAPTemplate.
     *
     * @param contextSource the datasource to use.
     */
    public final void setContextSource(final LdapContextSource contextSource) {
        this.ldapTemplate = new LdapTemplate(contextSource);

        // Fix for http://www.ja-sig.org/issues/browse/CAS-663
        this.ldapTemplate.setIgnorePartialResultException(true);
    }
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

     *
     * @param contextSource the datasource to use.
     */
    public final void setContextSource(final ContextSource contextSource) {
        this.contextSource = contextSource;
        this.ldapTemplate = new LdapTemplate(contextSource);
    }
View Full Code Here

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

            throw new UnsupportedOperationException(
                    "DN must not be empty, but you provided an empty DN");
        }

        LdapOperation operation = endpoint.getOperation();
        LdapTemplate ldapTemplate = endpoint.getLdapTemplate();

        if (null == operation) {
            throw new UnsupportedOperationException(
                    "LDAP operation must not be empty, but you provided an empty operation");
        }

        switch (operation) {
        case SEARCH:
            String filter = (String) body.get(FILTER);
            exchange.getIn().setBody(ldapTemplate.search(dn, filter, endpoint.getScope(), mapper));
            break;
        case BIND:
            Attributes attributes = (Attributes) body.get(ATTRIBUTES);
            ldapTemplate.bind(dn, null, attributes);
            break;
        case UNBIND:
            ldapTemplate.unbind(dn);
            break;
        default:
            throw new UnsupportedOperationException(
                    "Bug in the Spring-LDAP component. Despite of all assertions, you managed to call an unsupported operation '"
                            + operation + "'");
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

            source.afterPropertiesSet();
        } catch (Exception e) {
            e.printStackTrace();
        }

        LdapTemplate template = new LdapTemplate(source);
        try {
            template.authenticate(DistinguishedName.EMPTY_PATH,
                    new EqualsFilter(configurationModel.getLdapConfiguration()
                            .getLdapUserId(), "test").toString(), "test");
            messages.showMessage(Level.INFO,
                    _("LDAP connection was successful"));
        } catch (Exception e) {
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

    };

    private String[] attributesToRetrieve;

    public LdapUserDetailsManager(ContextSource contextSource) {
        template = new LdapTemplate(contextSource);
    }
View Full Code Here

Examples of org.springframework.ldap.core.LdapTemplate

          throws NamingException {
        return attrs.get(groupNamingAttribute).get();
      }
    };

    LdapTemplate ldapTemplate = new LdapTemplate((getContextSource()));
    ldapTemplate.setIgnorePartialResultException(true);
    ldapTemplate.setIgnoreNameNotFoundException(true);

    List<String> ambariAdminGroups = ldapTemplate.search(
        groupBase,filterBuilder.toString(),attributesMapper);

    //user has admin role granted, if user is a member of at least 1 group,
    // which matches the rules in configuration
    if (ambariAdminGroups.size() > 0) {
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.