Share via


CodeAccessPermission::assertMultiple Method

Declares that the calling code can invoke an API that is protected by any of the permissions in a specified collection.

Syntax

client server public static void assertMultiple(Set permissionSet)

Run On

Called

Parameters

  • permissionSet
    Type: Set Class
    A Set class object that contains a collection of permissions.

Remarks

You call the assertMultple method instead of making multiple, successive calls to the CodeAccessPermission.assert and CodeAccessPermission::revertAssert methods in the same calling code.

Examples

The following code example calls the CodeAccessPermission::assertMultple method. Then the code example calls the WinAPIServer::createFile method, which would fail without the previous call to the CodeAccessPermission::assertMultple method.

The code example is a static method that you can add to a new class that you create. You can call this static method from an X++ job by using one line of code that resembles MyClass::RunOnServerPermissionTest.

In the code example, the WinAPIServer class has several secure methods. The WinAPIServer class runs on the server tier, not on the client tier. Therefore the code example method must also run on the server tier. Otherwise, any permission asserts that are made on the client tier are ignored by methods that run on the server tier. This is why the server keyword is included in the method declaration of the code example. The server keyword on the method takes precedence over the RunOn property value that is specified on the class.

server
    static public void RunOnServerPermissionTest()
{
    Set permissionSet;
    str fileName = @"C:\TestFile75a.txt";
    boolean boolFileDeleted;
 
    permissionSet =  new Set(Types::Class);
    permissionSet.add(new FileIoPermission(fileName,'rw'));

    CodeAccessPermission::assertMultiple(permissionSet);
    //--- Permissions are set, now perform file operations.

    WinAPIServer::createFile(fileName);
    boolFileDeleted = WinAPI::deleteFile(fileName);

    if (boolFileDeleted)
    {
        info("The file was deleted. Good.");
    }
    else
    {
        error("The file was not deleted. Error.");
    }
}

See Also

CodeAccessPermission Class

CodeAccessPermission Class