Package services

Source Code of services.LDAPChecker

package services;

import dao.LDAPSupport;
import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import net.sf.ldaptemplate.AttributesMapper;
import net.sf.ldaptemplate.LdapTemplate;
import net.sf.ldaptemplate.support.DistinguishedName;


public class LDAPChecker implements LDAPSupport {

    private LdapTemplate ldapTemplate;

    @Override
    public LdapTemplate getLdapTemplate() {
        return ldapTemplate;
    }

    @Override
    public void setLdapTemplate(LdapTemplate ldapTemplate) {
        this.ldapTemplate = ldapTemplate;
    }

   
    public String checkAlreadyExists(String login) {
        DistinguishedName webaccounts = new DistinguishedName();
        webaccounts.add("ou","webaccounts");

        List lst = getLdapTemplate().search(webaccounts, "cn=" + login, new AttributesMapper() {
            @Override
            public Object mapFromAttributes(Attributes attrs) throws NamingException {
               return attrs.get("cn").get();
            }
         });
        if(lst.size() > 0) {
            return "Такой логин уже занят";
        }
        return null;
    }


}
TOP

Related Classes of services.LDAPChecker

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.