Skip to content

Instantly share code, notes, and snippets.

@miya2000
Created September 5, 2009 07:15
Show Gist options
  • Save miya2000/181327 to your computer and use it in GitHub Desktop.
Save miya2000/181327 to your computer and use it in GitHub Desktop.
using System;
using System.Security.Permissions;
using System.Security;
using System.Diagnostics;
using System.Threading;
using System.Security.Principal;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
try
{
Hoge("test0");
Debug.Assert(false, "例外未発生");
}
catch (SecurityException)
{
}
try
{
Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("ユーザー"), new []{ "role1" });
Hoge("test1");
}
catch (SecurityException)
{
Debug.Assert(false, "例外発生");
}
try
{
Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("ユーザー"), new[] { "role2" });
Hoge("test2");
}
catch (SecurityException)
{
Debug.Assert(false, "例外発生");
}
}
[PrincipalPermission(SecurityAction.Demand, Role = "role1")]
[PrincipalPermission(SecurityAction.Demand, Role = "role2")]
static void Hoge(string str)
{
Debug.WriteLine("Hoge:" + str);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment