Ejemplo n.º 1
0
 public bool DropRole(string roleName)
 {
     try {
         return(SystemSession.Access().UserManager.DropRole(roleName));
     } finally {
         RevokeAllGrantsFrom(roleName);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
 public void CreateUser(UserInfo userInfo)
 {
     SystemSession.Access().UserManager.CreateUser(userInfo);
 }
Ejemplo n.º 8
0
 public bool UserExists(string userName)
 {
     return(SystemSession.Access().UserManager.UserExists(userName));
 }
Ejemplo n.º 9
0
 public UserStatus GetUserStatus(string userName)
 {
     return(SystemSession.Access().UserManager.GetUserStatus(userName));
 }
Ejemplo n.º 10
0
 public void SetUserStatus(string username, UserStatus status)
 {
     SystemSession.Access().UserManager.SetUserStatus(username, status);
 }
Ejemplo n.º 11
0
 public void SetRoleAdmin(string roleName, string userName)
 {
     SystemSession.Access().UserManager.SetRoleAdmin(roleName, userName);
 }
Ejemplo n.º 12
0
 public bool RoleExists(string roleName)
 {
     return(SystemSession.Access().UserManager.RoleExists(roleName));
 }
Ejemplo n.º 13
0
 public void CreateRole(string roleName)
 {
     SystemSession.Access().UserManager.CreateRole(roleName);
 }
Ejemplo n.º 14
0
 public void CreateRoutine(RoutineInfo routineInfo)
 {
     SystemSession.Access().CreateObject(routineInfo);
 }
Ejemplo n.º 15
0
 public bool DeleteRoutine(ObjectName routineName)
 {
     return(SystemSession.Access().DropObject(DbObjectType.Routine, routineName));
 }