class DefaultLdapAttributeDetectionService implements LdapAttributeDetectionService {

  @Override
  public AmbariLdapConfiguration detectLdapUserAttributes(AmbariLdapConfiguration ambariLdapConfiguration) throws AmbariLdapException {
    LOG.info("Detecting LDAP user attributes ...");

    // perform a search using the user search base
    if (Strings.isEmpty(ambariLdapConfiguration.userSearchBase())) {
      LOG.warn("No user search base provided");
      return ambariLdapConfiguration;
    }

    try {

      LdapConnectionTemplate ldapConnectionTemplate = ldapConnectionTemplateFactory.create(ambariLdapConfiguration);
      AttributeDetector<Entry> userAttributeDetector = attributeDetectorFactory.userAttributDetector();

      SearchRequest searchRequest = assembleUserSearchRequest(ldapConnectionTemplate, ambariLdapConfiguration);

      // do the search
      List<Entry> entries = ldapConnectionTemplate.search(searchRequest, getEntryMapper());

      for (Entry entry : entries) {
        LOG.info("Collecting user attribute information from the sample entry with dn: [{}]", entry.getDn());
        userAttributeDetector.collect(entry);
      }

      // select attributes based on the collected information
      Map<String, String> detectedUserAttributes = userAttributeDetector.detect();

      // setting the attributes into the configuration
      setDetectedAttributes(ambariLdapConfiguration, detectedUserAttributes);

      LOG.info("Decorated ambari ldap config : [{}]", ambariLdapConfiguration);

    } catch (Exception e) {

      LOG.error("Ldap operation failed while detecting user attributes", e);
      throw new AmbariLdapException(e);

    }

    return ambariLdapConfiguration;
  }

  @Inject public  DefaultLdapAttributeDetectionService();

}