Skip to content

Commit

Permalink
Obsolete PrincipalPermissionAttribute ctor as error (#37536)
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabYourPitchforks authored Jun 18, 2020
1 parent 42da124 commit 997539e
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 10 deletions.
17 changes: 17 additions & 0 deletions docs/project/list-of-obsoletions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
List of Obsoletions
==================

Per https://github.com/dotnet/designs/blob/master/accepted/2020/better-obsoletion/better-obsoletion.md, we now have a strategy in place for marking existing APIs as `[Obsolete]`. This takes advantage of the new diagnostic id and URL template mechanisms introduced to `ObsoleteAttribute` in .NET 5.

When obsoleting an API, use the diagnostic ID `MSLIB####`, where _\#\#\#\#_ is the next four-digit identifier in the sequence, and add it to the list below. This helps us maintain a centralized location of all APIs that were obsoleted using this mechanism.

The URL template we use for obsoletions is `https://aka.ms/dotnet-warnings/{0}`.

Currently the identifiers `MSLIB0001` through `MSLIB0999` are carved out for obsoletions. If we wish to introduce analyzer warnings not related to obsoletion in the future, we should begin at a different range, such as `MSLIB2000`.

## Current obsoletions (`MSLIB0001` - `MSLIB0999`)

| Diagnostic ID | Description |
| :--------------- | :---------- |
| __`MSLIB0001`__ | (Reserved for `Encoding.UTF7`.) |
| __`MSLIB0002`__ | `PrincipalPermissionAttribute` is not honored by the runtime and must not be used. |
3 changes: 2 additions & 1 deletion eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@
<Rule Id="CA2237" Action="None" /> <!-- Mark ISerializable types with serializable -->
<Rule Id="CA2241" Action="Warning" /> <!-- Provide correct arguments to formatting methods -->
<Rule Id="CA2242" Action="Warning" /> <!-- Test for NaN correctly -->
<Rule Id="CA2243" Action="Warning" /> <!-- Attribute string literals should parse correctly -->
<!-- CA2243 temporarily disabled: https://github.com/dotnet/roslyn-analyzers/issues/3635 -->
<Rule Id="CA2243" Action="None" /> <!-- Attribute string literals should parse correctly -->
<Rule Id="CA2244" Action="None" /> <!-- Do not duplicate indexed element initializations -->
<Rule Id="CA2245" Action="Warning" /> <!-- Do not assign a property to itself. -->
<Rule Id="CA2246" Action="None" /> <!-- Assigning symbol and its member in the same statement. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,9 @@ public void FromXml(System.Security.SecurityElement elem) { }
[System.AttributeUsageAttribute(System.AttributeTargets.Class | System.AttributeTargets.Method, AllowMultiple=true, Inherited=false)]
public sealed partial class PrincipalPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
{
#if CAS_OBSOLETIONS
[System.ObsoleteAttribute("PrincipalPermissionAttribute is not honored by the runtime and must not be used.", true, DiagnosticId = "MSLIB0002", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public PrincipalPermissionAttribute(System.Security.Permissions.SecurityAction action) : base (default(System.Security.Permissions.SecurityAction)) { }
public bool Authenticated { get { throw null; } set { } }
public string Name { get { throw null; } set { } }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461;netcoreapp3.0;$(NetFrameworkCurrent)</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<ExcludeCurrentFullFrameworkFromPackage>true</ExcludeCurrentFullFrameworkFromPackage>
</PropertyGroup>
<!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. -->
<PropertyGroup>
<IsPartialFacadeAssembly Condition="$(TargetFramework.StartsWith('net4'))">true</IsPartialFacadeAssembly>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<DefineConstants>$(DefineConstants);CAS_OBSOLETIONS</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Security.Permissions.cs" />
<Compile Include="System.Security.Permissions.Forwards.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
<PropertyGroup>
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<TargetFrameworks>$(NetCoreAppCurrent);netcoreapp3.0;netstandard2.0;net461;$(NetFrameworkCurrent)</TargetFrameworks>
<ExcludeCurrentNetCoreAppFromPackage>true</ExcludeCurrentNetCoreAppFromPackage>
<ExcludeCurrentFullFrameworkFromPackage>true</ExcludeCurrentFullFrameworkFromPackage>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)'">
<DefineConstants>$(DefineConstants);CAS_OBSOLETIONS</DefineConstants>
</PropertyGroup>
<ItemGroup Condition="!$(TargetFramework.StartsWith('net4'))">
<Compile Include="System\ApplicationIdentity.cs" />
<Compile Include="System\Configuration\ConfigurationPermission.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace System.Security.Permissions
[AttributeUsage((AttributeTargets)(68), AllowMultiple = true, Inherited = false)]
public sealed partial class PrincipalPermissionAttribute : CodeAccessSecurityAttribute
{
#if CAS_OBSOLETIONS
[Obsolete("PrincipalPermissionAttribute is not honored by the runtime and must not be used.", error: true, DiagnosticId = "MSLIB0002", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#endif
public PrincipalPermissionAttribute(SecurityAction action) : base(default(SecurityAction)) { }
public bool Authenticated { get; set; }
public string Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,6 @@ public static void PrincipalPermissionCallMethods()
pp.ToXml();
}

[Fact]
public static void PrincipalPermissionAttributeCallMethods()
{
PrincipalPermissionAttribute ppa = new PrincipalPermissionAttribute(new Permissions.SecurityAction());
IPermission ip = ppa.CreatePermission();
}

[Fact]
public static void PublisherIdentityPermissionCallMethods()
{
Expand Down

0 comments on commit 997539e

Please sign in to comment.