internal static LoogonUserResult User_Logon(string userName, string password, string domain)
        {
            LoogonUserResult loogonUserResult = new LoogonUserResult();
            loogonUserResult.Autenticated = false;
            try
            {
                LDAPHelper _ADHelper = new LDAPHelper(domain, ActiveDirectoryService.CnnStringName, true, false);
                TechnicalException logError = null;

                loogonUserResult.LogResult = _ADHelper.User_Logon(userName, password, out logError).ToString();

                if (logError != null)
                    loogonUserResult.ErrorMessage = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(logError);
                else
                {
                    loogonUserResult.ErrorMessage = string.Empty;
                    loogonUserResult.Autenticated = true;
                }


            }
            catch (Exception ex)
            {
                loogonUserResult.ErrorMessage = Fwk.Exceptions.ExceptionHelper.GetAllMessageException(ex);


            }
            return loogonUserResult;
        }
Exemple #2
0
 /// <summary>
 /// Obtiene la lista de controladores de dominio para un DomainID especificado
 /// </summary>
 private List <DomainController> GetDomainControllersByDomainId(String pConnString, Int32 pDomainId)
 {
     try
     {
         using (SqlDomainControllersDataContext dc = new SqlDomainControllersDataContext(pConnString))
         {
             IEnumerable <DomainController> list = from s in dc.DomainControllers
                                                   where s.DomainId == pDomainId
                                                   select
                                                   new DomainController
             {
                 DomainId = s.DomainId,
                 HostName = s.DCHostName,
                 Id       = s.DCId,
                 Ip       = s.DCIp
             };
             return(list.ToList <DomainController>());
         }
     }
     catch (Exception ex)
     {
         Fwk.Exceptions.TechnicalException te = new Fwk.Exceptions.TechnicalException("Error al intentar obtener la lista de dominios desde la base de datos: ", ex);
         LDAPHelper.SetError(te);
         te.ErrorId = "15004";
         throw te;
     }
 }
