public ISettings GetDefault()
        {
            var domainName        = "";
            var distinguishedName = "";

            var isMono = WorkContext.IsMono;

            if (!isMono)
            {
                try
                {
                    var domain = Domain.GetCurrentDomain();
                    domainName = string.Format(@"LDAP://{0}", domain.Name);

                    if (_ldapHelper == null)
                    {
                        _ldapHelper = new SystemLdapHelper();
                    }

                    distinguishedName =
                        _ldapHelper.GetDefaultDistinguishedName(domainName, Constants.STANDART_LDAP_PORT) ?? "";
                }
                catch (Exception)
                {
                    domainName        = "";
                    distinguishedName = "";
                }
            }

            var settings = new LDAPSupportSettings
            {
                Server     = domainName,
                UserDN     = distinguishedName,
                PortNumber = Constants.STANDART_LDAP_PORT,
                UserFilter = string.Format("({0}=*)",
                                           isMono
                        ? Constants.RfcLDAPAttributes.UID
                        : Constants.ADSchemaAttributes.USER_PRINCIPAL_NAME),
                LoginAttribute = isMono
                    ? Constants.RfcLDAPAttributes.UID
                    : Constants.ADSchemaAttributes.ACCOUNT_NAME,
                FirstNameAttribute   = Constants.ADSchemaAttributes.FIRST_NAME,
                SecondNameAttribute  = Constants.ADSchemaAttributes.SURNAME,
                MailAttribute        = Constants.ADSchemaAttributes.MAIL,
                TitleAttribute       = Constants.ADSchemaAttributes.TITLE,
                MobilePhoneAttribute = Constants.ADSchemaAttributes.MOBILE,
                LocationAttribute    = Constants.ADSchemaAttributes.STREET,
                GroupDN     = distinguishedName,
                GroupFilter = string.Format("({0}={1})", Constants.ADSchemaAttributes.OBJECT_CLASS,
                                            isMono
                        ? Constants.ObjectClassKnowedValues.POSIX_GROUP
                        : Constants.ObjectClassKnowedValues.GROUP),
                UserAttribute =
                    isMono
                        ? Constants.RfcLDAPAttributes.UID
                        : Constants.ADSchemaAttributes.DISTINGUISHED_NAME,
                GroupAttribute     = isMono ? Constants.RfcLDAPAttributes.MEMBER_UID : Constants.ADSchemaAttributes.MEMBER,
                GroupNameAttribute = Constants.ADSchemaAttributes.COMMON_NAME,
                Authentication     = string.IsNullOrEmpty(distinguishedName)
            };

            return(settings);
        }
Ejemplo n.º 2
0
        public ISettings GetDefault()
        {
            string domainName = null;
            string userFilter;
            string loginAttribute;
            string userAttribute;
            string groupFilter;
            string groupAttribute;

            string firstNameAttribute   = Constants.ADSchemaAttributes.FirstName;
            string secondNameAttribute  = Constants.ADSchemaAttributes.Surname;
            string mailAttribute        = Constants.ADSchemaAttributes.Mail;
            string titleAttribute       = Constants.ADSchemaAttributes.Title;
            string mobilePhoneAttribute = Constants.ADSchemaAttributes.Mobile;
            string locationAttribute    = Constants.ADSchemaAttributes.Street;
            string groupNameAttribute   = Constants.ADSchemaAttributes.CommonName;

            if (!WorkContext.IsMono)
            {
                try
                {
                    var domain = Domain.GetCurrentDomain();
                    domainName = String.Format(@"LDAP://{0}", domain.Name);
                }
                catch
                {
                    domainName = null;
                }
                userFilter     = "(" + Constants.ADSchemaAttributes.UserPrincipalName + "=*)";
                loginAttribute = Constants.ADSchemaAttributes.AccountName;
                groupFilter    = "(" + Constants.ADSchemaAttributes.ObjectClass + "=" + Constants.ObjectClassKnowedValues.Group + ")";
                userAttribute  = Constants.ADSchemaAttributes.DistinguishedName;
                groupAttribute = Constants.ADSchemaAttributes.Member;
            }
            else
            {
                userFilter     = "(" + Constants.RFCLDAPAttributes.Uid + "=*)";
                loginAttribute = Constants.RFCLDAPAttributes.Uid;
                groupFilter    = "(" + Constants.ADSchemaAttributes.ObjectClass + "=" + Constants.ObjectClassKnowedValues.PosixGroup + ")";
                userAttribute  = Constants.RFCLDAPAttributes.Uid;
                groupAttribute = Constants.RFCLDAPAttributes.MemberUId;
            }

            string distinguishedName = ldapHelper.GetDefaultDistinguishedName(domainName, Constants.STANDART_LDAP_PORT);

            return(new LDAPSupportSettings
            {
                Server = domainName,
                UserDN = distinguishedName,
                PortNumber = Constants.STANDART_LDAP_PORT,
                UserFilter = userFilter,
                LoginAttribute = loginAttribute,
                FirstNameAttribute = firstNameAttribute,
                SecondNameAttribute = secondNameAttribute,
                MailAttribute = mailAttribute,
                TitleAttribute = titleAttribute,
                MobilePhoneAttribute = mobilePhoneAttribute,
                LocationAttribute = locationAttribute,
                GroupDN = distinguishedName,
                GroupFilter = groupFilter,
                UserAttribute = userAttribute,
                GroupAttribute = groupAttribute,
                GroupNameAttribute = groupNameAttribute,
                Authentication = distinguishedName == null,
            });
        }