Go Back   Velocity Reviews > Newsgroups > MCTS
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

MCTS - Help on PrincipalPermission Demand Throwing Exception

 
Thread Tools Search this Thread
Old 02-07-2007, 09:25 PM   #1
Default Help on PrincipalPermission Demand Throwing Exception


[PrincipalPermission(SecurityAction.Demand, Name=@"MYDomain\MyUserName")]
static void TestMethod()
{
Console.WriteLine("Test Message");
}

public static void Main(string[] args)
{
WindowsIdentity wID = WindowsIdentity.GetCurrent();
Console.WriteLine("Current User: {0}", wID .Name);

try
{
TestMethod();
}
catch (System.Security.SecurityException ex)
{
Console.WriteLine("Exception: {0}", ex.Message);
}

Console.Read();
}



Abba Biya
  Reply With Quote
Old 02-07-2007, 10:05 PM   #2
Abba Biya
 
Posts: n/a
Default RE: Help on PrincipalPermission Demand Throwing Exception
Shoud add the following line for it to work.

AppDomain.CurrentDomain.SetPrincipalPolicy(Princip alPolicy.WindowsPrincipal);


some observations:

Security Principals listed on separate demands will be OR whereas if listed
all in one SecurityAction.Demand, it will be AND.

[PrincipalPermission(SecurityActioin.Demand, Authenticated = true, Role =
@"CONTOSO\Admins")]
will allow only authenticated and users from Admins group.

If we change it to the following:
[PrincipalPermission(SecurityActioin.Demand, Authenticated = true)]
[PrincipalPermission(SecurityAction.Demand, Role = @"CONTOSO\Admins")]

Authenticated users with out being Admins will be able to run this code.
this is a Logical OR.

This is great.



"Abba Biya" wrote:

> [PrincipalPermission(SecurityAction.Demand, Name=@"MYDomain\MyUserName")]
> static void TestMethod()
> {
> Console.WriteLine("Test Message");
> }
>
> public static void Main(string[] args)
> {
> WindowsIdentity wID = WindowsIdentity.GetCurrent();
> Console.WriteLine("Current User: {0}", wID .Name);
>
> try
> {
> TestMethod();
> }
> catch (System.Security.SecurityException ex)
> {
> Console.WriteLine("Exception: {0}", ex.Message);
> }
>
> Console.Read();
> }
>



Abba Biya
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
exception has been thrown by the target of an invocation mintcremes General Help Related Topics 0 07-03-2008 02:51 AM
java.net.SocketException: Broken pipe exception at HttpServletRequest sadasivar Software 0 03-11-2008 04:40 AM
exception unknown software exception error - Excel.exe mfinamore Software 0 11-15-2007 04:54 PM
Exception in thread "main" java.lang.NoClassDefFoundError: prakash.nmsp@gmail.com Software 0 06-29-2007 10:03 AM
how to overcome the nullpointer exception arputharaj Software 0 11-11-2006 07:05 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46