Exemple #3
0
        /// <summary>
        ///  Este metoo autentica elusuario pero no espesifica el error. Tal como lo hace User_Logon retornando LoginResult
        /// </summary>
        /// <param name="LDAPPath">url ldap o coneccion ldap perteneciente al dominio</param>
        /// <param name="domainName">Nombre de dominio</param>
        /// <param name="username">Nombre de usuario</param>
        /// <param name="pwd">password</param>
        /// <returns></returns>
        public static bool User_Logon_IsAuthenticated(string LDAPPath, string domainName, string username, string pwd)
        {
            string domainAndUsername = String.Concat(domainName + @"\" + username);

            try
            {
                DirectoryEntry    Entry    = new DirectoryEntry(LDAPPath, username, pwd, AuthenticationTypes.Secure);
                DirectorySearcher searcher = new DirectorySearcher(Entry);
                searcher.SearchScope = SearchScope.OneLevel;


                System.DirectoryServices.SearchResult results = searcher.FindOne();
                if (results != null)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                TechnicalException te = new Fwk.Exceptions.TechnicalException(ex.Message);
                LDAPHelper.SetError(te);
                te.ErrorId = "15004";
                throw te;
            }
            return(false);
        }
Exemple #4
0
        /// <summary>
        /// Busca la lista de dominios en una base de datos.- A diferencia de DomainsUrl_GetList. Este metodo recive como parametro
        /// la cadena de coneccion y no su nombre de App.config
        /// </summary>
        /// <param name="cnnString">Cadena de coneccion</param>
        /// <returns>Lista de DomainsUrl</returns>
        public static List <DomainUrlInfo> DomainsUrl_GetList2(string cnnString)
        {
            List <DomainUrlInfo> wDomainUrlInfoList = new List <DomainUrlInfo>();

            try
            {
                using (SqlDomainURLDataContext dc = new SqlDomainURLDataContext(cnnString))
                {
                    IEnumerable <DomainUrlInfo> liste = from s in dc.DomainsUrls
                                                        select new DomainUrlInfo
                    {
                        DomainName = s.DomainName,
                        LDAPPath   = s.LDAPPath,
                        Id         = s.DomainID,
                        SiteName   = s.SiteName,
                        DomainDN   = s.DomainDN
                    };

                    return(liste.ToList <DomainUrlInfo>());
                }
            }
            catch (Exception ex)
            {
                Fwk.Exceptions.TechnicalException te = new Fwk.Exceptions.TechnicalException("Error al intentar obtener la lista de dominios desde la base de datos: ", ex);
                LDAPHelper.SetError(te);
                te.ErrorId = "15004";
                throw te;
            }
        }
Exemple #5
0
        /// <summary>
        /// Esta funcion utiliza chequea el loging de un usuario contra un dominio
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="logError"></param>
        /// <returns></returns>
        public LoginResult User_Logon(string userName, string password, out Fwk.Exceptions.TechnicalException logError)
        {
            LoginResult    wLoginResult = LoginResult.LOGIN_OK;
            Win32Exception win32Error   = null;

            logError = null;
            SafeTokenHandle safeTokenHandle;

            #region Busco el usuario con un DirectoryEntry con usuario administrador


            this.User_Get(userName, password, out wLoginResult);

            if (wLoginResult == LoginResult.ERROR_SERVER_IS_NOT_OPERATIONAL)
            {
                win32Error = new Win32Exception();
                logError   = new Fwk.Exceptions.TechnicalException(win32Error.Message);
                LDAPHelper.SetError(logError);
                logError.ErrorId = "15004";
                logError.Source  = string.Concat(logError.Source, Environment.NewLine, win32Error.Source);
                return(wLoginResult);
            }
            #endregion
            if (wLoginResult == LoginResult.LOGIN_OK)
            {
                return(wLoginResult);
            }

            //obtain a handle to an access token.
            bool returnValue = LogonUser(userName, _DomainUrlInfo.DomainName, password,
                                         (int)LOGON32.LOGON32_LOGON_INTERACTIVE,
                                         (int)LOGON32.LOGON32_PROVIDER_DEFAULT,
                                         out safeTokenHandle);



            if (!returnValue)
            {
                int ret = GetLastError();
                win32Error = new Win32Exception();
                logError   = new Fwk.Exceptions.TechnicalException(win32Error.Message);
                LDAPHelper.SetError(logError);
                logError.ErrorId = "15004";
                logError.Source  = string.Concat(logError.Source, Environment.NewLine, win32Error.Source);
            }



            return(wLoginResult);
        }
Exemple #6
0
        bool SetAD(Boolean pSecure)
        {
            lblURL.Text = string.Empty;

            DomainUrlInfo wDomainUrlInfo = (DomainUrlInfo)cmbDomains.SelectedItem;//urls.Find(p => p.DomainName.Equals(txtDomain.Text,StringComparison.CurrentCultureIgnoreCase));

            if (wDomainUrlInfo == null)
            {
                lblCheckResult.Text = "Nombre de dominio incorrecto";
                return false;
            }
            //_ADHelper = new ADHelper(wDomainUrlInfo.LDAPPath, wDomainUrlInfo.Usr, wDomainUrlInfo.Pwd);
            _ADHelper = new LDAPHelper(wDomainUrlInfo.DomainName, "testActiveDirectory", pSecure);

            return true;
        }
Exemple #7
0
        /// <summary>
        /// Retorna todos los DolmainUrl por medio de un sp usp_GetDomainsUrl_All que lee de bd encriptada
        /// </summary>
        /// <param name="cnnStringName">Nombre de la cadena de cnn</param>
        /// <returns></returns>
        public static List <DomainUrlInfo> DomainsUrl_Get_FromSp_all(string cnnStringName)
        {
            String wApplicationId = String.Empty;


            DomainUrlInfo        wDomainUrlInfo = null;
            List <DomainUrlInfo> list           = new List <DomainUrlInfo>();

            try
            {
                using (SqlConnection cnn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings[cnnStringName].ConnectionString))
                    using (SqlCommand cmd = new SqlCommand("dbo.usp_GetDomainsUrl_All", cnn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cnn.Open();


                        using (IDataReader dr = cmd.ExecuteReader())
                        {
                            while (dr.Read())
                            {
                                wDomainUrlInfo            = new DomainUrlInfo();
                                wDomainUrlInfo.DomainDN   = dr["DomainDN"].ToString();
                                wDomainUrlInfo.DomainName = dr["DomainName"].ToString();

                                wDomainUrlInfo.LDAPPath = dr["LDAPPath"].ToString();

                                wDomainUrlInfo.Pwd      = dr["Pwd"].ToString();
                                wDomainUrlInfo.SiteName = dr["SiteName"].ToString();
                                wDomainUrlInfo.Usr      = dr["Usr"].ToString();
                                list.Add(wDomainUrlInfo);
                            }
                        }

                        return(list);
                    }
            }
            catch (Exception ex)
            {
                Fwk.Exceptions.TechnicalException te = new Fwk.Exceptions.TechnicalException("Error al intentar obtener los datos del dominio desde la base de datos: ", ex);
                LDAPHelper.SetError(te);
                te.ErrorId = "15004";
                throw te;
            }
        }
Exemple #8
0
        bool SetAD(Boolean pSecure)
        {
            _ADHelper = new LDAPHelper(txtDomain.Text, "testActiveDirectory", pSecure, false);

            return true;
        }