Visual C++ .NET/Security/WindowsPrincipal — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 12:05, 26 мая 2010
Generic Principal and Identity
#include "stdafx.h"
using namespace System;
using namespace System::Security;
using namespace System::Security::Principal;
using namespace System::Threading;
void main()
{
AppDomain::CurrentDomain->SetPrincipalPolicy(PrincipalPolicy::WindowsPrincipal);
WindowsPrincipal ^wPrinc = (WindowsPrincipal^)Thread::CurrentPrincipal;
Console::WriteLine("Is an Administrator?: {0}", wPrinc->IsInRole(WindowsBuiltInRole::Administrator));
Console::WriteLine("Is a Hacker?: {0}", wPrinc->IsInRole("Hacker"));
WindowsIdentity ^wIdent = (WindowsIdentity^)wPrinc->Identity;
array<String^>^ rolesArray = {"Hacker"};
Thread::CurrentPrincipal = gcnew GenericPrincipal(gcnew GenericIdentity("John Doe"), rolesArray);
GenericPrincipal ^gPrinc = (GenericPrincipal^)Thread::CurrentPrincipal;
Console::WriteLine("Is an Administrator?: {0}",
gPrinc->IsInRole("BUILTIN\\Administrator"));
Console::WriteLine("Is a Hacker?: {0}", gPrinc->IsInRole("Hacker"));
GenericIdentity ^gIdent = (GenericIdentity^)gPrinc->Identity;
Console::WriteLine("\nUser Name: {0}", gIdent->Name);
Console::WriteLine("Is Authenticated: {0}\n", gIdent->IsAuthenticated);
}
Get Windows Principal and Identity
#include "stdafx.h"
using namespace System;
using namespace System::Security;
using namespace System::Security::Principal;
using namespace System::Threading;
void main()
{
AppDomain::CurrentDomain->SetPrincipalPolicy(PrincipalPolicy::WindowsPrincipal);
WindowsPrincipal ^wPrinc = (WindowsPrincipal^)Thread::CurrentPrincipal;
Console::WriteLine("Is an Administrator?: {0}", wPrinc->IsInRole(WindowsBuiltInRole::Administrator));
Console::WriteLine("Is a Hacker?: {0}", wPrinc->IsInRole("Hacker"));
WindowsIdentity ^wIdent = (WindowsIdentity^)wPrinc->Identity;
Console::WriteLine("\nWindows Login Name: {0}", wIdent->Name);
Console::WriteLine("Authentication Type: {0}", wIdent->AuthenticationType);
Console::WriteLine("Is Authenticated: {0}", wIdent->IsAuthenticated);
Console::WriteLine("Is System Account: {0}", wIdent->IsSystem);
}