Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add System.Security.Permissions.PrincipalPermission #17693

Closed
danmoseley opened this issue Jun 23, 2016 · 4 comments · Fixed by dotnet/corefx#13275
Closed

Add System.Security.Permissions.PrincipalPermission #17693

danmoseley opened this issue Jun 23, 2016 · 4 comments · Fixed by dotnet/corefx#13275
Assignees
Milestone

Comments

@danmoseley
Copy link
Member

We see this being used in apps. It does have effect in Desktop in the default configuration (unlike CAS). We could reasonably implement it cross platform. So we should add it.

class Program
{
    static void Main()
    {
        new System.Security.Permissions.PrincipalPermission("foo", "bar").Demand();
    }
}

Unhandled Exception: System.Security.SecurityException: Request for principal permission failed.
   at System.Security.Permissions.PrincipalPermission.ThrowSecurityException()
   at System.Security.Permissions.PrincipalPermission.Demand()
   at Program.Main() in C:\Users\stoub\Documents\Visual Studio 2015\Projects\ConsoleApplication27\ConsoleApplication27\Program.cs:line 5
@danmoseley danmoseley changed the title Add Note that System.Security.Permissions.PrincipalPermission Add System.Security.Permissions.PrincipalPermission Jun 23, 2016
@danmoseley
Copy link
Member Author

danmoseley commented Jun 23, 2016

Not in scope: making the Attribute work. Only the imperative. This does not need to work:

    public static void Main()
    {
        try
        {
            // PrincipalPolicy must be set to WindowsPrincipal to check roles.
            AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            // Check using the PrincipalPermissionAttribute
            CheckAdministrator();
            // Check using PrincipalPermission class.
            PrincipalPermission principalPerm = new PrincipalPermission(null, "Administrators");
            principalPerm.Demand();
            Console.WriteLine("Demand succeeded.");
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
    }
    [PrincipalPermission(SecurityAction.Demand, Role = "Administrators")]
    static void CheckAdministrator()
    {
        Console.WriteLine("User is an administrator");
    }

@ioanacrant
Copy link
Contributor

Resolved in dotnet/corefx#10977

@stephentoub
Copy link
Member

The type was added in dotnet/corefx#10977, but it's not actually functional. This is one we decided we need to be functional.

@stephentoub stephentoub reopened this Oct 18, 2016
@stephentoub stephentoub assigned danmoseley and unassigned ioanacrant Oct 18, 2016
@danmoseley danmoseley removed their assignment Oct 18, 2016
@ianhays
Copy link
Contributor

ianhays commented Oct 26, 2016

Looking at the original reference source, most of it can be easily translatable to .net core. My only concerns are the things wrapped in FEATURE_CAS_POLICY and FEATURE_IMPERSONATION. Are those bits necessary to include as well? Some of the functions like Demand won't work without FEATURE_IMPERSONATION so I assume that's necessary. FEATURE_CAS_POLICY on the other hand only affects XML parsing.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants