Пример #1
0
 private void SetLdapSettings(ILdapSettingsService settings)
 {
     settings.ServerPath = WebConfigurationManager.AppSettings["LDAPServerPath"];
     settings.SearchRoot = WebConfigurationManager.AppSettings["LDAPSearchRoot"];
     settings.Username   = txtbUsername.Value;
     settings.Password   = txtbPassword.Value;
 }
Пример #2
0
        public void Connect(ILdapSettingsService settings)
        {
            IsAuthenticated = VerifyConnection(settings, UIDProperty);

            if (IsAuthenticated)
            {
                IsUIDPropertyUsed = true;
            }
            else
            {
                IsAuthenticated = VerifyConnection(settings, CNProperty);
            }
        }
Пример #3
0
        private bool VerifyConnection(ILdapSettingsService settings, string identificationProperty)
        {
            Username   = $"{identificationProperty}={settings.Username},ou=People,dc=proxiad,dc=bg";
            RootEntry  = new DirectoryEntry(settings.ServerPath, Username, settings.Password, AuthenticationTypes.None);
            SearchRoot = new DirectoryEntry(settings.SearchRoot, Username, settings.Password, AuthenticationTypes.None);

            try
            {
                var schema = RootEntry.SchemaEntry;
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
        public ILoginResponse Login(ILdapSettingsService settings)
        {
            if (string.IsNullOrWhiteSpace(settings.Username) ||
                string.IsNullOrWhiteSpace(settings.Password))
            {
                response.User            = null;
                response.ResponseMessage = BusinessResources.InvalidInput;

                return(response);
            }

            ldapConnection.Connect(settings);

            if (ldapConnection.IsAuthenticated)
            {
                ldapAccountService.SetAccountManager(ldapConnection);

                IUser user;

                if (ldapConnection.IsUIDPropertyUsed)
                {
                    user = ldapAccountService.ReadUserData(settings.Username);
                }
                else
                {
                    var username = ldapAccountService.ReadUserUsername(settings.Username);
                    user = ldapAccountService.ReadUserData(username);
                }

                response.User            = user;
                response.ResponseMessage = BusinessResources.AuthenticationSucceded;
            }
            else
            {
                response.User            = null;
                response.ResponseMessage = BusinessResources.AuthenticationFailed;
            }

            return(response);
        }