Example #1
0
        private string GetDetailEmployees(OU ou, List <User> users)
        {
            StringBuilder sb = new StringBuilder();

            foreach (Position position in ou.Positions)
            {
                if (position.User?.Uuid != null)
                {
                    string employeeName = "<Ikke registreret bruger>";
                    foreach (User user in users)
                    {
                        if (user.Uuid.Equals(position.User.Uuid))
                        {
                            employeeName = user.Person?.Name;
                            break;
                        }
                    }

                    sb.AppendLine("\t" + position.Name + ", besat af " + employeeName);
                }
                else
                {
                    sb.AppendLine(position.Name + ", ubesat stilling");
                }
            }

            return(sb.ToString());
        }
Example #2
0
        public virtual JObject AddExistUsers(HttpContext context)
        {
            YZRequest request  = new YZRequest(context);
            string    parentou = request.GetString("parentou");

            JArray post = request.GetPostData <JArray>();
            BPMObjectNameCollection accounts = post.ToObject <BPMObjectNameCollection>();

            JObject rv    = new JObject();
            JArray  added = new JArray();

            rv["added"] = added;

            try
            {
                using (BPMConnection cn = new BPMConnection())
                {
                    cn.WebOpen();

                    foreach (string account in accounts)
                    {
                        OU.AddMember(cn, parentou, account);
                        added.Add(account);
                    }
                }
            }
            catch (Exception e)
            {
                rv[YZJsonProperty.success]      = false;
                rv[YZJsonProperty.errorMessage] = e.Message;
            }

            return(rv);
        }
Example #3
0
        public static object[] GetRoles(BPMConnection cn, string memberFullName)
        {
            List <object> rv = new List <object>();

            BPMObjectNameCollection roleSids = SecurityManager.GetMemberRoleSIDs(cn, memberFullName);

            foreach (string sid in roleSids)
            {
                string dept     = null;
                string roleName = SecurityManager.TryGetObjectNameFromSID(cn, SIDType.RoleSID, sid);
                if (String.IsNullOrEmpty(roleName))
                {
                    roleName = sid;
                }
                else
                {
                    Role role = new Role();
                    role.Open(cn, roleName);
                    roleName = role.Name;
                    OU ou = role.GetParentOU(cn);
                    dept = ou.GetFriendlyFullName(cn);
                }

                rv.Add(
                    new
                {
                    ou       = dept,
                    RoleName = roleName
                }
                    );
            }

            return(rv.ToArray());
        }
Example #4
0
        public static User CreateUser(OU targetOU, string firstname, string lastname, string loginName, string password, bool isEnabled, DateTime?accountExpirationDate)
        {
            // onderstaande zou moeten werken (= gebruiker meteen in correcte OU plaatsen) maar werkt niet
            //PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, AD.ADDomainNameShort, targetOU.Path);
            // dan maar nieuwe gebruiker in de OU in de "CN=Users,DC=ait,DC=local" plaatsen en achteraf verplaatsen naar targetOU
            PrincipalContext principalContext = new PrincipalContext(ContextType.Domain);
            UserPrincipal    userPrincipal    = new UserPrincipal(principalContext);

            userPrincipal.GivenName         = firstname;
            userPrincipal.Surname           = lastname;
            userPrincipal.DisplayName       = firstname + " " + lastname;
            userPrincipal.SamAccountName    = loginName;
            userPrincipal.UserPrincipalName = loginName + AD.ADDomainEmail;
            userPrincipal.SetPassword(password);
            userPrincipal.Enabled = isEnabled;
            userPrincipal.AccountExpirationDate = accountExpirationDate;
            try
            {
                userPrincipal.Save();
                User user = new User(userPrincipal.SamAccountName);
                OUService.MovePrincipal(user, targetOU);
                return(user);
            }
            catch (Exception error)
            {
                throw new Exception(error.Message);
            }
        }
        public static void MovePrincipal(User user, OU destinationOU)
        {
            DirectoryEntry currentDirectoryEntry = user.DirectoryEntry;
            DirectoryEntry destinationDirectory  = destinationOU.DirectoryEntry;

            currentDirectoryEntry.MoveTo(destinationDirectory);
        }
        public static void MovePrincipal(Group group, OU destinationOU)
        {
            DirectoryEntry currentDirectoryEntry = group.DirectoryEntry;
            DirectoryEntry destinationDirectory  = destinationOU.DirectoryEntry;

            currentDirectoryEntry.MoveTo(destinationDirectory);
        }
