Http JSF2:重定向到外部url并添加头参数

Http JSF2:重定向到外部url并添加头参数,http,jsf,redirect,jsf-2,http-headers,Http,Jsf,Redirect,Jsf 2,Http Headers,我现在的情况是:我们有一个web应用程序,其中身份验证/授权是使用一个Shibboleth SP(服务提供商)完成的,该SP连接到一个外部Shibboleth IDP(IdentityProvider),这就像一个符咒。基本上,对网站受限部分的呼叫被Shibboleth拦截,我们被重定向到外部网站,在那里我们可以使用eID登录。 登录后,Shibboleth会引用该页面,Shibboleth会添加与登录用户相关的不同标题属性。 我们创建一个UserPrincipal并将其放置在应用程序的Secu

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

现在,另一个应用程序希望使用相同的Shibboleth和外部eID页面登录。所以我想创建一个不同的url来拦截,比如/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>
在myBean中,我最初的计划是

  • 从SecurityContext获取loggedIn用户(UserPrincipal)
  • 基于UserPrincipal属性构建JWT(Json Web令牌)
  • 将此JWT添加到http头
  • 执行指向其他应用程序的重定向
但据我所知,这似乎不可能从ExternalContext执行重定向并保留标头(因为HTTP创建了一个新的请求?) 我可以将jwtToken添加为queryParameter(由https加密),但我认为这也不是一个好主意

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

@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");
}