Freigeben über


Einschränken von Sicherheitsberechtigungen für UDF-Code

If you do not want a particular user-defined function (UDF) assembly to run with full trust, you must explicitly restrict code access security permissions for it. You can configure code groups and restrict permissions by using the .NET Framework 2.0 Configuration tool.

For example, imagine a scenario where you have a UDF assembly that contains multiple methods. One of the UDF methods performs a custom calculation, and another UDF method in the same assembly calls a Web service to obtain stock quotes. Because your users only use Excel workbooks that call the first (calculation) method, you might want to disable the assembly from having Web access, for increased security. Sie haben die UDF-Assembly in einem Ordner auf dem Server bei C:\UdfAssemblies\CalcAndWebAccessUdf.dll installiert. Because the assembly is on the same computer as Microsoft SharePoint Server 2010, when Dienste für Excel-Berechnungen loads the UDF assembly, it is loaded in the MyComputer zone. By default, the MyComputer zone is fully trusted. This means that the UDF assembly is granted full trust permission.

To lock down the UDF assembly so that it cannot have Web access, you must explicitly restrict the permission set that it is granted by following these steps:

  1. Create a new URL-based code group under My_Computer_Zone at the Machine level. Scope the code group to that specific assembly and create a custom permission set.

  2. Configure the custom code group properties so that your policy level has only the permissions from the permission set that is associated with the custom code group. When Dienste für Excel-Berechnungen loads a UDF assembly that resides on the same computer, the assembly is loaded in the MyComputer zone. This means that by default, the UDF assembly is granted full trust. When the custom permission set intersects with the full trust permission set, the result is full trust. To make it so that the a policy has only the permission from the permission set that is associated with your custom code group, you must enable the This policy level will only have the permissions from the permission set associated with this code group property.

For more information about configuring code groups, see the following articles on MSDN:

So erstellen Sie eine neue Codegruppe

  1. Click Start, point to All Programs, point to Administrative Tools, and then click Microsoft .NET Framework 2.0 Configuration.

    This starts the .NET 2.0 Framework Configuration tool.

  2. In the left pane, expand the My Computer node, and then expand the Runtime Security Policy node.

  3. Expand the Machine node.

  4. Expand the Code Groups node.

  5. Expand the All_Code node.

  6. Expand the My_Computer_Zone node.Right-click My_Computer_Zone and then select New to display the Identify the new Code Group dialog box.

  7. Select Create a new code group.

  8. In the Name field, type a name for the new code group, for example,RestrictWebAccessUdf.

  9. Klicken Sie auf Weiter.

  10. To scope the code group to your specific UDF assembly, select URL from the Choose the condition type for this code group.

    This displays the URL field.

  11. Geben Sie im Feld URL den Pfad zu der UDF-Assembly ein, für die Sie den Zugriff auf das Web einschränken möchten, z. B. C:\UdfAssemblies\CalcAndWebAccessUdf.dll.

  12. Klicken Sie auf Weiter.

  13. Select Create a new permission set, and then click Next.

  14. In the Name field, type a name for your permission set, for example,AssemblyExecutionCustomPermissionSet.

  15. Klicken Sie auf Weiter.

  16. To give your UDF assembly "assembly execution" permission, select Security from the Assembly Permissions list, and then click Add.

    Dadurch wird das Dialogfeld Berechtigungseinstellungen angezeigt.

  17. Wählen Sie Assemblys den Zugriff auf folgende Sicherheitsberechtigungen gewähren aus.

  18. Wählen Sie Assemblyausführung aktivieren aus.

  19. Click OK, and then click Next.

  20. Klicken Sie auf Fertig stellen.

    You should see your new custom code group under the My_Computer_Zone node (in this example, RestrictWebAccessUdf).

So stellen Sie sicher, dass die Berechtigungssätze ausgeführt werden

  1. Under the My_Computer_Zone node, right-click the new custom code group (in this example, RestrictWebAccessUdf), and then select Properties.

  2. On the General tab, select the This policy level will only have the permissions from the permission set associated with this code group check box.

  3. Klicken Sie im Feld Wähleinstellungen (Telefonkontext) auf Durchsuchen, um die Wähleinstellungen für den Benutzer zu suchen.

    Hinweis

    Wenn die UDF-Methode eine Ausnahme auslöst, da ein Webdienstaufruf nicht ausgeführt werden kann, sollte in der Excel-Formel, die die UDF aufgerufen hat, ein #WERT!-Fehler angezeigt werden.

    Hinweis

    Wenn Sie zu Testzwecken den Webzugriff für die UDF-Assembly aktivieren möchten, müssen Sie die entsprechende Berechtigung zum benutzerdefinierten Berechtigungssatz hinzufügen. Wählen Sie hierfür in Schritt 11 des Verfahrens "So erstellen Sie eine neue Codegruppe" die Option Webzugriff aus.

Siehe auch