Example #7
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (NymX.Length != 0)
            {
                hash ^= NymX.GetHashCode();
            }
            if (NymY.Length != 0)
            {
                hash ^= NymY.GetHashCode();
            }
            if (OU.Length != 0)
            {
                hash ^= OU.GetHashCode();
            }
            if (Role.Length != 0)
            {
                hash ^= Role.GetHashCode();
            }
            if (Proof.Length != 0)
            {
                hash ^= Proof.GetHashCode();
            }
            return(hash);
        }
Example #8
0
        public OUInfo[] GetOUsByRole(int roleID)
        {
            OU            ou        = new OU();
            List <OUInfo> oUsByRole = ou.GetOUsByRole(roleID);

            return(oUsByRole.ToArray());
        }
Example #9
0
        public OUInfo[] GetOUs()
        {
            OU            ou  = new OU();
            List <OUInfo> all = ou.GetAll();

            return(all.ToArray());
        }
Example #10
0
        public static bool UpdateUser(User user, OU targetOU, string firstname, string lastname, string loginName, string password, bool isEnabled, DateTime?accountExpirationDate)
        {
            user.UserPrincipal.GivenName         = firstname;
            user.UserPrincipal.Surname           = lastname;
            user.UserPrincipal.DisplayName       = firstname + " " + lastname;
            user.UserPrincipal.SamAccountName    = loginName;
            user.UserPrincipal.UserPrincipalName = loginName + AD.ADDomainEmail;

            if (password.Trim() != "")
            {
                user.UserPrincipal.SetPassword(password);
            }
            user.UserPrincipal.Enabled = isEnabled;
            user.UserPrincipal.AccountExpirationDate = accountExpirationDate;
            try
            {
                user.UserPrincipal.Save();
                user.SamAccountName = loginName;
            }
            catch (Exception fout)
            {
                return(false);
            }
            if (targetOU.Path != user.DirectoryEntry.Path)
            {
                OUService.MovePrincipal(user, targetOU);
            }
            return(true);
        }
Example #11
0
        public virtual object GetRolesInPath(HttpContext context)
        {
            YZRequest      request = new YZRequest(context);
            string         path    = request.GetString("path", null);
            RoleCollection roles   = new RoleCollection();

            if (!String.IsNullOrEmpty(path))
            {
                using (BPMConnection cn = new BPMConnection())
                {
                    cn.WebOpen();

                    roles = OU.GetRoles(cn, path);
                }
            }

            //将数据转化为Json集合
            JObject rv = new JObject();

            JArray children = new JArray();

            rv[YZJsonProperty.children] = children;

            foreach (Role role in roles)
            {
                JObject item = new JObject();
                children.Add(item);
                item["Name"]     = role.Name;
                item["SID"]      = role.SID;
                item["FullName"] = role.FullName;
            }

            //输出数据
            return(rv);
        }
Example #12
0
File: Form.cs Project: radtek/EMIP
        public virtual object GetPositionInfo(HttpContext context)
        {
            YZRequest request        = new YZRequest(context);
            string    ouLevel        = request.GetString("OULevel", null);
            string    memberfullname = request.GetString("memberfullname");

            using (BPMConnection cn = new BPMConnection())
            {
                cn.WebOpen();

                Member member   = Member.FromFullName(cn, memberfullname);
                OU     ou       = null;
                OU     parentOU = member.GetParentOU(cn);

                if (!String.IsNullOrEmpty(ouLevel))
                {
                    ou = member.GetParentOU(cn, ouLevel);
                }

                return(new
                {
                    MemberFullName = member.FullName,
                    LeaderTitle = member.LeaderTitle,
                    Department = member.Department,
                    Level = member.Level,
                    OUName = ou == null ? "" : ou.Name,
                    OUCode = ou == null ? "" : ou.Code,
                    ParentOUName = parentOU == null ? "" : parentOU.Name,
                    ParentOUCode = parentOU == null ? "" : parentOU.Code,
                });
            }
        }
