Tableau报表外嵌Web页面单点登录

  1. 登录TSM添加受信任主机,保存后重启
  2. 获取受信任的账户票据
  3. 通过带有票据信息的url即可免登录访问Tableau(单点登录

方案:  客户端à客户端服务器à代理服务器(Nginx)à大数据服务器

Linux下Nginx配置(访问https)

1.编译:带有ssl模块

./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module & make

2.修改nginx.conf 文件

       在Server节点中配置如下:

       server {

        listen       80;

        server_name  localhost;

                   access_log  logs/access.log  main;

        error_log logs/error.log error;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {

             proxy_pass  http://finereportpool;

            root   html;

            index  index.html index.htm;

        }

        location /bigdata {

             proxy_pass  https://xxx/xxx/;   #需要代理的地址

            root   html;

            index  index.html index.htm;

        }

}

停止nginx服务

指令:./nginx –s stop

替换编译后的文件:

替换nginx.conf 文件

启动nginx

指令:./nginx

重启nginx

指令:./nginx  -s reload

启动nginx后访问  http://xxx/xxx即可跳转

配置受信任主机:

      

测试获取受信任用户的IP:

   编写测试页面:

Trusted Ticket Requester

Trusted Ticketer

 

   

      

     

   

   

     

     

   

   

     

     

   

   

     

     

   

   

     

     

   

 

Username
Server
Client IP (optional)
Site (leave blank for Default site; otherwise enter the site name)
 

Be sure to add your IP as a Trusted IP address to the server

运行如下:

Username:TableauServer中已添加的用户

Server:TableauServer的地址

Client IP:受信任主机的IP

Site: 站点名称  单一站点不填   多站点:输入站点名称

点击Get Ticket  返回一个24位随机码  这就是客户端的受信任票据信息

.NET中的应用:

  1. 获取票据信息

Post

///

        /// 获取票证

        ///

        ///

        public static string getTrustedTicket(string wgserver, string user)

        {

            var client = new RestClient(wgserver);

            client.Timeout = -1;

            var request = new RestRequest(Method.POST);

            request.AddHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");//请求需要添加的信息

            request.AddParameter("username", user);

            IRestResponse response = client.Execute(request);

            var ticketServer = response.Content.ToString();

            return ticketServer;

        }

  1. 拼接访问URL

public string getTicketUrl()

        {

            var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build();

            string tableauServer = configuration["TableauServer"];//TableauServer地址

            string Nginx = configuration["Nginx"];//Nginx服务器地址

            string TableauReport = configuration["EnergyAndShipping"];//报表后缀

            string user = configuration["User"];//Tableau添加的用户名

            string ticket;

            string ticketUrl = "";

            try

            {

                ticket = getTrustedTicket(Nginx, user);

                if (!ticket.Equals("-1"))

                {

                    ticketUrl = tableauServer + "/" + ticket + "/#" + TableauReport;

                }

                else

                {

                    return "-1";

                }

            }

            catch (Exception ex)

            {

                return ("获取票据信息失败!" + ex.Message); ;

            }

            return ticketUrl;

        }

  1. 前端报表渲染

下载需要的css和js文件

    

        

        

        

        

        

页面添加一个div   id自定义:例如:tableauViz

Js添加代码:

initializeViz();//方法调用

function initializeViz() {

    var placeholderDiv = document.getElementById("tableauViz");

    var url = TicketUrl;//后台返回的带有票据信息的url

    var options = {

        width: placeholderDiv.offsetWidth,

        height: placeholderDiv.offsetHeight,

        hideTabs: true,

        hideToolbar: true,

        onFirstInteractive: function () {

            workbook = viz.getWorkbook();

            activeSheet = workbook.getActiveSheet();

        }

    };

    viz = new tableau.Viz(placeholderDiv, url, options);

}

你可能感兴趣的