Security issue needs to be resolved.

  • Thread starter Thread starter MyCatAlex
  • Start date Start date
M

MyCatAlex

Guest
I have this code:

public void GetRole ( )
{
StringBuilder sbld = new StringBuilder ( );
System.AppDomain.CurrentDomain.SetPrincipalPolicy ( PrincipalPolicy.WindowsPrincipal );
WindowsIdentity curIdentity = WindowsIdentity.GetCurrent ( );
WindowsPrincipal myPrincipal = new WindowsPrincipal ( curIdentity );
List<string> groups = new List<string> ( );
foreach ( IdentityReference irc in curIdentity.Groups )
{
groups.Add ( ( ( NTAccount )irc.Translate ( typeof ( NTAccount ) ) ).Value );
}

sbld.Append ( "Name: " + curIdentity.Name + " System: curIdentity.IsSystem " + " Authenticated: " +
curIdentity.IsAuthenticated + " BuiltinAdmin: " + "Identiry: " +
myPrincipal.IsInRole ( WindowsBuiltInRole.Administrator ).ToString ( ) +
myPrincipal.Identity + string.Join ( string.Format ( ",{0}tt", Environment.NewLine ), groups.ToArray ( ) ) );
Console.WriteLine ( @"Name: {0} System: {1} Authenticated: {2} BuiltinAdmin: {3} Identity: {4} Groups: {5}",
curIdentity.Name, curIdentity.IsSystem, curIdentity.IsAuthenticated,
myPrincipal.IsInRole ( WindowsBuiltInRole.Administrator ) ? "True" : "False",
myPrincipal.Identity,
string.Join ( string.Format ( ",{0}tt", Environment.NewLine ), groups.ToArray ( ) ) );
try
{
Console.WriteLine ( Environment.NewLine );
}
catch ( System.Security.SecurityException scx )
{
Console.WriteLine ( scx.Message + " " + scx.FirstPermissionThatFailed.ToString ( ) );
}
Console.WriteLine(Environment.NewLine);
} // GetRole


I get this Exception at runtime:

System.Security.SecurityException
HResult=0x8013150A
Message=Request for principal permission failed.
Source=mscorlib
StackTrace:
at System.Security.Permissions.PrincipalPermission.ThrowSecurityException()
at System.Security.Permissions.PrincipalPermission.Demand()
at System.Security.PermissionSet.DemandNonCAS()
at ComeAndGet.SecurityAndDebug.GetRole() in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\SecurityAndDebug.cs:line 23
at ComeAndGet.Form1.comboSecurity_PG9_SelectedIndexChanged(Object sender, EventArgs e) in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\Form1.cs:line 7625
at System.Windows.Forms.ComboBox.OnSelectedIndexChanged(EventArgs e)
at System.Windows.Forms.ComboBox.WmReflectCommand(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Control.SendMessage(Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Control.ReflectMessageInternal(IntPtr hWnd, Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ComboBox.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at ComeAndGet.Program.Main() in C:\VCSharp_Projects\ComeAndGet\ComeAndGet\Program.cs:line 16


What is the reason. I am the administrator on this computer.

Thanks, - MyCatAlex

Continue reading...
 

Similar threads

M
Replies
0
Views
114
Mani25
M
G
Replies
0
Views
160
Graham Skan
G
D
Replies
0
Views
91
Decompressor
D
Back
Top