Visual C++ .NET/Security/PermissionSet

Материал из .Net Framework эксперт
Версия от 12:05, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Set Security

 
#include "stdafx.h"
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Security::Policy;
void main(){
    PermissionSet^ permSet = gcnew PermissionSet(PermissionState::None);
      
    permSet->AddPermission(gcnew SecurityPermission(PermissionState::Unrestricted));
    permSet->AddPermission(gcnew UIPermission(PermissionState::Unrestricted));
    permSet->AddPermission(gcnew FileIOPermission(FileIOPermissionAccess::Read,"C:\\Test"));
    PolicyStatement^ policy = gcnew PolicyStatement(permSet);
    IMembershipCondition^ membership = gcnew UrlMembershipCondition("http://192.168.1.1/*");
    CodeGroup^ codeGroup = gcnew UnionCodeGroup(membership, policy);
    codeGroup->Description = "C:\\";
    codeGroup->Name = "ReadOnly Secure Group";
    System::Collections::IEnumerator^ ph = SecurityManager::PolicyHierarchy();
    while( ph->MoveNext() ) 
    {
        PolicyLevel^ pl = (PolicyLevel^)ph->Current;
        if( pl->Label == "Machine" ) 
        {
            // Add code group to Machine policy
            pl->RootCodeGroup->AddChild(codeGroup);
            break;
        }
    }
    SecurityManager::SavePolicy();
}