class DefaultLdapAttributeDetectionService implements LdapAttributeDetectionService {

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

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

    try {

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

      SearchRequest searchRequest = assembleGroupSearchRequest(ldapConnectionTemplate, ambariLdapConfiguration);

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

      for (Entry groupEntry : groupEntries) {

        LOG.info("Collecting group attribute information from the sample entry with dn: [{}]", groupEntry.getDn());
        groupAttributeDetector.collect(groupEntry);

      }

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

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

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

    } catch (Exception e) {

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

    }

    return ambariLdapConfiguration;
  }

  @Inject public  DefaultLdapAttributeDetectionService();

}