public void AddRole(role mRole)
 {
     mRole.AppID  = App.AppID;
     RoleSrv.CreateNew(mRole);
     //throw new Exception("This method have not Implement.");
 }
Example #2
0
 public override void CreateRole(string roleName)
 {
     if (_App == null) return;
     role mRole = RoleSrv.GetByName(roleName, _App.AppID);
     if (mRole == null)
     {
         mRole = new role();
         mRole.AppID = _App.AppID;
         mRole.name = roleName;
         RoleSrv.CreateNew(mRole);
         RoleSrv.CommitChanges();
     }
 }
 public void AddDescendant(role r_asc, role r_desc)
 {
     throw new Exception("This method have not Implement.");
 }
 public void AddInheritance(role r_asc, role r_desc)
 {
     throw new Exception("This method have not Implement.");
 }
 private role Mapping(role mRole)
 {
     role TempRole = null;
     if (mRole.roleid > 0) TempRole = RoleSrv.Getbykey(mRole.roleid);
     else
     {
         TempRole =RoleSrv.GetByName(mRole.name, App.AppID);
     }
     return TempRole;
 }
 public void AddActiveRole(user mUser, session mSession, role mRole)
 {
     throw new Exception("This method have not Implement.");
 }
 public IList<operation> RoleOperationsOnObject(role mRole, objectRbac mObject)
 {
     role TempRole = Mapping(mRole);
     objectRbac TempObject = Mapping(mObject);
     if(TempRole.AppID != App.AppID || TempObject.AppID != App.AppID) return null ;
     return (from per in TempRole.Permissions where  (per.ObjectRBAC == TempObject) select per.Operation).ToList<operation>();
 }
 public IList<permission> RolePermissions(role mRole)
 {
     role TempRole = Mapping(mRole);
     return TempRole.Permissions;
 }
        public void RevokePermission(operation mOperation, objectRbac mObject, role mRole)
        {
            role TempRole = Mapping(mRole);
            if (TempRole == null) throw new Exception("Role Does not exist in system.");

            objectRbac tempObject = Mapping(mObject);
            operation tempOperation = Mapping(mOperation);
            if (tempOperation == null || tempObject == null) return;
            //Grant permission
            string hsql = "from permission per where per.ObjectRBAC = :ObjectRBAC AND  per.Operation = :Operation ";

            List<permission> _lst = PermissionSrv.GetbyHQuery(hsql, new SQLParam("ObjectRBAC", tempObject), new SQLParam("ObjectRBAC", tempOperation));
            permission TempPermission = (_lst == null || _lst.Count == 0) ? null : _lst[0];

            if (TempPermission != null)
            {
                if (TempRole.Permissions.Contains(TempPermission))
                {
                    TempRole.Permissions.Remove(TempPermission);
                    RoleSrv.CommitChanges();
                }
            }
        }
        public void GrantPermission(objectRbac mObject, operation mOperation, role mRole)
        {
            role TempRole = Mapping(mRole);
            if (TempRole == null) throw new Exception("Role Does not exist in system.");

            objectRbac tempObject = Mapping(mObject);
            operation tempOperation = Mapping(mOperation);

            //Grant permission
            string hsql = "from permission per where per.ObjectRBAC = :ObjectRBAC AND  per.Operation = :Operation ";

            List<permission> _lst = PermissionSrv.GetbyHQuery(hsql, new SQLParam("ObjectRBAC", tempObject), new SQLParam("ObjectRBAC", tempOperation));
            permission TempPermission = (_lst == null || _lst.Count == 0) ? null : _lst[0];
            if (TempPermission == null)
            {
                TempPermission = new permission();
                TempPermission.AppID = App.AppID;
                TempPermission.name = tempObject.name + ":" + tempOperation.name;
                TempPermission.ObjectRBAC = tempObject;
                TempPermission.Operation = tempOperation;
                PermissionSrv.CreateNew(TempPermission);
                TempRole.Permissions.Add(TempPermission);
                RoleSrv.CommitChanges();
            }

            else
            {
                if (!TempRole.Permissions.Contains(TempPermission))
                {
                    TempRole.Permissions.Add(TempPermission);
                    RoleSrv.CommitChanges();
                }
            }
        }
 public void DeleteRole(role mRole)
 {
     //mapping Roles
     role TempRole = Mapping(mRole);
     if (TempRole != null)
     {
         RoleSrv.Delete(TempRole);
         RoleSrv.CommitChanges();
     }
 }
        public void DeassignUser(user mUser, role mRole)
        {
            user TempUser = Mapping(mUser);
            if (TempUser == null) throw new Exception("User does not exist in system.");

            role TempRole = Mapping(mRole);
            if (TempRole == null) throw new Exception("Role does not exist in system.");

            if (TempUser.Roles.Contains(TempRole)) TempUser.Roles.Remove(TempRole);
            UserSrv.CommitChanges();
        }
 public IList<user> AuthorizedUsers(role mRole)
 {
     role TempRole = Mapping(mRole);
     if (TempRole != null)
     {
         return TempRole.Users;
     }
     else return null;
 }