Example #13
0
        public virtual void MoveOUObjects(HttpContext context)
        {
            YZRequest request = new YZRequest(context);
            string    src     = request.GetString("src");
            string    tag     = request.GetString("tag");
            bool      copy    = request.GetBool("copy");

            JObject post = request.GetPostData <JObject>();
            BPMObjectNameCollection roles   = post["roles"].ToObject <BPMObjectNameCollection>();
            BPMObjectNameCollection members = post["members"].ToObject <BPMObjectNameCollection>();

            using (BPMConnection cn = new BPMConnection())
            {
                cn.WebOpen();

                if (copy)
                {
                    OU.CopyRoleAndMembers(cn, src, tag, roles, members);
                }
                else
                {
                    OU.MoveRoleAndMembers(cn, src, tag, roles, members);
                }
            }
        }
Example #14
0
        public OU[] getControlledOUs(string OuDn)
        {
            List <OU>      alObjects = new List <OU>();
            DirectoryEntry directoryObject;

            if (hapConfig.Current.AD.SecureLDAP)
            {
                directoryObject = new DirectoryEntry("LDAP://" + OuDn, hapConfig.Current.AD.User, hapConfig.Current.AD.Password, AuthenticationTypes.Secure | AuthenticationTypes.Sealing | AuthenticationTypes.Signing);
            }
            else
            {
                directoryObject = new DirectoryEntry("LDAP://" + OuDn, hapConfig.Current.AD.User, hapConfig.Current.AD.Password);
            }
            foreach (DirectoryEntry child in directoryObject.Children)
            {
                string childPath = child.Path.ToString();
                OU     ou        = new OU(childPath.Remove(0, 7), !childPath.Contains("CN"));
                if (child.SchemaClassName == "organizationalUnit")
                {
                    ou.OUs = getControlledOUs(ou.OUPath);
                }
                else
                {
                    ou.OUPath = ou.Name;
                }
                alObjects.Add(ou);
                //remove the LDAP prefix from the path

                child.Close();
                child.Dispose();
            }
            directoryObject.Close();
            directoryObject.Dispose();
            return(alObjects.ToArray());
        }
Example #15
0
        public int CreateOU(OU ou)
        {
            //Creates the List attributes of the entry and add them to attributeset

            LdapAttributeSet attributeSet = GetAttributeSet(ou);

            // DN of the entry to be added
            string dn = ou.DN;

            LdapEntry newEntry = new LdapEntry(dn, attributeSet);


            var qMgmt = LdapQueryManager.Instance;

            try
            {
                logger.Info("Saving ou={OU}", ou.DN);
                qMgmt.AddEntry(newEntry);
                return(0);
            }
            catch (Exception ex)
            {
                logger.Error("Error saving ou={DN}", ou.DN);
                logger.Log(LogLevel.Error, ex);
                return(-1);
            }
        }
