JSF 2:重定向到外部URL并添加头部参数

时间:2016-07-04 15:15:38

标签: http jsf redirect jsf-2 http-headers

我目前的情况:我们有一个Web应用程序,其中使用连接到外部Shibboleth IDP(IdentityProvider)的Shibboleth SP(服务提供商)完成身份验证/授权,这就像魅力一样。基本上,Shibboleth拦截了对网站受限制部分的呼叫,我们被重定向到外部网站,我们可以使用我们的eID登录。 登录后,我们将被Shibboleth引用到该页面,其中不同的头部属性由与登录用户相关的shibboleth添加。 我们创建一个UserPrincipal并将其放在应用程序的SecurityContext上。

现在另一个应用程序想要使用相同的Shibboleth和外部eID页面登录。所以我想创建一个不同的网址,如/ private / loginApp2

登录后,我将用户引向xhtml页面:

<!DOCTYPE html>
<html xmlns:f="http://java.sun.com/jsf/core" >
    <f:metadata>
        <f:event type="preRenderView" listener="#{myBean.redirect}"/>
    </f:metadata>
</html>

这是我的豆子:

@Component
@SessionScoped
public class MyBean {

@Autowired
private UserInformationBean userInformationBean;

public void redirect() throws IOException {
    final String jwtToken = JwtTokenCreator.createJwtToken(SecurityContext.getUserPrincipal());
    ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();

    HttpServletRequest req = (HttpServletRequest) ec.getRequest();
    MutableHttpServletRequest mutableRequest = new MutableHttpServletRequest(req);
    mutableRequest.putHeader("kid", jwtToken);
    ec.setRequest(mutableRequest);
    ec.redirect("http://external.url");
}

在myBean中,我最初的计划是

  • 从SecurityContext
  • 获取loggedIn用户(UserPrincipal)
  • 基于UserPrincipal属性构建JWT(Json Web Token)
  • 将此JWT添加到http标头
  • 执行重定向到其他应用程序

但正如我所理解的,这似乎不可能从ExternalContext执行重定向并保留标题(因为HTTP会创建一个新请求?) 我可以将jwtToken添加为queryParameter(由https加密),但我认为这也不是一个好主意。

有人知道我的情况下最干净的解决方案是什么?

0 个答案:

没有答案
相关问题