Created
September 5, 2009 07:15
-
-
Save miya2000/181327 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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