Exemplo n.º 1
0
        public AdUser GetAdUser(string samAccountName, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();

                PrincipalContext context   = new PrincipalContext(ContextType.Domain, setup.Host, setup.Base, setup.Username, setup.Password);
                UserPrincipal    principal = new UserPrincipal(context);

                if (context != null)
                {
                    principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, samAccountName);
                }

                if (principal != null)
                {
                    return(AdUser.CastToAdUser(principal));
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error retrieving AD User", ex);
            }
        }
Exemplo n.º 2
0
        public Task <Result> CreateOU(string name, SpuContext spucontext)
        {
            return(Task.Run(() =>
            {
                try
                {
                    var setup = spucontext.table_setup.FirstOrDefault();
                    var ouname = "ou=guest,";

                    PrincipalContext context = new PrincipalContext(ContextType.Domain, setup.Host, ouname + setup.Base, setup.Username, setup.Password);

                    DirectoryEntry objAD = new DirectoryEntry(setup.Base, setup.Username, setup.Password);
                    DirectoryEntry objOU = objAD.Children.Add("OU=" + name, "OrganizationalUnit");
                    objOU.CommitChanges();
                    return new Result()
                    {
                        result = true
                    };
                }
                catch (Exception ex)
                {
                    return new Result()
                    {
                        result = false, Message = ex.Message
                    };
                }
            }));
        }
Exemplo n.º 3
0
        public Result ChangePwdGuestUser(User user, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();
                PrincipalContext context   = new PrincipalContext(ContextType.Domain, setup.Host, "ou=guest," + setup.Base, setup.Username, setup.Password);
                UserPrincipal    principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, user.UserName);
                if (principal == null)
                {
                    return(new Result()
                    {
                        result = false, Message = "Account has not found"
                    });
                }
                principal.SetPassword(DataEncryptor.Decrypt(user.Password));
                principal.Save();

                return(new Result()
                {
                    result = true
                });
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
        }
Exemplo n.º 4
0
        public LdapUser GetUser(string uid, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();
                using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
                {
                    var    username = uid;
                    string filter   = "(&(|(objectClass=inetOrgPerson))(&(uid=" + username + ")))";

                    DirectorySearcher nDS = new DirectorySearcher(entry);
                    nDS.SearchScope = SearchScope.Subtree;
                    nDS.Filter      = filter;
                    SearchResult src = nDS.FindOne();
                    if (src != null)
                    {
                        DirectoryEntry de = src.GetDirectoryEntry();
                        return(LdapUser.CastToUser(de.Properties));
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                throw new Exception("Error retrieving LDAP User", ex);
            }
        }
Exemplo n.º 5
0
 public Task <List <Organization> > GetOrganizationLvl1(SpuContext spucontext, SystemConf conf)
 {
     return(Task.Run(() =>
     {
         try
         {
             var ous = new List <Organization>();
             var setup = spucontext.table_setup.FirstOrDefault();
             var ouselectd = conf.DefaultValue_OU_Filter.Split(",", StringSplitOptions.RemoveEmptyEntries);
             using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
             {
                 foreach (DirectoryEntry entryChild in entry.Children)
                 {
                     var ouname = entryChild.Name.Replace("o=", "").Replace("ou=", "");
                     if (ouselectd.Contains(ouname.ToLower()))
                     {
                         var ou = new Organization();
                         ou.ouname = ouname;
                         ou.schemaname = entryChild.SchemaClassName.ToLower();
                         ou.path = entryChild.Path.ToLower();
                         ou.ou = entryChild.Name;//.Replace("=","|");
                         ous.Add(ou);
                     }
                 }
             }
             return ous.OrderBy(o => o.ouname).ToList();
         }
         catch (Exception ex)
         {
             throw new Exception("Error retrieving LDAP User", ex);
         }
     }));
 }
Exemplo n.º 6
0
        public Result DisableUser(visual_fim_user model, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();

                PrincipalContext context   = new PrincipalContext(ContextType.Domain, setup.Host, setup.Base, setup.Username, setup.Password);
                UserPrincipal    principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, model.basic_uid);
                if (principal == null)
                {
                    return(new Result()
                    {
                        result = false, Message = "Account has not found"
                    });
                }

                DirectoryEntry d = principal.GetUnderlyingObject() as DirectoryEntry;
                d.Properties["userAccountControl"].Value = userAccountControl.DisablePasswordNotRequired;
                principal.Save();

                return(new Result()
                {
                    result = true
                });
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
        }
