1、需求背景
由于客户有些报表数据敏感,为了不让用户随便导出报表,故提出需求:要求用户在导出报表的时候,需有导出权限的主管来输入用户名密码来授权导出。
2、实现方案
a、通过升级类增加一张维表t_exportreport,字段c_reportid
b、通过升级类增加一张回写表"报表导出权限控制表",用来添加哪些需要导出权限控制的报表
c、添加主管授权时的输入用户名密码界面
3.部署扩展包
3.1 加载扩展包
exportreportcontrol.ext,扩展包部署见扩展包部署。
3.2 扩展包主要代码
3.2.1 ExportModule类
3.2.2 ExportFilter类
package cn.com.smartbi;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import smartbi.SmartbiException;
import smartbi.decisionpanel.DecisionPanelModule;
import smartbi.decisionpanel.dashboard.DashboardBO;
import smartbi.freequery.FreeQueryErrorCode;
import smartbi.olap.OlapErrorCode;
import smartbi.olap.OlapQueryService;
import smartbi.olap.query.OlapQueryBO;
import smartbi.oltp.FreeQueryModule;
import smartbi.state.IStateModule;
import smartbi.decisionpanel.DecisionPanelModule;
import smartbi.decisionpanel.dashboard.DashboardBO;
import smartbi.freequery.FreeQueryErrorCode;
import smartbi.olap.OlapErrorCode;
import smartbi.olap.OlapQueryService;
import smartbi.olap.query.OlapQueryBO;
import smartbi.oltp.FreeQueryModule;
import smartbi.state.IStateModule;
public class ExportFilter implements Filter{
private Logger log = Logger.getLogger(ExportFilter.class);
@Override
public void destroy() {
// TODO Auto-generated method stub
}
private Logger log = Logger.getLogger(ExportFilter.class);
@Override
public void destroy() {
// TODO Auto-generated method stub
}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain){
try{
request.setCharacterEncoding("UTF-8");
HttpServletRequest req = (HttpServletRequest)request;
if(req.getRequestURI().indexOf("ExportServlet") != -1){
String actionType = request.getParameter("actionType");
if ("download".equals(actionType)) {
chain.doFilter(request, response);
return;
}
ExportModule em = ExportModule.getInstance();
String clientId = request.getParameter("clientId");
String resid = "";
if(req.getRequestURI().indexOf("/ExportServlet") != -1){
resid = request.getParameter("queryId");
}else if(req.getRequestURI().indexOf("/InsightExportServlet") != -1){
/*HttpSession session = req.getSession();
InsightBO report = (InsightBO) session.getAttribute(clientId);
if (report == null)
throw new SmartbiException(FreeQueryErrorCode.EXPORT_REPORT_NOT_FOUND);*/
resid = request.getParameter("insightId");
}else if(req.getRequestURI().indexOf("/DpExportServlet") != -1){
IStateModule stateModule = DecisionPanelModule.getInstance().getStateModule();
DashboardBO report = (DashboardBO) stateModule.getSessionAttribute(clientId);
if (report == null)
throw new SmartbiException(FreeQueryErrorCode.REPORT_CLIENT_ERROR);
resid = report.getId();
}else if(req.getRequestURI().indexOf("/OlapExportServlet") != -1){
OlapQueryBO report = (OlapQueryBO) OlapQueryService.getInstance()
.getStateModule().getSessionAttribute(clientId);
if (report == null) {
throw new SmartbiException(
OlapErrorCode.EXPORT_REPORT_NOT_FOUND);
}
resid = report.getId();
}else{
chain.doFilter(request, response);
return;
}
if(em.isInReport(resid)){
String username = request.getParameter("uname");
String password = request.getParameter("upsw");
boolean rtn = ExportModule.getInstance().isContainRole(username, password);
if(rtn){
chain.doFilter(request, response);
}else{
throw new SmartbiException(FreeQueryErrorCode.EXPORT_ERROR).setDetail("权限验证不通过!");
}
}else{
chain.doFilter(request, response);
}
}else if(req.getRequestURI().indexOf("/ssreportServlet") != -1){
String refreshType = request.getParameter("refreshType");
if("refresh".equals(refreshType)){
chain.doFilter(request, response);
}else{
ExportModule em = ExportModule.getInstance();
String resid = request.getParameter("resid");
if(em.isInReport(resid)){
String username = request.getParameter("uname");
String password = request.getParameter("upsw");
boolean rtn = ExportModule.getInstance().isContainRole(username, password);
if(rtn){
chain.doFilter(request, response);
}else{
throw new SmartbiException(FreeQueryErrorCode.EXPORT_ERROR).setDetail("权限验证不通过!");
}
}else{
chain.doFilter(request, response);
}
}
}else{
chain.doFilter(request, response);
}
}catch(Exception e){
log.error(e.getMessage(), e);
}
}
protected IStateModule getStateModule() {
return FreeQueryModule.getInstance().getStateModule();
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain){
try{
request.setCharacterEncoding("UTF-8");
HttpServletRequest req = (HttpServletRequest)request;
if(req.getRequestURI().indexOf("ExportServlet") != -1){
String actionType = request.getParameter("actionType");
if ("download".equals(actionType)) {
chain.doFilter(request, response);
return;
}
ExportModule em = ExportModule.getInstance();
String clientId = request.getParameter("clientId");
String resid = "";
if(req.getRequestURI().indexOf("/ExportServlet") != -1){
resid = request.getParameter("queryId");
}else if(req.getRequestURI().indexOf("/InsightExportServlet") != -1){
/*HttpSession session = req.getSession();
InsightBO report = (InsightBO) session.getAttribute(clientId);
if (report == null)
throw new SmartbiException(FreeQueryErrorCode.EXPORT_REPORT_NOT_FOUND);*/
resid = request.getParameter("insightId");
}else if(req.getRequestURI().indexOf("/DpExportServlet") != -1){
IStateModule stateModule = DecisionPanelModule.getInstance().getStateModule();
DashboardBO report = (DashboardBO) stateModule.getSessionAttribute(clientId);
if (report == null)
throw new SmartbiException(FreeQueryErrorCode.REPORT_CLIENT_ERROR);
resid = report.getId();
}else if(req.getRequestURI().indexOf("/OlapExportServlet") != -1){
OlapQueryBO report = (OlapQueryBO) OlapQueryService.getInstance()
.getStateModule().getSessionAttribute(clientId);
if (report == null) {
throw new SmartbiException(
OlapErrorCode.EXPORT_REPORT_NOT_FOUND);
}
resid = report.getId();
}else{
chain.doFilter(request, response);
return;
}
if(em.isInReport(resid)){
String username = request.getParameter("uname");
String password = request.getParameter("upsw");
boolean rtn = ExportModule.getInstance().isContainRole(username, password);
if(rtn){
chain.doFilter(request, response);
}else{
throw new SmartbiException(FreeQueryErrorCode.EXPORT_ERROR).setDetail("权限验证不通过!");
}
}else{
chain.doFilter(request, response);
}
}else if(req.getRequestURI().indexOf("/ssreportServlet") != -1){
String refreshType = request.getParameter("refreshType");
if("refresh".equals(refreshType)){
chain.doFilter(request, response);
}else{
ExportModule em = ExportModule.getInstance();
String resid = request.getParameter("resid");
if(em.isInReport(resid)){
String username = request.getParameter("uname");
String password = request.getParameter("upsw");
boolean rtn = ExportModule.getInstance().isContainRole(username, password);
if(rtn){
chain.doFilter(request, response);
}else{
throw new SmartbiException(FreeQueryErrorCode.EXPORT_ERROR).setDetail("权限验证不通过!");
}
}else{
chain.doFilter(request, response);
}
}
}else{
chain.doFilter(request, response);
}
}catch(Exception e){
log.error(e.getMessage(), e);
}
}
protected IStateModule getStateModule() {
return FreeQueryModule.getInstance().getStateModule();
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
}
public void init(FilterConfig arg0) throws ServletException {
}
}