예제 #1
0
        public void GrantPermission(string mObject, string mOperation, string[] mRoles)
        {
            if (_App == null)
            {
                return;
            }
            string HQL     = "from role r where r.AppID = :AppID AND r.name in ({0})";
            string ParaStr = ":" + string.Join(",:", mRoles);

            HQL = string.Format(HQL, ParaStr);
            SQLParam[] paramList = new SQLParam[mRoles.Length + 1];
            paramList[0] = new SQLParam("AppID", _App.AppID);
            for (int i = 0; i < mRoles.Length; i++)
            {
                paramList[i + 1] = new SQLParam(mRoles[i], mRoles[i]);
            }
            List <role> RoleLst = RoleSrv.GetbyHQuery(HQL, paramList);

            if (RoleLst == null || RoleLst.Count == 0)
            {
                return;
            }
            //Grant permission
            permission TempPermission = PermissionSrv.GetPermission(mObject, mOperation, _App.AppID);

            if (TempPermission == null)
            {
                objectRbac tempObject    = ObjectSrv.GetByName(mObject, _App.AppID);
                operation  tempOperation = OperationSrv.GetByName(mOperation, _App.AppID);
                if (tempObject == null || tempOperation == null)
                {
                    return;
                }
                TempPermission            = new permission();
                TempPermission.AppID      = _App.AppID;
                TempPermission.name       = tempObject.name + ":" + tempOperation.name;
                TempPermission.ObjectRBAC = tempObject;
                TempPermission.Operation  = tempOperation;
                TempPermission.Roles      = new List <role>();
                foreach (role r in RoleLst)
                {
                    TempPermission.Roles.Add(r);
                }
                PermissionSrv.CreateNew(TempPermission);
                PermissionSrv.CommitChanges();
            }

            else
            {
                foreach (role r in RoleLst)
                {
                    if (!TempPermission.Roles.Contains(r))
                    {
                        TempPermission.Roles.Add(r);
                    }
                }
                PermissionSrv.CommitChanges();
            }
        }
예제 #2
0
        private operation Mapping(operation mOperation)
        {
            operation tempOperation;

            if (mOperation.operationid > 0)
            {
                tempOperation = OperationSrv.Getbykey(mOperation.operationid);
            }
            else
            {
                tempOperation = OperationSrv.GetByName(mOperation.name, App.AppID);
            }
            return(tempOperation);
        }