Exemplo n.º 7
0
        public Task <List <AdUser4> > FindUser(SearchDTO model, string[] roles, SpuContext spucontext)
        {
            return(Task.Run(() =>
            {
                var setup = spucontext.table_setup.FirstOrDefault();
                var adusers = new List <AdUser4>();

                if (roles != null)
                {
                    //if (model.ou == "Staff" | model.ou == "Internet")
                    //{
                    //    if (adusers.Count < 100)
                    //        adusers.AddRange(FindUser(model.ou.ToLower(), "", model.text_search, setup, spucontext));
                    //}
                    //else
                    //{
                    //    foreach (var role in roles)
                    //    {
                    //        if (adusers.Count < 100)
                    //            adusers.AddRange(FindUser(model.ou.ToLower(), role, model.text_search, setup, spucontext));
                    //    }
                    //}
                }
                return adusers.OrderBy(o => o.givenName).ThenBy(o => o.sn).ToList();
            }));
        }
Exemplo n.º 8
0
        public Task <Result> RemoveStaffUser(string samAccountName, SpuContext spucontext)
        {
            return(Task.Run(() =>
            {
                try
                {
                    var setup = spucontext.table_setup.FirstOrDefault();

                    PrincipalContext context = new PrincipalContext(ContextType.Domain, setup.Host, "ou=staff," + setup.Base, setup.Username, setup.Password);
                    UserPrincipal principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, samAccountName);
                    if (principal == null)
                    {
                        return new Result()
                        {
                            result = false, Message = "Account has not found"
                        };
                    }
                    principal.Delete();
                    principal.Save();

                    return new Result()
                    {
                        result = true
                    };
                }
                catch (Exception ex)
                {
                    return new Result()
                    {
                        result = false, Message = ex.Message
                    };
                }
            }));
        }