Example #16
0
    private TreeNode CreateNode(OU ou)
    {
        TreeNode node = new TreeNode("&nbsp;" + ou.Name, ou.FullName);

        node.Value = ou.FullName;

        node.SelectAction     = TreeNodeSelectAction.Select;
        node.PopulateOnDemand = true;

        string mapvalue;

        mapvalue  = "OUName=" + ou.Name + ";";
        mapvalue += "OUFullName=" + ou.FullName + ";";
        mapvalue += "OULevel=" + ou.OULevel + ";";
        mapvalue += "OUCode=" + ou.Code + ";";

        foreach (string attrName in ou.ExtAttrNames)
        {
            object extValue = ou[attrName];
            if (extValue is DateTime)
            {
                extValue = AspxHelper.DateToString((DateTime)extValue);
            }

            mapvalue += attrName + "=" + extValue + ";";
        }

        node.NavigateUrl = String.Format("javascript:SetOwnerBtnValue({0},'{1}');",
                                         Request.QueryString["idx"],
                                         mapvalue);

        return(node);
    }
        public static Group UpdateGroup(Group group, OU targetOU, string groupName)
        {
            Group retourGroup = null;

            try
            {
                // dit kan wel ???
                group.GroupPrincipal.SamAccountName = groupName;
                group.GroupPrincipal.Save();

                // Name prop is readonly bij een bestaande groep, dus onderstaande werkt niet ?????
                // group.GroupPrincipal.Name = groupName;
                //
                // Wat dan wel werkt : (hierdoor wordt op AD blijkbaar wel een nieuwe group-object gemaakt, dus ik vermoed wissen en nieuw maken):
                // ===========================================================
                DirectoryEntry directoryEntry = new DirectoryEntry(AD.LDAPShort + group.GroupPrincipal.DistinguishedName);
                directoryEntry.Rename("CN=" + groupName);
                // ===========================================================

                retourGroup = new Group(groupName);
            }
            catch (Exception error)
            {
                throw new Exception(error.Message);
            }
            if (targetOU.Path != retourGroup.DirectoryEntry.Path)
            {
                OUService.MovePrincipal(retourGroup, targetOU);
            }
            return(retourGroup);
        }
Example #18
0
        public int AddOU(string identity, OUInfo ouInfo)
        {
            this.VerifyUser(identity);
            OU ou = new OU();

            return(ou.Insert2(ouInfo));
        }
