Sharepoint:是否可以自动部署自定义 CAS 策略?

发布于 2024-08-31 09:17:33 字数 628 浏览 4 评论 0原文

我正在寻找一种在 SharePoint 中自动部署自定义 CAS 策略的方法。

我想要实现的目标如下:

由我们的构建服务器(使用密钥)构建和签名的所有程序集应在“高于正常”信任级别的 SharePoint 中运行。

现在我可以手动编辑 cas 策略文件以包含如下内容:

        <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="MyPermissionSet" Name="[My Company public key]" Description="Grants all ">
          <IMembershipCondition class="StrongNameMembershipCondition" version="1" PublicKeyBlob="[public key goes here]" />
        </CodeGroup>

这非常有效。然而,我们有几个巨大的共享点场,上面运行着许多应用程序。我希望避免手动编辑所有策略文件以包含此 xml 片段。

有没有办法自动执行此操作?例如,来自某个功能?

谨致问候, 埃尔文·范德瓦尔克

I'm looking for a way to automate the deployment of a custom CAS policy in SharePoint.

What i would like to achieve is the following:

All assemblies that have been built and signed by our build server (with a secret key) should run in SharePoint under the 'higher than normal' trust level.

Now I can manually edit the cas policy files to include something like this:

        <CodeGroup class="UnionCodeGroup" version="1" PermissionSetName="MyPermissionSet" Name="[My Company public key]" Description="Grants all ">
          <IMembershipCondition class="StrongNameMembershipCondition" version="1" PublicKeyBlob="[public key goes here]" />
        </CodeGroup>

And that works great. However, we have several huge sharepoint farms, with many applications running on it. I'd like to avoid having to manually edit all policy files to include this xml snippet.

Is there a way to automate this? For example, from a feature?

With kind regards,
Erwin van der Valk

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

執念 2024-09-07 09:17:33

希望您熟悉 .wsp 文件。这是将任何内容部署到场的标准方法。您还可以通过 wsp 文件部署 CAS 策略条目。 (也许您需要仅为您的 cas 策略创建一个 wsp 文件)。 wsp 文件与 cab 文件相同,只是重命名。 wsp 文件内有一个 manifest.xml,您可以在其中定义要对 CAS 文件应用哪些更改。这样做的好处是可以通过卸载 WSP 来恢复。我见过几种不同的部署 CAS 策略的方法,包括将自定义策略文件作为 wsp 的一部分,并像任何其他文件一样进行部署。

您应该谷歌 wsp cas 政策 manifest.xml 以获得进一步的教程。

希望这有帮助..

Hope you're familiar with .wsp files. This is a standard way to deploying anything to the farm. You can also deploy CAS policy entries though a wsp file. (Maybe you'll want to create a wsp file just for your cas policy). wsp files are the same as cab files, just renamed. Inside a wsp file lives manifest.xml in which you can define what changes to the CAS file you want to apply. The great thing about doing it this way that its reversible by uninstallaing the WSP. I've seen several different approaches to deploying CAS policies including having your custom policy file as part of your wsp and it gets deployed just like any other file.

You should google wsp cas policy manifest.xml for further tutorials.

Hope this helps..

优雅的叶子 2024-09-07 09:17:33

这就是我为自动部署 WebPart 的 CAS 策略所做的操作:

以下内容的 Manifest.xml 文件:

<?xml version="1.0" encoding="utf-8" ?>
<Solution SolutionId="0C006FE3-919D-4a2a-9CF0-FEA66A0A91E4" xmlns="http://schemas.microsoft.com/sharepoint/" >
    <Assemblies>
        <Assembly Location="MyWebPart.dll" DeploymentTarget="WebApplication">
            <ClassResources>
                <ClassResource Location="MyWebpart_log.config" />
                <ClassResource Location="combo.css" />
                <ClassResource Location="combo.js" />
                <ClassResource Location="img/arrow.png" />
                <ClassResource Location="img/coordination.gif" />
                <ClassResource Location="img/dt-arrow-dn.png" />
                <ClassResource Location="img/dt-arrow-up.png" />
                <ClassResource Location="img/loading.gif" />
                <ClassResource Location="img/menu-button-arrow.png" />
                <ClassResource Location="img/spinner.gif" />
                <ClassResource Location="img/split-button-arrow.png" />
                <ClassResource Location="img/sprite.png" />
            </ClassResources>
            <SafeControls>
                <SafeControl Assembly="MyWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=017e953639e07a31"
                             Namespace="MyWebPart" TypeName="*" Safe="True" />
            </SafeControls>
        </Assembly>
        <Assembly Location="log4net.dll" DeploymentTarget="WebApplication">
            <SafeControls>
                <SafeControl Assembly="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"
                             Namespace="MyWebPart" TypeName="*" Safe="True" />
            </SafeControls>
        </Assembly>
    </Assemblies>
    <CodeAccessSecurity>
        <PolicyItem>
            <PermissionSet class="NamedPermissionSet" version="1" Name="MyWebPartPermissionSet"
                           Description="Permission set for My Web Part">
                <IPermission class="AspNetHostingPermission" version="1" Level="Medium" />
                <IPermission class="System.Net.DnsPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                             version="1" Unrestricted="true" />
                <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                      version="1" Read="$AppDir$" Write="$AppDir$" Append="$AppDir$" PathDiscovery="$AppDir$" />
                <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                    version="1" 
                    Flags="Execution" />
                <IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" ObjectModel="True" />
                <IPermission class="Microsoft.SharePoint.Security.WebPartPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 
                             version="1" Connections="True" />
                <IPermission class="System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                             version="1">
                    <ConnectAccess>
                        <URI uri=".*"/>
                    </ConnectAccess>
                </IPermission>
            </PermissionSet>
            <Assemblies>
                <Assembly Name="MyWebPart" />
            </Assemblies>
        </PolicyItem>
        <PolicyItem>
            <PermissionSet class="NamedPermissionSet" version="1" Name="Log4NetForMyWebPart"
                           Description="Permission set for Log4Net (logging library used by the My Web Part">
                <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Execution" />
                <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                        version="1" Read="$AppDir$" Write="$AppDir$" Append="$AppDir$" PathDiscovery="$AppDir$" />
            </PermissionSet>
            <Assemblies>
                <Assembly Name="log4net" />
            </Assemblies>
        </PolicyItem>
    </CodeAccessSecurity>