Exemplo n.º 9
0
        public Result UpdateUser(visual_fim_user model, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();
                using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
                {
                    string filter = "(&(|(objectClass=inetOrgPerson))(&(uid=" + model.basic_uid + ")))";

                    DirectorySearcher nDS = new DirectorySearcher(entry);
                    nDS.SearchScope = SearchScope.Subtree;
                    nDS.Filter      = filter;
                    SearchResult src = nDS.FindOne();
                    if (src != null)
                    {
                        DirectoryEntry de = src.GetDirectoryEntry();
                        de.Properties["cn"].Value              = AppUtil.ManageNull(model.basic_cn);
                        de.Properties["sn"].Value              = AppUtil.ManageNull(model.basic_sn);
                        de.Properties["displayName"].Value     = AppUtil.ManageNull(model.basic_displayname);
                        de.Properties["givenName"].Value       = AppUtil.ManageNull(model.basic_givenname);
                        de.Properties["telephoneNumber"].Value = AppUtil.ManageNull(model.basic_telephonenumber);
                        de.Properties["mobile"].Value          = AppUtil.ManageNull(model.basic_mobile);
                        de.Properties["jobcode"].Value         = AppUtil.ManageNull(model.cu_jobcode);
                        de.Properties["pplid"].Value           = AppUtil.ManageNull(model.cu_pplid);
                        de.Properties["thcn"].Value            = AppUtil.ManageNull(model.cu_thcn);
                        de.Properties["thsn"].Value            = AppUtil.ManageNull(model.cu_thsn);
                        de.Properties["inetCOS"].Value         = AppUtil.ManageNull(model.unix_inetCOS);
                        de.Properties["CUexpire"].Value        = AppUtil.ManageNull(model.cu_CUexpire);

                        if (model.system_idm_user_type != IDMUserType.temporary)
                        {
                            de.Properties["gecos"].Value = AppUtil.ManageNull(model.cu_gecos);
                        }
                        de.CommitChanges();
                        entry.Close();
                        de.Close();

                        return(new Result()
                        {
                            result = true
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
            return(new Result()
            {
                result = false
            });
        }
Exemplo n.º 10
0
        public Result UpdateUser(visual_fim_user model, SpuContext spucontext)
        {
            try
            {
                var setup    = spucontext.table_setup.FirstOrDefault();
                var oufilter = model.system_ou_lvl1.Replace("o=", "ou=") + ",";
                if (!string.IsNullOrEmpty(model.system_ou_lvl2))
                {
                    oufilter = model.system_ou_lvl2.Replace("o=", "ou=") + "," + oufilter;
                }
                if (!string.IsNullOrEmpty(model.system_ou_lvl3))
                {
                    oufilter = model.system_ou_lvl3.Replace("o=", "ou=") + "," + oufilter;
                }

                PrincipalContext context   = new PrincipalContext(ContextType.Domain, setup.Host, oufilter + setup.Base, setup.Username, setup.Password);
                UserPrincipal    principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, model.basic_uid);
                if (principal == null)
                {
                    return(new Result()
                    {
                        result = false, Message = "Account has not found"
                    });
                }
                principal.GivenName   = model.basic_givenname;
                principal.Surname     = model.basic_sn;
                principal.DisplayName = model.basic_displayname;
                if (!string.IsNullOrEmpty(model.basic_telephonenumber))
                {
                    principal.VoiceTelephoneNumber = model.basic_telephonenumber;
                }
                principal.EmailAddress      = model.basic_mail;
                principal.UserPrincipalName = model.basic_userprincipalname;

                principal.Save();

                DirectoryEntry d = principal.GetUnderlyingObject() as DirectoryEntry;
                d.Properties["pplid"].Value      = model.cu_pplid;
                d.Properties["employeeID"].Value = model.cu_jobcode;
                principal.Save();

                return(new Result()
                {
                    result = true
                });
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
        }
Exemplo n.º 11
0
        public Result DeleteUser(visual_fim_user model, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();
                using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
                {
                    string filter = "(&(|(objectClass=inetOrgPerson))(&(uid=" + model.basic_uid + ")))";

                    SearchResult      src = null;
                    DirectorySearcher nDS = new DirectorySearcher(entry);
                    nDS.SearchScope = SearchScope.Subtree;
                    nDS.Filter      = filter;
                    try
                    {
                        src = nDS.FindOne();
                        if (src != null)
                        {
                            DirectoryEntry removeEntry = src.GetDirectoryEntry();
                            DirectoryEntry parentEntry = removeEntry.Parent;
                            parentEntry.Children.Remove(removeEntry);
                            parentEntry.CommitChanges();
                            parentEntry.Close();
                            removeEntry.Close();
                        }
                        entry.Close();
                        return(new Result()
                        {
                            result = true
                        });
                    }
                    catch (Exception ex)
                    {
                        return(new Result()
                        {
                            result = false, Message = ex.Message
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
        }
Exemplo n.º 12
0
        public Result MoveOU(visual_fim_user model, SpuContext spucontext)
        {
            try
            {
                var setup    = spucontext.table_setup.FirstOrDefault();
                var oufilter = model.system_ou_lvl1.Replace("o=", "ou=") + ",";
                if (!string.IsNullOrEmpty(model.system_ou_lvl2))
                {
                    oufilter = model.system_ou_lvl2.Replace("o=", "ou=") + "," + oufilter;
                }
                if (!string.IsNullOrEmpty(model.system_ou_lvl3))
                {
                    oufilter = model.system_ou_lvl3.Replace("o=", "ou=") + "," + oufilter;
                }


                PrincipalContext context   = new PrincipalContext(ContextType.Domain, setup.Host, setup.Base, setup.Username, setup.Password);
                UserPrincipal    principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, model.basic_uid);
                if (principal == null)
                {
                    return(new Result()
                    {
                        result = false, Message = "Account has not found"
                    });
                }


                DirectoryEntry de = principal.GetUnderlyingObject() as DirectoryEntry;

                DirectoryEntry nde = new DirectoryEntry("LDAP://" + setup.Host + "/" + oufilter + setup.Base, setup.Username, setup.Password, AuthenticationTypes.FastBind);
                de.CommitChanges();
                de.MoveTo(nde);
                de.Close();
                nde.Close();
                return(new Result()
                {
                    result = true
                });
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
        }
Exemplo n.º 13
0
        public Result ChangePwd(visual_fim_user model, string pwd, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();
                using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
                {
                    string filter = "(&(|(objectClass=inetOrgPerson))(&(uid=" + model.basic_uid + ")))";

                    DirectorySearcher nDS = new DirectorySearcher(entry);
                    nDS.SearchScope = SearchScope.Subtree;
                    nDS.Filter      = filter;
                    SearchResult src = nDS.FindOne();
                    if (src != null)
                    {
                        DirectoryEntry de = src.GetDirectoryEntry();
                        //de.Invoke("SetPassword", new object[] { AppUtil.ManageNull(pwd) });
                        de.Properties["userPassword"].Value = AppUtil.ManageNull(pwd);
                        de.CommitChanges();
                        entry.Close();
                        de.Close();

                        return(new Result()
                        {
                            result = true
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
            return(new Result()
            {
                result = false
            });
        }
Exemplo n.º 14
0
        public Result ValidateCredentials(string samAccountName, string password, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();

                PrincipalContext context = new PrincipalContext(ContextType.Domain, setup.Host, setup.Base, setup.Username, setup.Password);
                var result = context.ValidateCredentials(samAccountName, password);
                return(new Result()
                {
                    result = result
                });
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
        }
Exemplo n.º 15
0
        public Result ChangePwd(visual_fim_user model, string pwd, SpuContext spucontext)
        {
            try
            {
                var setup    = spucontext.table_setup.FirstOrDefault();
                var oufilter = model.system_ou_lvl1.Replace("o=", "ou=") + ",";
                if (!string.IsNullOrEmpty(model.system_ou_lvl2))
                {
                    oufilter = model.system_ou_lvl2.Replace("o=", "ou=") + "," + oufilter;
                }
                if (!string.IsNullOrEmpty(model.system_ou_lvl3))
                {
                    oufilter = model.system_ou_lvl3.Replace("o=", "ou=") + "," + oufilter;
                }

                PrincipalContext context   = new PrincipalContext(ContextType.Domain, setup.Host, oufilter + setup.Base, setup.Username, setup.Password);
                UserPrincipal    principal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, model.basic_uid);
                if (principal == null)
                {
                    return(new Result()
                    {
                        result = false, Message = "Account has not found"
                    });
                }
                principal.SetPassword(pwd);
                principal.Save();

                return(new Result()
                {
                    result = true
                });
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
        }
Exemplo n.º 16
0
        public Task <List <Organization> > GetOrganizationLvl2(SpuContext spucontext, SystemConf conf, string oulvl1)
        {
            return(Task.Run(() =>
            {
                try
                {
                    //oulvl1 = oulvl1.Replace("|", "=");

                    if (oulvl1 == "o=internet" | oulvl1 == "o=tmpacc")
                    {
                        return new List <Organization>();
                    }

                    var oufilter = oulvl1 + ",";

                    var ous = new List <Organization>();
                    var setup = spucontext.table_setup.FirstOrDefault();
                    using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + oufilter + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
                    {
                        foreach (DirectoryEntry entryChild in entry.Children)
                        {
                            var ouname = entryChild.Name.Replace("o=", "").Replace("ou=", "");

                            var ou = new Organization();
                            ou.ouname = ouname;
                            ou.schemaname = entryChild.SchemaClassName.ToLower();
                            ou.path = entryChild.Path.ToLower();
                            ou.ou = entryChild.Name;//.Replace("=","|");
                            ous.Add(ou);
                        }
                    }
                    return ous.OrderBy(o => o.ouname).ToList();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error retrieving LDAP User", ex);
                }
            }));
        }
Exemplo n.º 17
0
        public Task <List <Organization> > GetOrganization(SpuContext spucontext, SystemConf conf, string oulvl1, string oulvl2 = null, string oulvl3 = null)
        {
            return(Task.Run(() =>
            {
                try
                {
                    var ous = new List <Organization>();
                    var setup = spucontext.table_setup.FirstOrDefault();

                    var oufilter = "";

                    if (!string.IsNullOrEmpty(oulvl3))
                    {
                        oufilter += oulvl3 + ",";
                    }
                    if (!string.IsNullOrEmpty(oulvl2))
                    {
                        oufilter += oulvl2 + ",";
                    }
                    oufilter += oulvl1 + ",";

                    using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + oufilter + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
                    {
                        foreach (DirectoryEntry entryChild in entry.Children)
                        {
                            var ouname = entryChild.Name.Replace("o=", "").Replace("ou=", "");
                            var schemaname = entryChild.SchemaClassName.ToLower();
                        }
                    }
                    return ous.OrderBy(o => o.ouname).ToList();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error retrieving LDAP User", ex);
                }
            }));
        }
Exemplo n.º 18
0
        private List <AdUser4> FindUser(string ou, string role, string text_search, setup setup, SpuContext spucontext)
        {
            var adusers = new List <AdUser4>();

            try
            {
                var oufilter = "ou=" + ou + ",";
                if (!string.IsNullOrEmpty(role))
                {
                    oufilter = "ou=" + role + "," + oufilter;
                }


                var context   = new PrincipalContext(ContextType.Domain, setup.Host, oufilter + setup.Base, setup.Username, setup.Password);
                var principal = new UserPrincipal(context);

                var searcher = new PrincipalSearcher(principal);
                var nDS      = (DirectorySearcher)searcher.GetUnderlyingSearcher();
                nDS.SearchScope = SearchScope.Subtree;
                var filter = new StringBuilder();
                filter.Append("(& (objectClass=user)(objectCategory=person)");
                if (!string.IsNullOrEmpty(text_search))
                {
                    filter.Append("(| (sAMAccountName=" + text_search + "*) (cn=" + text_search + "*) (sn=" + text_search + "*) (givenName=" + text_search + "*) (mail=" + text_search + "*) (mobile=" + text_search + "*) )");
                }
                filter.Append(")");
                nDS.Filter = filter.ToString();

                var src = nDS.FindAll();
                foreach (SearchResult sr in src)
                {
                    PropertyCollection propertyCollection = sr.GetDirectoryEntry().Properties;

                    var aduser = new AdUser4();
                    aduser.sAMAccountName     = getPropertyValue(propertyCollection, "sAMAccountName");
                    aduser.displayName        = getPropertyValue(propertyCollection, "displayName");
                    aduser.givenName          = getPropertyValue(propertyCollection, "givenName");
                    aduser.sn                 = getPropertyValue(propertyCollection, "sn");
                    aduser.cn                 = getPropertyValue(propertyCollection, "cn");
                    aduser.distinguishedName  = getPropertyValue(propertyCollection, "distinguishedName");
                    aduser.userAccountControl = getPropertyValue(propertyCollection, "userAccountControl");
                    aduser.mail               = getPropertyValue(propertyCollection, "mail");
                    adusers.Add(aduser);
                }
            }
            catch
            {
            }
            return(adusers);
        }
Exemplo n.º 19
0
        public Result MoveOU(visual_fim_user model, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();
                using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
                {
                    string filter = "(&(|(objectClass=inetOrgPerson))(&(uid=" + model.basic_uid + ")))";

                    DirectorySearcher nDS = new DirectorySearcher(entry);
                    nDS.SearchScope = SearchScope.Subtree;
                    nDS.Filter      = filter;
                    SearchResult src = nDS.FindOne();
                    if (src != null)
                    {
                        var system_ou_lvl1 = AppUtil.getOuName(model.system_ou_lvl1);
                        var system_ou_lvl2 = AppUtil.getOuName(model.system_ou_lvl2);
                        var system_ou_lvl3 = AppUtil.getOuName(model.system_ou_lvl3);

                        var nou = "";
                        if (!string.IsNullOrEmpty(model.system_ou_lvl3))
                        {
                            nou += "," + model.system_ou_lvl3.ToLower();
                        }
                        if (!string.IsNullOrEmpty(model.system_ou_lvl2))
                        {
                            nou += "," + model.system_ou_lvl2.ToLower();
                        }
                        if (!string.IsNullOrEmpty(model.system_ou_lvl1))
                        {
                            nou += "," + model.system_ou_lvl1.ToLower();
                        }

                        nou = nou.Substring(1);
                        DirectoryEntry de  = src.GetDirectoryEntry();
                        DirectoryEntry nde = new DirectoryEntry(setup.LDAPHost + nou + "," + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind);
                        if (model.system_idm_user_type != IDMUserType.temporary)
                        {
                            de.Properties["gecos"].Value = AppUtil.ManageNull(model.cu_gecos);
                        }
                        de.CommitChanges();
                        de.MoveTo(nde);
                        entry.Close();
                        de.Close();
                        nde.Close();
                        return(new Result()
                        {
                            result = true
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
            return(new Result()
            {
                result = false
            });
        }
Exemplo n.º 20
0
        public Result CreateUser(visual_fim_user model, SpuContext spucontext)
        {
            try
            {
                var setup    = spucontext.table_setup.FirstOrDefault();
                var oufilter = model.system_ou_lvl1.Replace("o=", "ou=") + ",";
                if (!string.IsNullOrEmpty(model.system_ou_lvl2))
                {
                    oufilter = model.system_ou_lvl2.Replace("o=", "ou=") + "," + oufilter;
                }
                if (!string.IsNullOrEmpty(model.system_ou_lvl3))
                {
                    oufilter = model.system_ou_lvl3.Replace("o=", "ou=") + "," + oufilter;
                }

                PrincipalContext context = new PrincipalContext(ContextType.Domain, setup.Host, oufilter + setup.Base, setup.Username, setup.Password);
                UserPrincipal    old     = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, model.basic_uid);
                if (old != null)
                {
                    return(new Result()
                    {
                        result = false, Message = "Account is duplicated"
                    });
                }
                //using (DirectoryEntry de = new DirectoryEntry("LDAP://" + setup.Host + "/" + oufilter + setup.Base, setup.Username, setup.Password, AuthenticationTypes.FastBind))
                //{
                //    DirectoryEntry newUser = de.Children.Add("CN=" + model.basic_uid, "user");
                //    newUser.Properties["samaccountname"].Value = model.basic_uid;
                //    //d.Properties["userPassword"].Value = Cryptography.decrypt(model.basic_userPassword);
                //    newUser.Properties["givenName"].Value = model.basic_givenname;
                //    newUser.Properties["sn"].Value = model.basic_sn;
                //    newUser.Properties["displayName"].Value = model.basic_displayname;
                //    newUser.Properties["telephoneNumber"].Value = model.basic_telephonenumber;
                //    newUser.Properties["mail"].Value = model.basic_mail;
                //    newUser.Properties["userPrincipalName"].Value = model.basic_userprincipalname;
                //    newUser.Properties["internetaccess"].Value = model.internetaccess;
                //    newUser.Properties["netcastaccess"].Value = model.netcastaccess;
                //    newUser.Properties["pplid"].Value = model.cu_pplid;

                //    newUser.Properties["employeeID"].Value = model.cu_jobcode;
                //    if (model.cu_nsaccountlock == "TRUE")
                //        newUser.Properties["userAccountControl"].Value = userAccountControl.DisablePasswordNotRequired;
                //    else
                //        newUser.Properties["userAccountControl"].Value = userAccountControl.EnablePasswordNotRequired;
                //    newUser.CommitChanges();
                //    //newUser.Invoke("SetPassword", Cryptography.decrypt(model.basic_userPassword));
                //    newUser.CommitChanges();
                //    de.CommitChanges();
                //}

                UserPrincipal principal = new UserPrincipal(context, model.basic_uid, Cryptography.decrypt(model.basic_userPassword), true);
                principal.SamAccountName = model.basic_uid;
                principal.GivenName      = model.basic_givenname;
                principal.Surname        = model.basic_sn;
                principal.DisplayName    = model.basic_displayname;
                if (!string.IsNullOrEmpty(model.basic_telephonenumber))
                {
                    principal.VoiceTelephoneNumber = model.basic_telephonenumber;
                }
                principal.EmailAddress      = model.basic_mail;
                principal.UserPrincipalName = model.basic_userprincipalname;

                principal.Save();

                DirectoryEntry d = principal.GetUnderlyingObject() as DirectoryEntry;
                d.Properties["internetaccess"].Value = model.internetaccess;
                d.Properties["netcastaccess"].Value  = model.netcastaccess;
                d.Properties["pplid"].Value          = model.cu_pplid;
                if (!string.IsNullOrEmpty(model.cu_jobcode))
                {
                    d.Properties["employeeID"].Value = model.cu_jobcode;
                }
                if (model.cu_nsaccountlock == "TRUE")
                {
                    d.Properties["userAccountControl"].Value = userAccountControl.DisablePasswordNotRequired;
                }
                else
                {
                    d.Properties["userAccountControl"].Value = userAccountControl.EnablePasswordNotRequired;
                }
                principal.Save();
                return(new Result()
                {
                    result = true
                });
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
        }
Exemplo n.º 21
0
        public async Task Invoke(HttpContext context, IUserProvider userProvider, IConfiguration config, SpuContext spucontext)
        {
            //if (!(userProvider.Initialized))
            //{
            //    //await userProvider.Create(context, config, spucontext);
            //}

            await next(context);
        }
Exemplo n.º 22
0
 public ReportController(SpuContext context, ILogger <ReportController> logger, ILoginServices loginServices, IUserProvider provider, ILDAPUserProvider providerldap, IOptions <SystemConf> conf) : base(context, logger, loginServices, conf, provider, providerldap)
 {
 }
Exemplo n.º 23
0
 public ProfileController(SpuContext context, ILogger <ProfileController> logger, ILoginServices loginServices, IUserProvider provider, ILDAPUserProvider providerldap, IOptions <SystemConf> conf) : base(context, logger, loginServices, conf, provider, providerldap)
 {
     this.provider = provider;
 }
Exemplo n.º 24
0
        public Result CreateUser(visual_fim_user model, SpuContext spucontext)
        {
            try
            {
                var setup = spucontext.table_setup.FirstOrDefault();
                using (DirectoryEntry entry = new DirectoryEntry(setup.LDAPHost + setup.LDAPBase, setup.LDAPUsername, setup.LDAPPassword, AuthenticationTypes.FastBind))
                {
                    string filter = "(&(|(objectClass=inetOrgPerson))(&(uid=" + model.basic_uid + ")))";

                    DirectorySearcher nDS = new DirectorySearcher(entry);
                    nDS.SearchScope = SearchScope.Subtree;
                    nDS.Filter      = filter;
                    SearchResult src = nDS.FindOne();
                    if (src == null)
                    {
                        var oufilter = model.system_ou_lvl1;
                        if (!string.IsNullOrEmpty(model.system_ou_lvl2))
                        {
                            oufilter = model.system_ou_lvl2 + "," + oufilter;
                        }
                        if (!string.IsNullOrEmpty(model.system_ou_lvl3))
                        {
                            oufilter = model.system_ou_lvl3 + "," + oufilter;
                        }

                        DirectoryEntry de = entry.Children.Find(oufilter);

                        //DirectoryEntry newUser = entry.Children.Add("CN=" + username, "person");
                        DirectoryEntry newUser = de.Children.Add("uid=" + model.basic_uid, "inetOrgPerson");
                        newUser.Properties["cn"].Value              = AppUtil.ManageNull(model.basic_cn);
                        newUser.Properties["sn"].Value              = AppUtil.ManageNull(model.basic_sn);
                        newUser.Properties["displayName"].Value     = AppUtil.ManageNull(model.basic_displayname);
                        newUser.Properties["givenName"].Value       = AppUtil.ManageNull(model.basic_givenname);
                        newUser.Properties["mail"].Value            = AppUtil.ManageNull(model.basic_mail);
                        newUser.Properties["telephoneNumber"].Value = AppUtil.ManageNull(model.basic_telephonenumber);
                        newUser.Properties["mobile"].Value          = AppUtil.ManageNull(model.basic_mobile);
                        newUser.Properties["userPassword"].Value    = AppUtil.ManageNull(Cryptography.decrypt(model.basic_userPassword));

                        newUser.CommitChanges();
                        newUser.RefreshCache();

                        /*chulaInfo*/
                        newUser.Properties["objectClass"].Add("chulaInfo");
                        newUser.Properties["jobcode"].Value                = AppUtil.ManageNull(model.cu_jobcode);
                        newUser.Properties["internetaccess"].Value         = AppUtil.ManageNull(model.internetaccess);
                        newUser.Properties["mailacceptinggeneralid"].Value = AppUtil.ManageNull(model.cu_mailacceptinggeneralid);
                        newUser.Properties["maildrop"].Value               = AppUtil.ManageNull(model.cu_maildrop);
                        newUser.Properties["netcastaccess"].Value          = AppUtil.ManageNull(model.netcastaccess);
                        newUser.Properties["pplid"].Value             = AppUtil.ManageNull(model.cu_pplid);
                        newUser.Properties["pwdchangedby"].Value      = AppUtil.ManageNull(model.cu_pwdchangedby);
                        newUser.Properties["pwdchangedloc"].Value     = AppUtil.ManageNull(model.cu_pwdchangedloc);
                        newUser.Properties["thcn"].Value              = AppUtil.ManageNull(model.cu_thcn);
                        newUser.Properties["thsn"].Value              = AppUtil.ManageNull(model.cu_thsn);
                        newUser.Properties["nsaccountlock"].Value     = AppUtil.ManageNull(model.cu_nsaccountlock);
                        newUser.Properties["CUexpire"].Value          = AppUtil.ManageNull(model.cu_CUexpire);
                        newUser.Properties["SCE-Package"].Value       = AppUtil.ManageNull(model.cu_sce_package);
                        newUser.Properties["userprincipalname"].Value = AppUtil.ManageNull(model.basic_userprincipalname);
                        newUser.Properties["thaidescription"].Value   = AppUtil.ManageNull(model.thaidescription);

                        if (model.system_idm_user_type != IDMUserType.temporary)
                        {
                            /*dspswuser*/
                            newUser.Properties["objectClass"].Add("dspswuser");

                            /*mirapointMailUser*/
                            newUser.Properties["objectClass"].Add("mirapointMailUser");
                            newUser.Properties["mailHost"].Value             = AppUtil.ManageNull(model.cu_mailhost);
                            newUser.Properties["miWmprefCharset"].Value      = AppUtil.ManageNull(model.mail_miWmprefCharset);
                            newUser.Properties["miWmprefEmailAddress"].Value = AppUtil.ManageNull(model.mail_miWmprefEmailAddress);
                            newUser.Properties["miWmprefFullName"].Value     = AppUtil.ManageNull(model.mail_miWmprefFullName);
                            newUser.Properties["miWmprefReplyOption"].Value  = AppUtil.ManageNull(model.mail_miWmprefReplyOption);
                            newUser.Properties["miWmprefTimezone"].Value     = AppUtil.ManageNull(model.mail_miWmprefTimezone);

                            /*mirapointUser*/
                            newUser.Properties["objectClass"].Add("mirapointUser");
                            //newUser.Properties["miMailExpirePolicy"].Value = AppUtil.ManageNull(model.miMailExpirePolicy);
                            //newUser.Properties["miMailQuota"].Value = AppUtil.ManageNull(model.miMailQuota);
                            //newUser.Properties["miService"].Value = AppUtil.ManageNull(model.miService);
                            //newUser.Properties["miDefaultJunkmailFilter"].Value = AppUtil.ManageNull(model.miDefaultJunkmailFilter);

                            /*ipUser*/
                            newUser.Properties["objectClass"].Add("ipUser");
                            newUser.Properties["inetCOS"].Value = AppUtil.ManageNull(model.unix_inetCOS);

                            /*cVPN3000-User-Authorization*/
                            newUser.Properties["objectClass"].Add("cVPN3000-User-Authorization");
                            //newUser.Properties["cVPN3000-Access-Hours"].Value = AppUtil.ManageNull(model.cVPN3000_Access_Hours);
                            //newUser.Properties["cVPN3000-Simultaneous-Logins"].Value = AppUtil.ManageNull(model.cVPN3000_Simultaneous_Logins);

                            /*shadowAccount*/
                            newUser.Properties["objectClass"].Add("shadowAccount");
                            newUser.Properties["uid"].Value = AppUtil.ManageNull(model.basic_uid);


                            /*mailrecipient*/
                            newUser.Properties["objectClass"].Add("mailrecipient");
                            newUser.Properties["mailRoutingAddress"].Value = AppUtil.ManageNull(model.cu_mailRoutingAddress);

                            /*radiusprofile*/
                            newUser.Properties["objectClass"].Add("radiusprofile");

                            /*posixaccount*/
                            newUser.Properties["objectClass"].Add("posixaccount");
                            newUser.Properties["gecos"].Value         = AppUtil.ManageNull(model.cu_gecos);
                            newUser.Properties["gidNumber"].Value     = AppUtil.ManageNull(model.unix_gidNumber);
                            newUser.Properties["homeDirectory"].Value = AppUtil.ManageNull(model.unix_homeDirectory);
                            newUser.Properties["loginShell"].Value    = AppUtil.ManageNull(model.unix_loginShell);
                            newUser.Properties["uidNumber"].Value     = AppUtil.ManageNull(model.unix_uidNumber);
                        }

                        newUser.CommitChanges();
                        entry.Close();
                        newUser.Close();

                        //newUser.Properties["dn"].Value = AppUtil.ManageNull(model.basic_dn);
                        //newUser.Properties["suntype"].Value = AppUtil.ManageNull(model.suntype);

                        return(new Result()
                        {
                            result = true
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                return(new Result()
                {
                    result = false, Message = ex.Message
                });
            }
            return(new Result()
            {
                result = false
            });
        }