public ILdapUser CastLdapUser(UserPrincipal userPrincipal)
        {
            var _user = new LdapUser();
            
            _user.Guid = userPrincipal.Guid.Value;
            _user.Sid = userPrincipal.Sid.ToString();
            _user.Name = userPrincipal.Name;
            _user.SamAccountName = userPrincipal.SamAccountName;
            _user.DisplayName = userPrincipal.DisplayName;
            _user.Description = userPrincipal.Description;
            _user.DistingueshedName = userPrincipal.DistinguishedName;
            _user.UserPrincipalName = userPrincipal.UserPrincipalName;
            _user.EmployeeId = userPrincipal.EmployeeId;
            _user.Email = userPrincipal.EmailAddress;

            DirectoryEntry _userDE = GetDirectoryEntry(userPrincipal);
            if (_userDE != null)
            {
                var _whenCreated = GetProperty(_userDE, "whenCreated");
                _user.Created = (DateTime)GetProperty(_userDE, "whenCreated");

                var _whenChanged = GetProperty(_userDE, "whenChanged");
                _user.Updated = (DateTime)GetProperty(_userDE, "whenChanged");
            }


            return _user;
        }
        private UserPrincipal Get(LdapUser user, PrincipalContext context)
        {
            var _identity = GetIdentityType(user);

            if (_identity != null)
            {
                UserPrincipal _user = UserPrincipal.FindByIdentity(context, _identity.Type, _identity.Value);
                return _user;
            }
            else
            {
                throw new ArgumentNullException("Object identity not defined");
            }
        }
Esempio n. 3
0
 public User CastDboUser(User user, LdapUser ldapUser)
 {
     return new User()
     {
         Login = user.Login,
         Guid = ldapUser.Guid != Guid.Empty ? ldapUser.Guid : Guid.NewGuid(),
         LdapSid = ldapUser.Sid,
         //Name = user.Name ?? string.Format("{0} {1} {2} ({3})", user.Surname, user.GivenName, user.MiddleName, user.Login),
         GivenName = user.GivenName,
         Surname = user.Surname,
         //DisplayName = user.DisplayName ?? string.Format("{0} {1} {2}", user.Surname, user.GivenName, user.MiddleName),
         Description = user.Description,
         //Domain = WorkflowManager.User. dbo.Domain.GetByName(user.Domain),
         Info = user.Info
     };
 }
        public void Create_LdapUser()
        {
            // arrage
            ILdapUser _user = new LdapUser()
            {
                Name = "Test Ldap User (_test_ldap_user)",
                GivenName = "Ldap User",
                Surname = "Test",
                DisplayName = "Test Ldap User",
                SamAccountName = "_test_ldap_user"
            };
            

            // action
            var _result = LdapUserManager.Instance.Create(_user, "P@$$w0rd", null);


            // assert
            Assert.IsNotNull(_result);
        }
        public void UpdateModel(LdapUser user, UserPrincipal userPrincipal)
        {
            user.Guid = userPrincipal.Guid.Value;
            user.Sid = userPrincipal.Sid.ToString();
            user.Name = userPrincipal.Name;
            user.SamAccountName = userPrincipal.SamAccountName;
            user.DisplayName = userPrincipal.DisplayName;
            user.Description = userPrincipal.Description;
            user.DistingueshedName = userPrincipal.DistinguishedName;
            user.UserPrincipalName = userPrincipal.UserPrincipalName;
            user.EmployeeId = userPrincipal.EmployeeId;
            user.Email = userPrincipal.EmailAddress;

            DirectoryEntry _userDE = GetDirectoryEntry(userPrincipal);
            if (_userDE != null)
            {
                var _whenCreated = GetProperty(_userDE, "whenCreated");
                user.Created = (DateTime)GetProperty(_userDE, "whenCreated");

                var _whenChanged = GetProperty(_userDE, "whenChanged");
                user.Updated = (DateTime)GetProperty(_userDE, "whenChanged");
            }

        }
 public void UpdateModel(LdapUser user, DirectoryEntry userDE)
 {
     
 }