Inheritance: PermissionSet
 internal static string GetEntriesToString(SecurityEntry[] entries)
 {
     return String.Join("\r\n", entries.Select(x => x.ToString()).ToArray());
 }
Beispiel #2
0
        protected internal override void SetPermission(SecurityEntry entry)
        {
            var sql = new StringBuilder();

            if (entry.AllowBits + entry.DenyBits == 0)
            {
                sql.Append("DELETE FROM SecurityEntries WHERE DefinedOnNodeId = @NodeId AND PrincipalId = @PrincipalId AND IsInheritable = @IsInheritable");
            }
            else
            {
                sql.AppendLine("IF NOT EXISTS (SELECT SecurityEntryId FROM dbo.SecurityEntries WHERE DefinedOnNodeId = @NodeId AND PrincipalId = @PrincipalId AND IsInheritable = @IsInheritable)");
                sql.AppendLine("    INSERT INTO dbo.SecurityEntries (DefinedOnNodeId, PrincipalId, IsInheritable) VALUES (@NodeId, @PrincipalId, @IsInheritable)");
                sql.AppendLine("UPDATE SecurityEntries SET");

                for (int i = 0; i < ActiveSchema.PermissionTypes.Count; i++)
                {
                    var value = (byte)0;
                    var mask = 1<<i;
                    if((entry.DenyBits & mask)!=0)
                        value = (byte)2;
                    else if((entry.AllowBits & mask)!=0)
                        value = (byte)1;
                    if (i > 0)
                        sql.AppendLine(",");
                    sql.Append("    PermissionValue").Append(i + 1).Append(" = ").Append(value);
                }
                sql.AppendLine();

                sql.AppendLine("WHERE DefinedOnNodeId = @NodeId AND PrincipalId = @PrincipalId AND IsInheritable = @IsInheritable");
            }

            SqlProcedure cmd = null;
            try
            {
                cmd = new SqlProcedure { CommandText = sql.ToString(), CommandType = CommandType.Text };
                cmd.Parameters.Add("@PrincipalId", SqlDbType.Int).Value = entry.PrincipalId;
                cmd.Parameters.Add("@NodeId", SqlDbType.Int).Value = entry.DefinedOnNodeId;
                cmd.Parameters.Add("@IsInheritable", SqlDbType.TinyInt).Value = entry.Propagates ? (byte)1 : (byte)0;
                cmd.ExecuteNonQuery();
            }
            finally
            {
                cmd.Dispose();
            }

        }
 protected internal override void SetPermission(SecurityEntry entry)
 {
     WriteLog(MethodInfo.GetCurrentMethod(), entry);
     base.SetPermission(entry);
 }