</Solution>

在我的 .wsp 文件中,我有一个包含 必须深入研究 MS 文档以获取所需的权限,因为我花了一段时间才弄清楚我需要哪些权限。

.wsp 文件是使用以下命令创建的:(

cabarc -r -p N ..\MyWebPart-1.0.0.wsp *

我从 Microsoft 网站下载了 cabarc,但我不记得确切位置)

将 Web 部件解决方案部署到 SharePoint我使用以下命令:

cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin

stsadm.exe -o addsolution -filename MyWebPart-1.0.0.wsp

stsadm.exe -o deploysolution -name MyWebPart-1.0.0.wsp -immediate -allcontenturls -allowCasPolicies

stsadm.exe -o execadmsvcjobs

allowCasPolicies 参数是必需的,因为解决方案包含 CAS 策略。如果没有它,它们将不会添加到 SharePoint 的 web.config 文件中。

This is what I have done to automate the deployment of CAS policies of my WebPart:

Inside my .wsp file, I have a Manifest.xml file with this content:

<?xml version="1.0" encoding="utf-8" ?>
<Solution SolutionId="0C006FE3-919D-4a2a-9CF0-FEA66A0A91E4" xmlns="http://schemas.microsoft.com/sharepoint/" >
    <Assemblies>
        <Assembly Location="MyWebPart.dll" DeploymentTarget="WebApplication">
            <ClassResources>
                <ClassResource Location="MyWebpart_log.config" />
                <ClassResource Location="combo.css" />
                <ClassResource Location="combo.js" />
                <ClassResource Location="img/arrow.png" />
                <ClassResource Location="img/coordination.gif" />
                <ClassResource Location="img/dt-arrow-dn.png" />
                <ClassResource Location="img/dt-arrow-up.png" />
                <ClassResource Location="img/loading.gif" />
                <ClassResource Location="img/menu-button-arrow.png" />
                <ClassResource Location="img/spinner.gif" />
                <ClassResource Location="img/split-button-arrow.png" />
                <ClassResource Location="img/sprite.png" />
            </ClassResources>
            <SafeControls>
                <SafeControl Assembly="MyWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=017e953639e07a31"
                             Namespace="MyWebPart" TypeName="*" Safe="True" />
            </SafeControls>
        </Assembly>
        <Assembly Location="log4net.dll" DeploymentTarget="WebApplication">
            <SafeControls>
                <SafeControl Assembly="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821"
                             Namespace="MyWebPart" TypeName="*" Safe="True" />
            </SafeControls>
        </Assembly>
    </Assemblies>
    <CodeAccessSecurity>
        <PolicyItem>
            <PermissionSet class="NamedPermissionSet" version="1" Name="MyWebPartPermissionSet"
                           Description="Permission set for My Web Part">
                <IPermission class="AspNetHostingPermission" version="1" Level="Medium" />
                <IPermission class="System.Net.DnsPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                             version="1" Unrestricted="true" />
                <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                      version="1" Read="$AppDir$" Write="$AppDir$" Append="$AppDir$" PathDiscovery="$AppDir$" />
                <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                    version="1" 
                    Flags="Execution" />
                <IPermission class="Microsoft.SharePoint.Security.SharePointPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" version="1" ObjectModel="True" />
                <IPermission class="Microsoft.SharePoint.Security.WebPartPermission, Microsoft.SharePoint.Security, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 
                             version="1" Connections="True" />
                <IPermission class="System.Net.WebPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                             version="1">
                    <ConnectAccess>
                        <URI uri=".*"/>
                    </ConnectAccess>
                </IPermission>
            </PermissionSet>
            <Assemblies>
                <Assembly Name="MyWebPart" />
            </Assemblies>
        </PolicyItem>
        <PolicyItem>
            <PermissionSet class="NamedPermissionSet" version="1" Name="Log4NetForMyWebPart"
                           Description="Permission set for Log4Net (logging library used by the My Web Part">
                <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="Execution" />
                <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                        version="1" Read="$AppDir$" Write="$AppDir$" Append="$AppDir$" PathDiscovery="$AppDir$" />
            </PermissionSet>
            <Assemblies>
                <Assembly Name="log4net" />
            </Assemblies>
        </PolicyItem>
    </CodeAccessSecurity>
</Solution>

You will have to dig into the MS documentation for the Permissions you need because it took me a while to figure out which ones I need.

The .wsp file was created with the command:

cabarc -r -p N ..\MyWebPart-1.0.0.wsp *

(I downloaded cabarc from the Microsoft website, but I don't remember exactly where)

To deploy the Web Part solution into SharePoint I use these commands:

cd C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\bin

stsadm.exe -o addsolution -filename MyWebPart-1.0.0.wsp

stsadm.exe -o deploysolution -name MyWebPart-1.0.0.wsp -immediate -allcontenturls -allowCasPolicies

stsadm.exe -o execadmsvcjobs

The allowCasPolicies parameter is necessary because the solution contains CAS policies. Without it, they will not be added to the web.config file of SharePoint.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文