public void InstallObject(string mObject, string[] mOperations) { if (_App == null) { return; } IoperationService OperationSrv = new operationService(SessionFactoryConfigPath); IobjectService ObjectSrv = new objectService(SessionFactoryConfigPath); IpermissionService PermissionSrv = new permissionService(SessionFactoryConfigPath); objectRbac tempObject = ObjectSrv.GetByName(mObject, _App.AppID); if (tempObject != null) { return; } tempObject = new objectRbac(); tempObject.AppID = _App.AppID; tempObject.name = mObject; ObjectSrv.CreateNew(tempObject); foreach (string ope in mOperations) { operation TempOpe = OperationSrv.GetByName(ope, _App.AppID); if (TempOpe == null) { TempOpe = new operation(); TempOpe.name = ope; TempOpe.AppID = _App.AppID; OperationSrv.CreateNew(TempOpe); } permission TempPermission = new permission(); TempPermission.AppID = _App.AppID; TempPermission.name = tempObject.name + ":" + TempOpe.name; TempPermission.ObjectRBAC = tempObject; TempPermission.Operation = TempOpe; PermissionSrv.CreateNew(TempPermission); } PermissionSrv.CommitChanges(); }
public void GrantPermission(string mObject, string mOperation, string[] mRoles) { if (_App == null) { return; } IroleService RoleSrv = new roleService(SessionFactoryConfigPath); 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; } IoperationService OperationSrv = new operationService(SessionFactoryConfigPath); IobjectService ObjectSrv = new objectService(SessionFactoryConfigPath); IpermissionService PermissionSrv = new permissionService(SessionFactoryConfigPath); //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(); } }