Example #1
0
        private string GetADUser(string gourp, string name)
        {
            string json = string.Empty;

            Yawei.Domain.Domain domain = new Yawei.Domain.Domain();

            if (name.Trim() != "")
            {
                SearchResultCollection searchResultCollection = Yawei.Domain.Domain.ExecuteSearchResult(domain.GetDirectoryEntry(domain.DistinguishedName), "(&(objectCategory=person)(objectClass=user)(CN=*" + name + "*))", SearchScope.Subtree);
                json += "{";
                json += "\"total\":" + searchResultCollection.Count.ToString() + ",\"rows\":[";
                for (int i = 0; i < searchResultCollection.Count; i++)
                {
                    DomainUser user = domain.GetUser(searchResultCollection[i].GetDirectoryEntry().Guid.ToString());
                    json += "{\"UserGuid\":\"" + user.Guid.ToString() + "\",\"UserDN\":\"" + user.DN + "\",\"UserCN\":\"" + user.CN + "\",\"UserLoginName\":\"" + user.LoginName + "\",\"UserType\":\"AD\"}";
                    if (i + 1 < searchResultCollection.Count)
                    {
                        json += ",";
                    }
                }
                json += "]}";
            }
            else
            {
                using (DomainOU domainOU = domain.GetOU(gourp))
                {
                    SearchResultCollection searchResultCollection = Yawei.Domain.Domain.ExecuteSearchResult(domainOU, "(&(objectCategory=person)(objectClass=user))", SearchScope.OneLevel);;//Yawei.Domain.Domain.ExecuteSearchResult(domainOU, "(&(objectCategory=person)(objectClass=user))", SearchScope.OneLevel);
                    json += "{";
                    json += "\"total\":" + searchResultCollection.Count.ToString() + ",\"rows\":[";
                    for (int i = 0; i < searchResultCollection.Count; i++)
                    {
                        DomainUser user = domain.GetUser(searchResultCollection[i].GetDirectoryEntry().Guid.ToString());
                        json += "{\"UserGuid\":\"" + user.Guid.ToString() + "\",\"UserDN\":\"" + user.DN + "\",\"UserCN\":\"" + user.CN + "\",\"UserLoginName\":\"" + user.LoginName + "\",\"UserType\":\"AD\"}";
                        if (i + 1 < searchResultCollection.Count)
                        {
                            json += ",";
                        }
                    }
                    json += "]}";
                }
            }
            return(json);
        }
Example #2
0
        private void SetPageData()
        {
            switch (model)
            {
            case "AD":
                Yawei.Domain.Domain domain   = new Yawei.Domain.Domain();
                DomainOU            domainOU = domain.GetOU("OU=市直机关,DC=qd,DC=gov,DC=cn");
                foreach (SearchResult searchResult in Yawei.Domain.Domain.ExecuteSearchResult(domainOU, "(objectClass=organizationalUnit)", SearchScope.OneLevel))
                {
                    ou += "<option value=\"" + searchResult.GetDirectoryEntry().Guid + "\">" + searchResult.GetDirectoryEntry().Name.Replace("OU=", "") + "</option>";
                }

                break;

            case "DB":
                Database database = DatabaseFactory.CreateDatabase("SystemPerson");
                DataSet  doc      = database.ExecuteDataSet("select Guid,title from Groups where ouPath='OU=青岛市政府投资项目科技防腐平台,DC=组'");
                foreach (DataRow dr in doc.Tables[0].Rows)
                {
                    ou += "<option value=\"" + dr["Guid"].ToString() + "\">" + dr["title"].ToString() + "</option>";
                }
                break;
            }
        }
Example #3
0
        /// <summary>
        /// 初始化页面属性及操作。
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            try
            {
                string userType = ConfigurationManager.AppSettings["SystemUser"];

                switch (userType.ToUpper())
                {
                case "AD":
                    if (Request.Cookies["CurrentUserInfo"] == null)
                    {
                        TicketManager ticketManager = new TicketManager();
                        if (ticketManager.LoadTicket(ConfigurationManager.AppSettings["domain"]))
                        {
                            Yawei.Domain.Domain domain = new Yawei.Domain.Domain();
                            using (DomainUser domainUser = domain.GetUser(ticketManager.ADGuid))
                            {
                                CurrentUser.SetCookieUserInfo(ticketManager.ADGuid, domainUser.CN, domainUser.DN, ticketManager.Userid);
                            }
                            GetUser(ticketManager.ADGuid);
                            SetOnlinUser();
                        }
                        //else
                        //    Response.Redirect(AppSupport.AppPath + "/SystemOption/lock.html");
                    }
                    else
                    {
                        var guid = Request.Cookies["CurrentUserInfo"].Values["CurrentUserGuid"];
                        GetUser(guid);
                        SetOnlinUser();
                    }
                    break;

                case "LD":
                case "DB":
                    if (Request.Cookies["CurrentUserInfo"] == null)
                    {
                        Response.Redirect(AppSupport.AppPath + "/Support/Login/Default.aspx?url=" + Server.UrlEncode(Request.Url.ToString()));
                    }
                    else
                    {
                        var guid = Request.Cookies["CurrentUserInfo"].Values["CurrentUserGuid"];
                        GetUser(guid);
                        SetOnlinUser();
                    }

                    break;
                }


                //if (string.IsNullOrWhiteSpace(CurrentUser.UserGuid) || (CurrentUser.UserRole == null))
                //    Response.Redirect(AppSupport.AppPath + "/SystemOption/lock.html");



                //CurrentUser = new CurrentUser("755dd04f-bb9d-44e0-b2f5-07c3986123fb");
            }
            catch (ThreadAbortException exc_)
            {
            }
            catch (Exception ex)
            {
            }


            base.OnLoad(e);
        }