Example #1
0
 public bool DropRole(string roleName)
 {
     try {
         return(SystemSession.Access().UserManager.DropRole(roleName));
     } finally {
         RevokeAllGrantsFrom(roleName);
     }
 }
Example #2
0
 public void Revoke(DbObjectType objectType, ObjectName objectName, string grantee, Privileges privileges,
                    bool grantOption = false)
 {
     try {
         var revoker = Session.User.Name;
         var grant   = new Grant(privileges, objectName, objectType, grantee, revoker, grantOption);
         SystemSession.Access().PrivilegeManager.Revoke(grant);
     } finally {
         var key = new GrantCacheKey(grantee, objectType, objectName.FullName, grantOption, false);
         PrivilegesCache.Remove(key);
     }
 }
Example #3
0
        public bool DeleteUser(string userName)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("userName");
            }

            try {
                return(SystemSession.Access().UserManager.DropUser(userName));
            } finally {
                RevokeAllGrantsFrom(userName);
            }
        }
Example #4
0
        public void CreateUser(string userName, string identification, string token)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("userName");
            }
            if (String.IsNullOrEmpty(identification))
            {
                throw new ArgumentNullException("identification");
            }
            if (String.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException("token");
            }

            if (String.Equals(userName, User.PublicName, StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException(
                          String.Format("User name '{0}' is reserved and cannot be registered.", User.PublicName), "userName");
            }

            if (userName.Length <= 1)
            {
                throw new ArgumentException("User name must be at least one character.");
            }
            if (token.Length <= 1)
            {
                throw new ArgumentException("The password must be at least one character.");
            }

            var c = userName[0];

            if (c == '#' || c == '@' || c == '$' || c == '&')
            {
                throw new ArgumentException(
                          String.Format("User name '{0}' is invalid: cannot start with '{1}' character.", userName, c), "userName");
            }

            var identifier = FindIdentifier(identification);

            if (identifier == null)
            {
                throw new ArgumentException(String.Format("User identification method '{0}' cannot be found", identification));
            }

            var userId   = identifier.CreateIdentification(token);
            var userInfo = new UserInfo(userName, userId);

            SystemSession.Access().UserManager.CreateUser(userInfo);
        }
Example #5
0
        public bool Authenticate(string username, string password)
        {
            try {
                if (String.IsNullOrEmpty(username))
                {
                    throw new ArgumentNullException("username");
                }
                if (String.IsNullOrEmpty(password))
                {
                    throw new ArgumentNullException("password");
                }

                var userInfo = SystemSession.Access().UserManager.GetUser(username);

                if (userInfo == null)
                {
                    return(false);
                }

                var userId     = userInfo.Identification;
                var identifier = FindIdentifier(userId.Method);

                if (identifier == null)
                {
                    throw new SecurityException(String.Format("The user '{0}' was identified by '{1}' but the identifier cannot be found in the context.", userInfo.Name, userId.Method));
                }

                if (!identifier.VerifyIdentification(password, userId))
                {
                    return(false);
                }

                // Successfully authenticated...
                return(true);
            } catch (SecurityException) {
                throw;
            } catch (Exception ex) {
                throw new SecurityException("Could not authenticate user.", ex);
            }
        }
Example #6
0
        public void AlterUserPassword(string username, string identification, string token)
        {
            if (String.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException("username");
            }
            if (String.IsNullOrEmpty(identification))
            {
                throw new ArgumentNullException("identification");
            }

            var identifier = FindIdentifier(identification);

            if (identifier == null)
            {
                throw new ArgumentException(String.Format("User identification method '{0}' cannot be found", identification));
            }

            var userId   = identifier.CreateIdentification(token);
            var userInfo = new UserInfo(username, userId);

            SystemSession.Access().UserManager.AlterUser(userInfo);
        }
Example #7
0
 public void CreateUser(UserInfo userInfo)
 {
     SystemSession.Access().UserManager.CreateUser(userInfo);
 }
Example #8
0
 public bool UserExists(string userName)
 {
     return(SystemSession.Access().UserManager.UserExists(userName));
 }
Example #9
0
 public UserStatus GetUserStatus(string userName)
 {
     return(SystemSession.Access().UserManager.GetUserStatus(userName));
 }
Example #10
0
 public void SetUserStatus(string username, UserStatus status)
 {
     SystemSession.Access().UserManager.SetUserStatus(username, status);
 }
Example #11
0
 public void SetRoleAdmin(string roleName, string userName)
 {
     SystemSession.Access().UserManager.SetRoleAdmin(roleName, userName);
 }
Example #12
0
 public bool RoleExists(string roleName)
 {
     return(SystemSession.Access().UserManager.RoleExists(roleName));
 }
Example #13
0
 public void CreateRole(string roleName)
 {
     SystemSession.Access().UserManager.CreateRole(roleName);
 }
Example #14
0
 public void CreateRoutine(RoutineInfo routineInfo)
 {
     SystemSession.Access().CreateObject(routineInfo);
 }
Example #15
0
 public bool DeleteRoutine(ObjectName routineName)
 {
     return(SystemSession.Access().DropObject(DbObjectType.Routine, routineName));
 }