Example #1
0
        /// <summary>
        /// This instance is allowed to call only from test bed - todo security
        /// </summary>
        /// <param name="userName">The logged in user name</param>
        /// <param name="rbacName">The overridden rbac name, empty will use user's default</param>
        /// <param name="roleName">The overriden role name, empty will use user's default</param>
        public Rbac(string userName, string rbacName, string roleName)
        {
            //no cache will be implemented

            DataManager.Manager manager = new DataManager.Manager(false);
            RbacUser            user    = new RbacUser(userName);

            if (!string.IsNullOrEmpty(roleName))
            {
                user.Role = new RbacRole(roleName);  //override role
            }
            if (user.Role == null)
            {
                RbacException.Raise(string.Format("The role '{0}' is not found!", roleName), RbacExceptionCategories.Repository);
            }

            Rbac dbRbac = null;

            if (!string.IsNullOrEmpty(rbacName))
            {
                dbRbac = manager.GetRbac(rbacName);     //override rbac
            }
            else
            {
                dbRbac = manager.GetRbac(user.Role.RbacId);
            }

            if (dbRbac == null)
            {
                RbacException.Raise(string.Format("The rbac '{0}' was not defined yet!", rbacName), RbacExceptionCategories.Repository);
            }

            dbRbac.User = user;
            Assign(dbRbac);
        }
        public static RbacUser CreateUser(string userName, string fullName, string email, string password, RbacRole role)
        {
            RbacUser user = new RbacUser(userName, fullName, email, role);

            ChangePassword(user.UserName, RbacCache.TempPassword, password);
            return(user);
        }
Example #3
0
 public static void AddParameter(this RbacUser user, string paramName, string paramValue)
 {
     if (user != null)
     {
         RbacParameter newParam = new DataManager.Manager(false).AddOrUpdateUserParameter(user.UserId, paramName, paramValue);
         user.Parameters.Add(newParam.Name, newParam.Value);
     }
 }
        public static void Save(RbacRegisterUser user)
        {
            RbacUser dbUser = GetUser(user.UserName);

            dbUser.FullName = user.FullName;
            dbUser.Email    = user.Email;
            dbUser.Role     = GetRole(user.RoleId);
            new DataManager.Manager().AddOrUpdate(dbUser);
        }
Example #5
0
 private void Assign(RbacUser user)
 {
     this.UserId   = user.UserId;
     this.UserName = user.UserName;
     this.FullName = user.FullName;
     this.Email    = user.Email;
     this.Role     = user.Role;
     this.Role.ParseMetaData();
 }
Example #6
0
        public RbacUser(string userName, string fullName, string email, RbacRole role, string password = null)
        {
            RbacUser newUser = new RbacUser();

            newUser.UserName = userName;
            newUser.FullName = fullName;
            newUser.Email    = email;
            newUser.Role     = role;
            newUser          = new DataManager.Manager(false).AddOrUpdate(newUser);
            Assign(newUser);
            Parameters = new ObservableDictionary <string, string>();
        }
Example #7
0
        public RbacUser Authenticate(string userName, string password)
        {
            RbacUser user = GetUser(userName);

            if (user == null)
            {
                RbacException.Raise("User name was not found!");
            }

            user = new DataManager.Manager().Authenticate(userName, password);
            if (user == null)
            {
                RbacException.Raise("Incorrect password!");
            }

            return(user);
        }
Example #8
0
        public Rbac(string userName)
        {
            Rbac rbacFromCache = RbacCache.Instance.GetContext(userName);

            if (rbacFromCache == null)
            {
                RbacUser user   = new RbacUser(userName);
                Rbac     dbRbac = new DataManager.Manager(false).GetRbac(user.Role.RbacId);
                dbRbac.User = user;
                Assign(dbRbac);
                RbacCache.Instance.Contexts.Add(userName, this);
            }
            else
            {
                Assign(rbacFromCache);
            }
        }
Example #9
0
 public static RbacUser PopulateRole(this RbacUser user)
 {
     return(new DataManager.Manager(false).GetUser(user.UserId));
 }
Example #10
0
 public static void Delete(RbacUser rbacUser)
 {
     new DataManager.Manager().Delete(rbacUser);
 }