Skip to content

Add System.Security.Permissions.PrincipalPermission #17693

Closed
dotnet/corefx
#13275

Description

@danmoseley

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

Activity

  1. changed the title [-]Add Note that System.Security.Permissions.PrincipalPermission[/-] [+]Add System.Security.Permissions.PrincipalPermission[/+] on Jun 23, 2016
  2. danmoseley commented on Jun 23, 2016

    @danmoseley
    ContributorAuthor

    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");
        }
    
    
  3. ioanacrant commented on Aug 23, 2016

    @ioanacrant
    Contributor
  4. stephentoub commented on Oct 18, 2016

    @stephentoub
    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.

  5. removed their assignment
    on Oct 18, 2016
  6. ianhays commented on Oct 26, 2016

    @ianhays
    Contributor

    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.

  7. transferred this issue fromdotnet/corefxon Jan 31, 2020
  8. added this to the 2.0.0 milestone on Jan 31, 2020
  9. ghost locked as resolved and limited conversation to collaborators on Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions