Visual C++ .NET/Security/PermissionSet — различия между версиями

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

Версия 15:31, 26 мая 2010

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();
}