コード例 #1
0
ファイル: Manager.RbacRole.cs プロジェクト: radtek/aarbac
        public Framework.RbacRole AddOrUpdate(Framework.RbacRole role)
        {
            RbacMetaData rbacMetaData = new RbacMetaData();

            rbacMetaData.ValidateAndGetRbacXmlDocument(role.MetaDataRbac);
            if (rbacMetaData.XmlValidationErrors.Count > 0)
            {
                RbacException.Raise("Cannot save role meta data, XML validation failed!"
                                    + Environment.NewLine
                                    + rbacMetaData.XmlValidationErrors.ToLine());
            }

            rbacMetaData.ValidateAndGetEntitlementXmlDocument(role.MetaDataEntitlements);
            if (rbacMetaData.XmlValidationErrors.Count > 0)
            {
                RbacException.Raise("Cannot save role entitlement meta data, XML validation failed!"
                                    + Environment.NewLine
                                    + rbacMetaData.XmlValidationErrors.ToLine());
            }

            RbacRole dbRole = null;

            try
            {
                using (var ctx = new Entities(ConnectionString))
                {
                    dbRole = ctx.RbacRoles.Where(r => r.RoleId == role.RoleId).SingleOrDefault();
                    if (dbRole == null) //try with name
                    {
                        dbRole = ctx.RbacRoles.Where(r => r.Name.Equals(role.Name, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
                    }

                    if (dbRole == null)
                    {
                        RbacRole newRole = Assign(role);
                        newRole.Version = 1;
                        dbRole          = ctx.RbacRoles.Add(newRole);
                    }
                    else
                    {
                        dbRole.Name                 = role.Name;
                        dbRole.Description          = role.Description;
                        dbRole.MetaDataRbac         = GetEncryptedString(role.MetaDataRbac);
                        dbRole.MetaDataEntitlements = GetEncryptedString(role.MetaDataEntitlements);
                        dbRole.Version              = role.Version + 1;
                    }

                    ctx.SaveChanges();
                }
            }
            catch (DbEntityValidationException e)
            {
                RaiseError(e);
            }
            catch (DbUpdateException dbe)
            {
                RaiseError(dbe);
            }
            return(Assign(dbRole));
        }
コード例 #2
0
 public Framework.RbacRole GetRole(string roleName)
 {
     Framework.RbacRole role = null;
     using (var ctx = new Entities(ConnectionString))
     {
         RbacRole dbRbacRole = ctx.RbacRoles.Where(r => r.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase)).SingleOrDefault();
         if (dbRbacRole != null)
         {
             role = Assign(dbRbacRole);
         }
     }
     return(role);
 }
コード例 #3
0
 public Framework.RbacRole GetRole(int roleId)
 {
     Framework.RbacRole role = null;
     using (var ctx = new Entities(ConnectionString))
     {
         RbacRole dbRbacRole = ctx.RbacRoles.Where(r => r.RoleId == roleId).SingleOrDefault();
         if (dbRbacRole != null)
         {
             role = Assign(dbRbacRole);
         }
     }
     return(role);
 }
コード例 #4
0
ファイル: Manager.cs プロジェクト: crazyants/aarbac
        private RbacRole Assign(Framework.RbacRole rbacRole)
        {
            if (rbacRole == null)
            {
                return(null);
            }

            RbacRole newRole = new RbacRole();

            newRole.RoleId               = rbacRole.RoleId;
            newRole.RbacId               = rbacRole.RbacId;
            newRole.Name                 = rbacRole.Name;
            newRole.Description          = rbacRole.Description;
            newRole.MetaDataRbac         = GetEncryptedString(rbacRole.MetaDataRbac);
            newRole.MetaDataEntitlements = GetEncryptedString(rbacRole.MetaDataEntitlements);
            newRole.Version              = rbacRole.Version;
            return(newRole);
        }
コード例 #5
0
ファイル: Manager.cs プロジェクト: crazyants/aarbac
        private Framework.RbacRole Assign(RbacRole rbacRole)
        {
            if (rbacRole == null)
            {
                return(null);
            }

            Framework.RbacRole newRbacRole = new Framework.RbacRole();
            newRbacRole.RbacId      = rbacRole.RbacId;
            newRbacRole.RoleId      = rbacRole.RoleId;
            newRbacRole.Name        = rbacRole.Name;
            newRbacRole.Description = rbacRole.Description;
            if (!HideSensitiveData)
            {
                newRbacRole.MetaDataRbac         = GetDecryptedString(rbacRole.MetaDataRbac);
                newRbacRole.MetaDataEntitlements = GetDecryptedString(rbacRole.MetaDataEntitlements);
            }
            newRbacRole.Version = (int)rbacRole.Version;
            return(newRbacRole);
        }