Skip to content

Commit

Permalink
Moving System.Security.Permissions Types from WPF
Browse files Browse the repository at this point in the history
* moved wpf types

* added new types to ref

* addressed comments

* addressing comments

* addressed more comments

* addressed comment

* updated ref

* added typeforwardedfrom and addressed comment

* updated publickeytoken

* added tests, addressed comments

* added mediapermissionattribute test
  • Loading branch information
ojhad authored and bartonjs committed Jun 14, 2019
1 parent e1eb561 commit df5bb8e
Show file tree
Hide file tree
Showing 10 changed files with 389 additions and 3 deletions.
106 changes: 106 additions & 0 deletions src/System.Security.Permissions/ref/System.Security.Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,55 @@ public enum KeyContainerPermissionFlags
ChangeAcl = 8192,
AllFlags = 13111,
}
public sealed partial class MediaPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
{
public MediaPermission() { }
public MediaPermission(System.Security.Permissions.MediaPermissionAudio permissionAudio) { }
public MediaPermission(System.Security.Permissions.MediaPermissionAudio permissionAudio, System.Security.Permissions.MediaPermissionVideo permissionVideo, System.Security.Permissions.MediaPermissionImage permissionImage) { }
public MediaPermission(System.Security.Permissions.MediaPermissionImage permissionImage) { }
public MediaPermission(System.Security.Permissions.MediaPermissionVideo permissionVideo) { }
public MediaPermission(System.Security.Permissions.PermissionState state) { }
public System.Security.Permissions.MediaPermissionAudio Audio { get { throw null; } }
public System.Security.Permissions.MediaPermissionImage Image { get { throw null; } }
public System.Security.Permissions.MediaPermissionVideo Video { get { throw null; } }
public override System.Security.IPermission Copy() { throw null; }
public override void FromXml(System.Security.SecurityElement securityElement) { }
public override System.Security.IPermission Intersect(System.Security.IPermission target) { throw null; }
public override bool IsSubsetOf(System.Security.IPermission target) { throw null; }
public bool IsUnrestricted() { throw null; }
public override System.Security.SecurityElement ToXml() { throw null; }
public override System.Security.IPermission Union(System.Security.IPermission target) { throw null; }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]
public sealed partial class MediaPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
{
public MediaPermissionAttribute(System.Security.Permissions.SecurityAction action) : base(default(System.Security.Permissions.SecurityAction)) { }
public System.Security.Permissions.MediaPermissionAudio Audio { get { throw null; } set { } }
public System.Security.Permissions.MediaPermissionImage Image { get { throw null; } set { } }
public System.Security.Permissions.MediaPermissionVideo Video { get { throw null; } set { } }
public override System.Security.IPermission CreatePermission() { throw null; }
}
public enum MediaPermissionAudio
{
NoAudio = 0,
SiteOfOriginAudio = 1,
SafeAudio = 2,
AllAudio = 3,
}
public enum MediaPermissionImage
{
NoImage = 0,
SiteOfOriginImage = 1,
SafeImage = 2,
AllImage = 3,
}
public enum MediaPermissionVideo
{
NoVideo = 0,
SiteOfOriginVideo = 1,
SafeVideo = 2,
AllVideo = 3,
}
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
public sealed partial class PermissionSetAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
{
Expand Down Expand Up @@ -1397,6 +1446,33 @@ public UrlIdentityPermissionAttribute(System.Security.Permissions.SecurityAction
public string Url { get { throw null; } set { } }
public override System.Security.IPermission CreatePermission() { throw null; }
}
public sealed partial class WebBrowserPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
{
public WebBrowserPermission() { }
public WebBrowserPermission(System.Security.Permissions.PermissionState state) { }
public WebBrowserPermission(System.Security.Permissions.WebBrowserPermissionLevel webBrowserPermissionLevel) { }
public System.Security.Permissions.WebBrowserPermissionLevel Level { get { throw null; } set { } }
public override System.Security.IPermission Copy() { throw null; }
public override void FromXml(System.Security.SecurityElement securityElement) { }
public override System.Security.IPermission Intersect(System.Security.IPermission target) { throw null; }
public override bool IsSubsetOf(System.Security.IPermission target) { throw null; }
public bool IsUnrestricted() { throw null; }
public override System.Security.SecurityElement ToXml() { throw null; }
public override System.Security.IPermission Union(System.Security.IPermission target) { throw null; }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple = true, Inherited = false)]
public sealed partial class WebBrowserPermissionAttribute : System.Security.Permissions.CodeAccessSecurityAttribute
{
public WebBrowserPermissionAttribute(System.Security.Permissions.SecurityAction action) : base(default(System.Security.Permissions.SecurityAction)) { }
public System.Security.Permissions.WebBrowserPermissionLevel Level { get { throw null; } set { } }
public override System.Security.IPermission CreatePermission() { throw null; }
}
public enum WebBrowserPermissionLevel
{
None = 0,
Safe = 1,
Unrestricted = 2,
}
public sealed partial class ZoneIdentityPermission : System.Security.CodeAccessPermission
{
public ZoneIdentityPermission(System.Security.Permissions.PermissionState state) { }
Expand Down Expand Up @@ -2015,3 +2091,33 @@ public enum AspNetHostingPermissionLevel
Unrestricted = 600,
}
}
namespace System.Xaml.Permissions
{
public partial class XamlAccessLevel
{
internal XamlAccessLevel() { }
public System.Reflection.AssemblyName AssemblyAccessToAssemblyName { get { throw null; } }
public string PrivateAccessToTypeName { get { throw null; } }
public static System.Xaml.Permissions.XamlAccessLevel AssemblyAccessTo(System.Reflection.Assembly assembly) { throw null; }
public static System.Xaml.Permissions.XamlAccessLevel AssemblyAccessTo(System.Reflection.AssemblyName assemblyName) { throw null; }
public static System.Xaml.Permissions.XamlAccessLevel PrivateAccessTo(string assemblyQualifiedTypeName) { throw null; }
public static System.Xaml.Permissions.XamlAccessLevel PrivateAccessTo(System.Type type) { throw null; }
}
public sealed partial class XamlLoadPermission : System.Security.CodeAccessPermission, System.Security.Permissions.IUnrestrictedPermission
{
public XamlLoadPermission(System.Collections.Generic.IEnumerable<System.Xaml.Permissions.XamlAccessLevel> allowedAccess) { }
public XamlLoadPermission(System.Security.Permissions.PermissionState state) { }
public XamlLoadPermission(System.Xaml.Permissions.XamlAccessLevel allowedAccess) { }
public System.Collections.Generic.IList<System.Xaml.Permissions.XamlAccessLevel> AllowedAccess { get { throw null; } }
public override System.Security.IPermission Copy() { throw null; }
public override bool Equals(object obj) { throw null; }
public override void FromXml(System.Security.SecurityElement elem) { }
public override int GetHashCode() { throw null; }
public bool Includes(System.Xaml.Permissions.XamlAccessLevel requestedAccess) { throw null; }
public override System.Security.IPermission Intersect(System.Security.IPermission target) { throw null; }
public override bool IsSubsetOf(System.Security.IPermission target) { throw null; }
public bool IsUnrestricted() { throw null; }
public override System.Security.SecurityElement ToXml() { throw null; }
public override System.Security.IPermission Union(System.Security.IPermission other) { throw null; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<Reference Include="System.Security" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Transactions" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsNetFx)' != 'true'">
<ProjectReference Include="..\..\System.Security.AccessControl\ref\System.Security.AccessControl.csproj" />
Expand All @@ -37,4 +39,4 @@
<ProjectReference Include="..\..\System.Text.RegularExpressions\ref\System.Text.RegularExpressions.csproj" />
<ProjectReference Include="..\..\System.Threading\ref\System.Threading.csproj" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="System\Security\Permissions\KeyContainerPermissionAccessEntryEnumerator.cs" />
<Compile Include="System\Security\Permissions\KeyContainerPermissionAttribute.cs" />
<Compile Include="System\Security\Permissions\KeyContainerPermissionFlags.cs" />
<Compile Include="System\Security\Permissions\MediaPermission.cs" />
<Compile Include="System\Security\Permissions\PermissionSetAttribute.cs" />
<Compile Include="System\Security\Permissions\PrincipalPermission.cs" />
<Compile Include="System\Security\Permissions\PrincipalPermissionAttribute.cs" />
Expand Down Expand Up @@ -120,6 +121,7 @@
<Compile Include="System\Security\Permissions\UIPermissionWindow.cs" />
<Compile Include="System\Security\Permissions\UrlIdentityPermission.cs" />
<Compile Include="System\Security\Permissions\UrlIdentityPermissionAttribute.cs" />
<Compile Include="System\Security\Permissions\WebBrowserPermission.cs" />
<Compile Include="System\Security\Permissions\ZoneIdentityPermission.cs" />
<Compile Include="System\Security\Permissions\ZoneIdentityPermissionAttribute.cs" />
<Compile Include="System\Security\Policy\AllMembershipCondition.cs" />
Expand Down Expand Up @@ -176,6 +178,8 @@
<Compile Include="System\Web\AspNetHostingPermission.cs" />
<Compile Include="System\Web\AspNetHostingPermissionAttribute.cs" />
<Compile Include="System\Web\AspNetHostingPermissionLevel.cs" />
<Compile Include="System\Xaml\Permissions\XamlAccessLevel.cs" />
<Compile Include="System\Xaml\Permissions\XamlLoadPermission.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard'">
<Compile Include="$(CommonPath)\CoreLib\System\Security\IStackWalk.cs">
Expand All @@ -201,6 +205,8 @@
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Transactions" />
<Reference Include="System.Web" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Security.AccessControl" />
Expand All @@ -222,4 +228,4 @@
<Reference Include="System.Threading" />
<Reference Include="System.Threading.Thread" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Security.Permissions
{
public enum MediaPermissionAudio
{
NoAudio,
SiteOfOriginAudio,
SafeAudio,
AllAudio
}
public enum MediaPermissionVideo
{
NoVideo,
SiteOfOriginVideo,
SafeVideo,
AllVideo,
}
public enum MediaPermissionImage
{
NoImage,
SiteOfOriginImage,
SafeImage,
AllImage,
}
sealed public class MediaPermission : CodeAccessPermission, IUnrestrictedPermission
{
public MediaPermission() { }
public MediaPermission(PermissionState state) { }
public MediaPermission(MediaPermissionAudio permissionAudio) { }
public MediaPermission(MediaPermissionVideo permissionVideo) { }
public MediaPermission(MediaPermissionImage permissionImage) { }
public MediaPermission(MediaPermissionAudio permissionAudio,
MediaPermissionVideo permissionVideo,
MediaPermissionImage permissionImage)
{ }
public bool IsUnrestricted() { return true; }
public override bool IsSubsetOf(IPermission target) { return true; }
public override IPermission Intersect(IPermission target) { return new MediaPermission(); }
public override IPermission Union(IPermission target) { return new MediaPermission(); }
public override IPermission Copy() { return new MediaPermission(); }
public override SecurityElement ToXml() { return default(SecurityElement); }
public override void FromXml(SecurityElement securityElement) { }
public MediaPermissionAudio Audio { get { return MediaPermissionAudio.AllAudio; } }
public MediaPermissionVideo Video { get { return MediaPermissionVideo.AllVideo; } }
public MediaPermissionImage Image { get { return MediaPermissionImage.AllImage; } }
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
sealed public class MediaPermissionAttribute : CodeAccessSecurityAttribute
{
public MediaPermissionAttribute(SecurityAction action) : base(action) { }
public override IPermission CreatePermission() { return new MediaPermission(); }
public MediaPermissionAudio Audio { get { return MediaPermissionAudio.AllAudio; } set { } }
public MediaPermissionVideo Video { get { return MediaPermissionVideo.AllVideo; } set { } }
public MediaPermissionImage Image { get { return MediaPermissionImage.AllImage; } set { } }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Security.Permissions
{
public enum WebBrowserPermissionLevel
{
None,
Safe,
Unrestricted
}
sealed public class WebBrowserPermission : CodeAccessPermission, IUnrestrictedPermission
{
public WebBrowserPermission() { }
public WebBrowserPermission(PermissionState state) { }
public WebBrowserPermission(WebBrowserPermissionLevel webBrowserPermissionLevel) { }
public bool IsUnrestricted() { return true; }
public override bool IsSubsetOf(IPermission target) { return true; }
public override IPermission Intersect(IPermission target) { return new WebBrowserPermission(); }
public override IPermission Union(IPermission target) { return new WebBrowserPermission(); }
public override IPermission Copy() { return new WebBrowserPermission(); }
public override SecurityElement ToXml() { return default(SecurityElement); }
public override void FromXml(SecurityElement securityElement) { }
public WebBrowserPermissionLevel Level { get { return WebBrowserPermissionLevel.Unrestricted; } set { } }
}

[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
sealed public class WebBrowserPermissionAttribute : CodeAccessSecurityAttribute
{
public WebBrowserPermissionAttribute(SecurityAction action) : base(action) { }
public override IPermission CreatePermission() { return new WebBrowserPermission(); }
public WebBrowserPermissionLevel Level { get { return WebBrowserPermissionLevel.Unrestricted; } set { } }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Reflection;
using System.Security;

namespace System.Xaml.Permissions
{
public class XamlAccessLevel
{
private XamlAccessLevel(string assemblyName, string typeName)
{
AssemblyNameString = assemblyName;
PrivateAccessToTypeName = typeName;
}

public static XamlAccessLevel AssemblyAccessTo(Assembly assembly)
{
return new XamlAccessLevel(assembly.FullName, null);
}

public static XamlAccessLevel AssemblyAccessTo(AssemblyName assemblyName)
{
return new XamlAccessLevel(assemblyName.FullName, null);
}

public static XamlAccessLevel PrivateAccessTo(Type type)
{
return new XamlAccessLevel(type.Assembly.FullName, type.FullName);
}

public static XamlAccessLevel PrivateAccessTo(string assemblyQualifiedTypeName)
{
int nameBoundary = assemblyQualifiedTypeName.IndexOf(',');
string typeName = assemblyQualifiedTypeName.Substring(0, nameBoundary).Trim();
string assemblyFullName = assemblyQualifiedTypeName.Substring(nameBoundary + 1).Trim();
AssemblyName assemblyName = new AssemblyName(assemblyFullName);
return new XamlAccessLevel(assemblyName.FullName, typeName);
}

public AssemblyName AssemblyAccessToAssemblyName
{
get { return new AssemblyName(AssemblyNameString); }
}

public string PrivateAccessToTypeName { get; private set; }

internal string AssemblyNameString { get; private set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;

namespace System.Xaml.Permissions
{
public sealed class XamlLoadPermission : CodeAccessPermission, IUnrestrictedPermission
{
public XamlLoadPermission(PermissionState state) { }
public XamlLoadPermission(XamlAccessLevel allowedAccess) { }
public XamlLoadPermission(IEnumerable<XamlAccessLevel> allowedAccess) { }
[ComVisible(false)]
public override bool Equals(object obj) { return ReferenceEquals(this, obj); }
[ComVisible(false)]
public override int GetHashCode() { return base.GetHashCode(); }
public IList<XamlAccessLevel> AllowedAccess { get; private set; } = new ReadOnlyCollection<XamlAccessLevel>(Array.Empty<XamlAccessLevel>());
public override IPermission Copy() { return new XamlLoadPermission(PermissionState.Unrestricted); }
public override void FromXml(SecurityElement elem) { }
public bool Includes(XamlAccessLevel requestedAccess) { return true; }
public override IPermission Intersect(IPermission target) { return new XamlLoadPermission(PermissionState.Unrestricted); }
public override bool IsSubsetOf(IPermission target) { return true; }
public override SecurityElement ToXml() { return default(SecurityElement); }
public override IPermission Union(IPermission other) { return new XamlLoadPermission(PermissionState.Unrestricted); }
public bool IsUnrestricted() { return true; }
}
}
Loading

0 comments on commit df5bb8e

Please sign in to comment.