gpt4 book ai didi

jsf - 使用 PhaseListener 而不是 Servlet Filter 进行授权的限制

转载 作者:行者123 更新时间:2023-12-01 10:41:51 26 4
gpt4 key购买 nike

我目前正在使用如下所示的 PhaseListener 来执行用户授权。

private PhaseId phaseId = PhaseId.RESTORE_VIEW;

@Override
public void afterPhase(PhaseEvent event) {

FacesContext fc = event.getFacesContext();
boolean isOnAllowedPage = false;
String[] allowedPages = choseRightPages(); // chose pages for role

for (String s : allowedPages) {
if (fc.getViewRoot().getViewId().lastIndexOf(s) > -1) {
isOnAllowedPage = true;
break;
}
}

if (!isOnAllowedPage) {
NavigationHandler nh = fc.getApplication().getNavigationHandler();
nh.handleNavigation(fc, null, "prohibited");
}
}

它做我想做的事,但我没有看到它列在 How to handle authentication/authorization with users in a database? 中和 this Coderanch topic titled "authorization with phaselistener problem"还提到了以下内容:

You shouldn't couple authorization that tight with JSF. Better make use of container managed authentication and/or a simple filter acting on an url-pattern covering the protected pages.

我不完全理解在执行用户授权时使用 PhaseListener 而不是 Filter 的局限性。谁能给我解释一下?

最佳答案

PhaseListener 仅在 JSF 请求(即调用 FacesServlet 的 HTTP 请求)上触发。当执行非 JSF 请求时它不会被触发,因此暴露了非 JSF 请求的潜在安全漏洞。无论目标 servlet 是什么,都可以在每个 HTTP 请求上触发 servlet Filter

换句话说:HTTP 请求授权不应与可用的 FacesContext 相关联,而应与可用的 ServletRequest 相关联。始终尝试授权尽可能“低级别”。

关于jsf - 使用 PhaseListener 而不是 Servlet Filter 进行授权的限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29600300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com