Example #19
0
        public virtual JObject SaveRole(HttpContext context)
        {
            YZRequest request = new YZRequest(context);
            string    mode    = request.GetString("mode");

            JObject data = request.GetPostData <JObject>();
            Role    role = data["Role"].ToObject <Role>();
            BPMObjectNameCollection members = data["Members"].ToObject <BPMObjectNameCollection>();
            Role newRole = null;

            using (BPMConnection cn = new BPMConnection())
            {
                cn.WebOpen();

                if (mode == "edit")
                {
                    newRole = Role.UpdateRole(cn, request.GetString("fullname"), role, members);
                }
                else
                {
                    newRole = OU.AddRole(cn, request.GetString("parentou"), role, members);
                }
            }

            return(this.SerializeOUObject(newRole));
        }
        public HttpResponseMessage getADUsers(string OUNAMES)
        {
            List <CreateUser> userlist = new List <CreateUser>();

            foreach (string OU in OUNAMES.Split(','))
            {
                try
                {
                    // OU =  userOU.Replace("National", OU);
                    using (var context = new PrincipalContext(ContextType.Domain, domainName, userOU.Replace("National", OU)))
                    {
                        using (var searcher = new PrincipalSearcher(new UserPrincipal(context)))
                        {
                            //CreateUser
                            foreach (var result in searcher.FindAll())
                            {
                                DirectoryEntry de = result.GetUnderlyingObject() as DirectoryEntry;
                                // ViewBag.Message += "</br>First Name: " + de.Properties["givenName"].Value;
                                //   ViewBag.Message += "Last Name : " + de.Properties["sn"].Value;

                                //  ViewBag.Message += "User principal name: " + de.Properties["userPrincipalName"].Value;
                                CreateUser obj = new CreateUser();

                                if (de.Properties["sn"].Value != null)
                                {
                                    obj.LastName = de.Properties["sn"].Value.ToString();
                                }
                                //obj.fu    de.Properties["userPrincipalName"].Value
                                obj.OU       = OU.ToUpper();
                                obj.UserName = de.Properties["samAccountName"].Value.ToString();
                                if (de.Properties["mail"].Value != null)
                                {
                                    obj.Emailid = de.Properties["mail"].Value.ToString();
                                }
                                if (de.Properties["telephoneNumber"].Value != null)
                                {
                                    obj.Mobileno = de.Properties["telephoneNumber"].Value.ToString();
                                }
                                if (de.Properties["department"].Value != null)
                                {
                                    obj.Department = de.Properties["department"].Value.ToString();
                                }
                                obj.FirstName = de.Properties["displayName"].Value.ToString();
                                if (de.Properties["st"].Value != null)
                                {
                                    obj.State = de.Properties["st"].Value.ToString();
                                }
                                userlist.Add(obj);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(getErrormessage(ex.Message));
                }
            }
            return(getHttpResponseMessage(JsonConvert.SerializeObject(userlist)));
        }
Example #21
0
        public virtual object GetOrgTree(HttpContext context)
        {
            YZRequest      request        = new YZRequest(context);
            string         path           = request.GetString("node", null);
            string         srcoupath      = request.GetString("srcoupath", null);
            GetRootOUsType getRootOUsType = request.GetEnum <GetRootOUsType>("getRootOUsType", GetRootOUsType.All);

            if (YZStringHelper.EquName(path, "root"))
            {
                path = null;
            }

            JObject rv = new JObject();

            using (BPMConnection cn = new BPMConnection())
            {
                cn.WebOpen();

                JArray children = new JArray();
                rv[YZJsonProperty.children] = children;

                if (String.IsNullOrEmpty(path))
                {
                    SecurityToken token         = cn.Token;
                    JObject       dirParentItem = null;

                    this.Expand(cn, children, path, token, ref dirParentItem, getRootOUsType, srcoupath);

                    if (dirParentItem != null)
                    {
                        dirParentItem["dirou"] = true;

                        //没必要列出所在部门的子部门
                        //dirParentItem["expanded"] = false;
                        //dirParentItem.ChildItems.Clear();
                    }
                }
                else
                {
                    OUCollection ous = OU.GetChildren(cn, path);

                    foreach (OU ou in ous)
                    {
                        JObject item = new JObject();
                        item["leaf"]       = false;
                        item["text"]       = ou.Name;
                        item["iconCls"]    = "folder";
                        item["id"]         = ou.FullName;
                        item["enpandable"] = true;
                        children.Add(item);

                        item["data"] = this.GetNodeData(ou);
                    }
                }
            }

            //输出数据
            return(rv);
        }
Example #22
0
 private Web.ArrayOfString getPaths(OU item)
 {
     Web.ArrayOfString s = new Web.ArrayOfString();
     foreach (OU o in item.OUs)
     {
         s.Add(o.OUPath);
     }
     return(s);
 }
Example #23
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            isRefreshRequired = false;
            OU     targetOU  = (OU)cmbOUs.SelectedItem;
            string groupName = txtGroupName.Text.Trim();

            if (groupName == "")
            {
                MessageBox.Show("Groepsnaam kan niet leeg zijn !", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (isNew)
            {
                try
                {
                    activeGroup = GroupService.CreateGroup(targetOU, groupName);
                }
                catch (Exception error)
                {
                    MessageBox.Show("Nieuwe groep werden niet aangemaakt !", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }
            else
            {
                try
                {
                    activeGroup = GroupService.UpdateGroup(activeGroup, targetOU, groupName);
                }
                catch (Exception error)
                {
                    MessageBox.Show("Wijzigingen werden niet weggeschreven !", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }
            }

            isRefreshRequired = true;

            foreach (User user in usersInActiveGroup)
            {
                UserService.RemoveUserFromGroup(activeGroup.GroupPrincipal, user.UserPrincipal);
            }
            foreach (var item in lstUsersWel.Items)
            {
                UserService.AddUserToGroup(activeGroup.GroupPrincipal, ((User)item).UserPrincipal);
            }
            foreach (Group group in groupsInActiveGroup)
            {
                GroupService.RemoveGroupFromGroup(group.GroupPrincipal, activeGroup.GroupPrincipal);
            }
            foreach (var item in lstGroupsWel.Items)
            {
                GroupService.AddGroupToGroup(((Group)item).GroupPrincipal, activeGroup.GroupPrincipal);
            }

            this.Close();
        }
Example #24
0
    protected void LoadChildNode(BPMConnection cn, TreeNode node)
    {
        OUCollection ous = OU.GetChildren(cn, node.Value);

        foreach (OU cou in ous)
        {
            TreeNode subNode = CreateNode(cou);
            node.ChildNodes.Add(subNode);
        }
    }
Example #25
0
        public void DeleteOU(string identity, int[] ouIDs)
        {
            this.VerifyUser(identity);
            OU ou = new OU();

            for (int i = 0; i < ouIDs.Length; i++)
            {
                ou.Delete(ouIDs[i].ToString());
            }
        }
Example #26
0
 void UpdateTree(TreeViewItem item, OU ou)
 {
     foreach (OU o in ou.OUs)
     {
         TreeViewItem i = new TreeViewItem();
         i.Header      = o.Name;
         i.DataContext = o;
         item.Items.Add(i);
     }
 }
Example #27
0
        public virtual void DeleteOU(HttpContext context)
        {
            YZRequest request  = new YZRequest(context);
            string    fullname = request.GetString("fullname");

            using (BPMConnection cn = new BPMConnection())
            {
                cn.WebOpen();
                OU.Delete(cn, fullname);
            }
        }
Example #28
0
        public virtual JObject SaveMember(HttpContext context)
        {
            YZRequest request  = new YZRequest(context);
            string    mode     = request.GetString("mode");
            string    parentou = request.GetString("parentou", "");

            JObject data   = request.GetPostData <JObject>();
            Member  member = data["Member"].ToObject <Member>();
            User    user   = data["User"].ToObject <User>(request.Serializer);
            BPMObjectNameCollection fgOUs = data["Member"]["FGOUs"].ToObject <BPMObjectNameCollection>();
            BPMObjectNameCollection fgYWs = data["Member"]["FGYWs"].ToObject <BPMObjectNameCollection>();
            SupervisorCollection    spvs  = data["Supervisors"].ToObject <SupervisorCollection>();

            string headshot = (string)data["User"]["headshot"];
            string sign     = (string)data["User"]["sign"];

            Member newMember = null;

            using (BPMConnection cn = new BPMConnection())
            {
                cn.WebOpen();

                if (mode == "edit")
                {
                    string         fullname     = request.GetString("fullname");
                    OUProviderInfo providerInfo = OrgSvr.GetProviderInfo(cn, fullname);
                    if (providerInfo.Editable)
                    {
                        newMember = Member.UpdateMember(cn, parentou, fullname, member, user, fgOUs, fgYWs, spvs);
                    }
                    else
                    {
                        newMember = Member.FromFullName(cn, fullname);
                    }
                }
                else
                {
                    newMember = OU.AddMember(cn, request.GetString("parentou"), null, member, user, fgOUs, fgYWs, spvs);
                }

                //设置外出
                UserCommonInfo userCommonInfo = data["UserCommonInfo"].ToObject <UserCommonInfo>();
                User.SetOutOfOffice(cn, user.Account, userCommonInfo.OutOfOfficeState, userCommonInfo.OutOfOfficeFrom, userCommonInfo.OutOfOfficeTo);

                //设置主管
                TaskRuleCollection taskRules = data["TaskRules"].ToObject <TaskRuleCollection>();
                User.SaveTaskRules(cn, user.Account, taskRules);

                //头像与签名
                this.SaveHeadshot(context, headshot, sign, user.Account);

                return(this.SerializeOUObject(cn, newMember));
            }
        }
Example #29
0
        public OUInfo GetOU(string identity, int ouID)
        {
            OUInfo info = null;

            if (this.IdentityIsValid(identity))
            {
                OU ou = new OU();
                info = (OUInfo)ou.FindByID(ouID.ToString());
            }
            return(info);
        }
Example #30
0
        private void disable_Click(object sender, RoutedEventArgs e)
        {
            controlled.Cursor = Cursors.AppStarting;
            enable.IsEnabled  = disable.IsEnabled = false;
            OU item = ((TreeViewItem)treeView1.SelectedItem).DataContext as OU;

            disable.Content = "Disabling...";
            Web.apiSoapClient c = new Web.apiSoapClient();
            c.DisableCompleted += new EventHandler <System.ComponentModel.AsyncCompletedEventArgs>(c_DisableCompleted);
            c.DisableAsync(getPaths(item), item.Name);
        }