Пример #1
0
        public UserTO loginActiveDirectory(string domain, string username, string password)
        {
            UserTO result = new UserTO();

            if (String.IsNullOrEmpty(domain) || String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
            {
                result.fault = new FaultTO("Must supply domain, username and password");
            }

            if (result.fault != null)
            {
                return(result);
            }

            try
            {
                DataSource src = new DataSource()
                {
                    SiteId = new SiteId("1"), Modality = "FEDUID", Protocol = "LDAP", Provider = domain
                };
                AbstractDaoFactory f   = AbstractDaoFactory.getDaoFactory(AbstractDaoFactory.getConstant(src.Protocol));
                LdapConnection     cxn = new LdapConnection(src);
                cxn.Account = new LdapAccount(cxn);

                LdapCredentials creds = new LdapCredentials()
                {
                    AccountName = username, AccountPassword = password
                };

                using (new Impersonator(mySession.MdwsConfiguration.LdapConfiguration.RunasUser))
                {
                    string guid = cxn.Account.authenticate(creds);

                    LdapUserDao  dao = new LdapUserDao(cxn);
                    IList <User> guidLookupResult = dao.userLookupList(new KeyValuePair <string, string>("", guid));

                    if (guidLookupResult.Count != 1)
                    {
                        throw new ApplicationException("Unexpected error - more than one user returned for authenticated user's GUID");
                    }

                    return(new UserTO(guidLookupResult[0]));
                }
            }
            catch (Exception exc)
            {
                result.fault = new FaultTO(exc);
            }

            return(result);
        }
Пример #2
0
    public LdapAuthenticator(LdapCredentials creds)
    {
        domain = creds.Domain;
        string fullname = GetFullname(creds.Username);

        if (creds.OU == null)
        {
            ldap = new PrincipalContext(ContextType.Domain, domain, fullname, creds.Password);
        }
        else
        {
            ldap = new PrincipalContext(ContextType.Domain, domain, creds.OU, fullname, creds.Password);
        }
    }
Пример #3
0
        private static T InitLdap <T>(Settings settings, Func <LdapCredentials, T> init) where T : class
        {
            var creds = new LdapCredentials(settings.LDAP_USERNAME, settings.LDAP_PASSWORD, settings.LDAP_DOMAIN, settings.LDAP_OU);

            try
            {
                return(init(creds));
            }
            catch (System.DirectoryServices.AccountManagement.PrincipalServerDownException ex)
            {
                ProgramOutput.Error("LDAP server could not be contacted. Please ensure that machine DNS settings and DNS server is propely configured to reach domain controller. Also make sure that server is on the network.", ex);
                return(null);
            }
            catch (System.Security.Authentication.AuthenticationException ex)
            {
                ProgramOutput.Error("Connection to LDAP server failed, because of invalid credentials. Please check config file.", ex);
                return(null);
            }
            catch (Exception ex)
            {
                ProgramOutput.Error("Cannot init LDAP connection.", ex);
                return(null);
            }
        }
Пример #4
0
 public AbpLdapOptions()
 {
     Credentials = new LdapCredentials();
 }
Пример #5
0
 public RocketLdapOptions()
 {
     Credentials = new LdapCredentials();
 }
Пример #6
0
 public PlusLdapOptions()
 {
     Credentials = new LdapCredentials();
 }