在JSF中重定向到外部URL时的基本身份验证

问题描述 投票:0回答:1

在重定向到JSF中的外部URL时,如何为请求添加基本身份验证。

我需要从JSF应用程序点击按钮下载报告(由SSRS以Excel格式提供),报告的网址格式为 -

http://report-server-host/ReportServer/Pages/ReportViewer.aspx?reportName&rs:Format=Excel

我找到了一种使用FacesContext从支持bean重定向到此页面的方法。

FacesContext.getCurrentInstance().getExternalContext().redirect(path); 

但是报表服务器需要基本身份验证,如何在执行此重定向时添加它?

jsf redirect servlets
1个回答
0
投票

您可以像这样在URL本身中添加用户名和密码

http://username:password@report-server-host/ReportServer/Pages/ReportViewer.aspx?reportName&rs:Format=Excel


要将基本身份验证标头转换为用户名:密码格式,请使用Base64解码器。

如果标题类似于Basic {TOKEN},其中{TOKEN}是Base64编码的字符串(类似于dXNlcm5hbWU6cGFzc3dvcmQ=),那么重定向URL应该是

  String auth = new String(Base64.getDecoder().decode(TOKEN));

  path = path.replaceFirst("://", "://" + auth + "@");

  FacesContext.getCurrentInstance().getExternalContext().redirect(path);

由于我没有评论的声誉,我在这里回复你的评论。 username:password@部分不需要进行URL转义。

© www.soinside.com 2019 - 2024. All rights reserved.