web报表控件FineReport中模板访问权限设置
1、前提准备
报表工程:如直接使用内置Jetty服务器中的报表工程WebReport,端口为8075;
用户系统:如用户工程PFDemo发布于IIS服务器,端口为80,可省;
报表工程已经配置了身份验证,并实现了单点登录,如其中存在用户A/123、B/123。
2、 载入FR提供的BouncyCastle.Crypto.dll及Com.FineReport.dll数字签名库
下载FR提供的BouncyCastle.Crypto.dll及Com.FineReport.dll数字签名库;
在用户.net系统中载入这两个数字签名库。
3、用户系统中添加一个web接口给报表工程提供公钥
用户系统中提供一个web接口,如创建一个getKey.aspx,可以通过http://localhost/getKey.aspx来获取公钥,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="getKey.aspx.cs" Inherits="PFDemo.getKey" %>
4、在页面Page_Load事件中调用我方提供的dll的接口,返回公钥信息,对应的后台cs代码getKey.aspx.cs为:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.FineReport.net;
namespace PFDemo
{
public partial class getKey : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
// 获得公钥的两个参数,传回
String modulus = FRPrivilegeFilterHelper.getPublicKeyModulus();
String exponent = FRPrivilegeFilterHelper.getPublicKeyExponent();
Response.Write(modulus + "&" + exponent);
}
catch (Exception e1)
{
Response.Write("error");
}
return;
}
}
}
}
5、 报表工程中获取用户系统的公钥
登陆FR管理平台http://localhost:8075/WebReport/ReportServer?op=fr_platform,选择权限配置>详细权限配置;
数字签名密钥地址为http://localhost/getKey.aspx,点击提交:

6、用户系统发送报表请求加入数字签名信息
如最上图中登陆后的主界面为index.aspx,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="PFDemo._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>PFDemo</title>
<script type="text/javascript">
function viewReport(report) {
var f = document.getElementById("frame");
f.src = "/report.aspx?report=" + report;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table style="width:1018px;" border="2">
<colgroup>
<col width="150px;"/>
<col/>
</colgroup>
<tr style="height:30px;">
<td style="font-size:24pt;background-color:blue;color:#EFEFEF;" colSpan="2">
Privilege Demo
<span style="margin-left:500px;">Current user:</span>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr style="height:730px;">
<td style="vertical-align:top;">
<ul>
<li style="cursor:pointer;color:blue;">
<asp:HyperLink ID="HyperLink1" runat="server" onclick="javascript:viewReport('GettingStarted.cpt');">Report1(A,B)</asp:HyperLink>
</li>
<li style="cursor:pointer;color:blue;">
<asp:HyperLink ID="HyperLink2" runat="server" onclick="javascript:viewReport('doc/Primary/CrossReport/Cross.cpt');">Report2(A)</asp:HyperLink>
</li>
</ul>
</td>
<td>
<iframe id="frame" name="frame
</td>
</tr>
</table>
</form>
</body>
</html>
当点击左边报表节点时,触发viewReport这个js方法,通过iframe执行report.aspx文件,并传递请求查看的报表名字。
7、在report.aspx中利用FR数字签名库提供的接口,对需要访问的报表路径、报表浏览形式(op)、当前用户名与当前系统时间进行数字签名,得到签名信息,并将签名信息加入请求中转发给报表工程,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report.aspx.cs" Inherits="PFDemo.Report" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
8、对应的后台cs代码Report.aspx.cs为:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.FineReport.net;
namespace PFDemo
{
public partial class Report : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
String reportPath = Request.QueryString["report"];
String username = (String)Session["username"]; // 获取当前用户名
String op = "page"; // 默认分页预览时,null即可
long curtime = FRPrivilegeFilterHelper.getCurTime4JavaPlatform(); // 获取与java平台同步的当前时间的毫秒数
String signInfo = FRPrivilegeFilterHelper.sign(reportPath, op, username, curtime); // 将上述获得的四个要素传入,获得相关的数字签名信息
String path = "http://localhost:8075/WebReport/ReportServer?reportlet=" + reportPath + "&op=" + op
+ "&" + FRPrivilegeFilterHelper.FR_DIGITALSIGNATURE_CURRENT_TIME + "=" + curtime
+ "&" + FRPrivilegeFilterHelper.FR_DIGITALSIGNATURE_INFO + "=" + signInfo; // 模拟拼接url,其实就是原有正常请求之后添加上签名的当前时间,和签名信息
Response.Redirect(path, true);
}
}
}
}
报表工程得到报表请求后进行验证,对reportlet参数值、op参数值、报表系统中当前用户名、发送来的系统时间进行数字签名验证是否正确。
且若用户系统发送来的签名时系统时间,与当前时间差超过90秒,将视为超时。如果都验证通过,则可以访问报表,否则提示没有权限查看。
9、重启服务器
重启用户系统服务器及报表服务器(注意:必须先启动用户系统再启动报表系统),设置即可生效,效果如下图。
