下载微软提供的demo

https://github.com/Microsoft/Reporting-Services/tree/master/CustomSecuritySample
如果上面链接打不开,点击下面链接下载
https://www.123pan.com/s/SSzA-pESdv

下载完的文件是个压缩包
image.png

编译项目

解压缩

右击demo压缩包,解压到当前文件夹
image.png

打开项目

用Visual Studio打开CustomSecuritySample.sln
image.png

安装.NET Framework

如果提示“未安装项目的目标框架,则选择下载,并点击确定
image.png
根据弹窗提示的.NETFramework版本号,下载对应的Developer Pack
注意:只能选择Developer Pack安装包,如果是在线安装包或脱机安装包,当所安装的版本低于当前系统所安装的.NETFramework最高版本时,将无法安装。
image.png
下载好安装包之后进行安装
回到Visual Studio,点击重试
image.png
页面中出现了刚才安装的.NET Framwork版本
image.png

创建密钥

打开Visual Studio开发人员命令提示符
image.png
打开后,跳转到需要的目录,如cd c:\test,然后输入:sn -k SampleKey.snk
image.png

设置签名

生成的samplekey.snk需要和程序关联,点击应用程序的属性,选择签名,选择强签名密钥文件为刚生成的samplekey.snk
image.png

编译

右击解决方案,选择生成
image.png
如果不能通过,可能需要添加 Microsoft.ReportingServices.Interfaces 这可以在 C:\Program Files\Microsoft Power BI Report Server\PBIRS\PowerBI 目录下找到 Microsoft.ReportingServices.Interfaces.DLL进行引用
[

](https://blog.csdn.net/capsicum29/article/details/83746921)
如果一切顺利将生成成功
image.png

部署项目

image.png
将Logon.aspx复制到下列目录:
C:\Program Files\Microsoft Power BI Report Server\PBIRS\ReportServer

将Microsoft.Samples.ReportingServices.CustomSecurity.dll和Microsoft.Samples.ReportingServices.CustomSecurity.pdb复制到下列目录:
C:\Program Files\Microsoft Power BI Report Server\PBIRS\ \ReportServer\bin
C:\Program Files\Microsoft Power BI Report Server\PBIRS\ \Portal
C:\Program Files\Microsoft Power BI Report Server\PBIRS\ \PowerBI

生成密钥

生成密钥理论有很多方法实现,我的这台服务器安装了IIS 我使用IIS进行生成密钥

打开IIS

image.png

安装IIS

如果搜不到IIS,需要先安装
控制面板-程序和功能,点击“启动或关闭Windows功能”
image.png
勾选IIS,点确定
image.png

双击打开“计算机密钥”

image.png

安装“计算机密钥”

如果在IIS中没有“计算机密钥”,需要先安装
控制面板-程序和功能,点击“启动或关闭Windows功能”
image.png
勾选HTTP激活,点确定
image.png
重新打开IIS,“计算机密钥”就有了。

生成密钥

验证方法选“AES”
加密方法选“AES”
点“生成密钥”
image.png
点“应用”
image.png
记录好验证密钥和解密密钥备用

修改配置文件

修改RSReportServer.config

C:\Program Files\Microsoft Power BI Report Server\PBIRS\ReportServer\RSReportServer.config
节下修改为

  1. <Authentication>
  2. <AuthenticationTypes>
  3. <Custom/>
  4. </AuthenticationTypes>
  5. <RSWindowsExtendedProtectionLevel>Off</RSWindowsExtendedProtectionLevel>
  6. <RSWindowsExtendedProtectionScenario>Proxy</RSWindowsExtendedProtectionScenario>
  7. <EnableAuthPersistence>true</EnableAuthPersistence>
  8. </Authentication>

在元素中找到,将 修改如下: 这里的username是管理员的名称,比如我这里设置为maxbiuser

  1. <Security>
  2. <Extension Name="Forms" Type="Microsoft.Samples.ReportingServices.CustomSecurity.Authorization, Microsoft.Samples.ReportingServices.CustomSecurity" >
  3. <Configuration>
  4. <AdminConfiguration>
  5. <UserName>maxbiuser</UserName>
  6. </AdminConfiguration>
  7. </Configuration>
  8. </Extension>
  9. </Security>
  1. <Authentication>
  2. <Extension Name="Forms" Type="Microsoft.Samples.ReportingServices.CustomSecurity.AuthenticationExtension,Microsoft.Samples.ReportingServices.CustomSecurity" />
  3. </Authentication>

下面加入:

  1. <MachineKey ValidationKey="[YOUR KEY]" DecryptionKey="[YOUR KEY]" Validation="AES" Decryption="AES" />

下加入,配置直通 cookie

  1. <UI>
  2. <CustomAuthenticationUI>
  3. <PassThroughCookies>
  4. <PassThroughCookie>sqlAuthCookie</PassThroughCookie>
  5. </PassThroughCookies>
  6. </CustomAuthenticationUI>
  7. </UI>

修改rssrvpolicy. config

C:\Program Files\Microsoft Power BI Report Server\PBIRS\ReportServer\rssrvpolicy. config
需要为自定义安全扩展添加一个代码组, 该代码组将授予您的扩展的 fulltrust 权限。为此, 可以将代码组添加到 rssrvpoligy. config 文件中。
在安全策略文件中的现有代码组之后添加以下元素, 如下所示, 然后添加一个条目, 如下所示, 以 rssrvpolicy. config。请确保根据您的 reportserver 安装目录更改以下路径:

  1. <CodeGroup
  2. class="UnionCodeGroup"
  3. version="1"
  4. Name="SecurityExtensionCodeGroup"
  5. Description="Code group for the sample security extension"
  6. PermissionSetName="FullTrust">5
  7. <IMembershipCondition
  8. class="UrlMembershipCondition"
  9. version="1"
  10. Url="C:\Program Files\Microsoft Power BI Report Server\PBIRS\ReportServer\bin\Microsoft.Samples.ReportingServices.CustomSecurity.dll"/>
  11. </CodeGroup>

修改web.config

C:\Program Files\Microsoft Power BI Report Server\PBIRS\ReportServer\web.config
找到, 并将 “模拟” 属性设置为 false。

<identity impersonate="false" />

找到<forms>, 并将 mode 属性更改为窗体。此外, 将以下元素添加为元素的子元素, 并设置 loginurl、名称、超时和路径属性, 如下所示:

<authentication mode="Forms">
    <forms loginUrl="logon.aspx" name="sqlAuthCookie" timeout="60" path="/"></forms>
</authentication>

直接在元素之后添加以下元素。``

<authorization> 
<deny users="?" />
</authorization>

这将拒绝未经身份验证的用户访问报表服务器的权限。该元素以前建立的 loginurl 属性将未经身份验证的请求重定向到 logon.aspx 页。

创建用户表

使用CustomSecuritySample\Setup下面 CreateUserStore.sql 创建用户表