Visual C++ .NET/Security/GenericPrincipal

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Role Based Security

 
#include "stdafx.h"
using namespace System;
using namespace System::Security;
using namespace System::Security::Principal;
using namespace System::Security::Permissions;
using namespace System::Threading;
[PrincipalPermissionAttribute(SecurityAction::Demand, Role = "Hacker")]
void DeclarativeSecurity()
{
    Console::WriteLine("Function");
}
void DemandSecurity()
{
    (gcnew PrincipalPermission(nullptr, "Hacker"))->Demand();
    Console::WriteLine("Demand Security Function");
}

void main()
{
    DeclarativeSecurity();
    DemandSecurity();
    array<String^>^ rolesArray = {"Hacker"};
    Thread::CurrentPrincipal = gcnew GenericPrincipal(gcnew GenericIdentity("John" ), rolesArray );
    DeclarativeSecurity();
    DemandSecurity();
}