gpt4 book ai didi

session - 身份验证为匿名的用户已尝试访问拥有的 session

转载 作者:行者123 更新时间:2023-12-05 04:15:08 28 4
gpt4 key购买 nike

在我登录之前,我可以点击我的安全约束目录之外的任何内容。如果我尝试转到安全约束目录内的某个位置,它会将我重定向到表单登录页面。如您所料。

登录后,我可以继续我的业务,​​并访问我的安全约束内外的资源。

但是,当 LTPA token 过期(仍然有事件 session )并且我尝试转到不受限制的页面时,比方说被重定向到登录页面,我在标题中收到错误。

所以我想弄清楚一些事情:1. 我能否让 LTPA token 像我的 session 一样不过期?2. 我可以在 LTPA token 过期时过期我的 session 吗?3、为什么我不能匿名访问不受限制的页面?它清楚地认识到我的 LTPA token 已过期并尝试重定向我以进行登录。在这一点上它失败了。

好的,所以找了个带过滤器的地方。过滤器将未登录的人重定向到登录页面。但问题又是,一旦 ltpa token 过期,此行就会失败 ((HttpServletRequest) request).getSession(false),并在标题中抛出异常,UnauthorizedSessionRequestException。因此,正如您所见,我试图捕获该错误并注销。哎呀,抛出另一个 UnauthorizedSessionRequestException。那么我如何才能不使用 session 呢?

@Override
public void doFilter(final ServletRequest request, final ServletResponse response,
final FilterChain chain) throws IOException, ServletException
{
final String sourceMethod = "doFilter";
if (logger.isLoggable(Level.FINER)) {
logger.entering(sourceClass, sourceMethod, new Object[] { request, response, chain });
}

try {
final HttpSession session = ((HttpServletRequest) request).getSession(false);
final UserBean user = (session != null) ? (UserBean) session.getAttribute("userBean")
: null;
if (user == null || (user != null && !user.isLoggedOn())) {
final HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect("../login.jsf");
}
} catch (final UnauthorizedSessionRequestException exc) {
((HttpServletRequest) request).logout();
final HttpServletResponse res = (HttpServletResponse) response;
res.sendRedirect("../login.jsf");
} catch (final Exception exc) {
final ServletException exception = new ServletException(
"[UserBeanFilter] Exception doFilter.", exc);
logger.throwing(sourceClass, sourceMethod, exception);
throw exception;
}
chain.doFilter(request, response);
logger.exiting(sourceClass, sourceMethod);
}

最佳答案

我能否让 LTPA token 像我的 session 一样不过期?

不幸的是没有。 LTPA token 有固定超时, session 有不活动超时。如果您需要,您可以将 LTPA token 超时延长到例如 8 小时以避免过期。

为什么我不能匿名访问不受限制的页面?

因为它试图访问之前与经过身份验证的用户相关联的 session 。您可以通过禁用 Security integration 来允许匿名访问 session 在 Servers > Server Types > WebSphere application servers > server_name > Session management 中设置.

您还可以检查 Use available authentication data when an unprotected URI is accessedSecurity > Global security > Authentication > Web and SIP security > General settings 中启用.

它清楚地认识到我的 LTPA token 已过期并尝试重定向我登录。在这一点上它失败了。

尝试在您的登录页面上禁用 session 支持,如果它是 jsp 则尝试设置 <@page session="false">在页面中。

更新

因此,如果您想进行预防,您可以检查 LTPA 过期时间,并基于 token 过期前的注销用户,例如 5 分钟前。当然,如果用户在那 5 分钟内处于非事件状态,您仍然会得到该异常,但对于 90% 的情况来说这应该足够了。

要获取 token 的到期时间,请使用以下代码(伪代码):

WSSubject subject = WSSubject.getRunAsSubject();
Set<WSCredential> credentials = subject.getPublicCredentials(WSCredential.class);

for(WSCredential credential : credentials) {
// in the most cases you will find only one credential, but if you
// want to be sure you can check credential OID
System.out.println("Exp date:" + new Date(credential.getExpiration()));
System.out.println("userName: " + credential.getSecurityName());
System.out.println("cred: " + credential.getOID());

// if expiration date closer than your threshold - logout user
// ...

}



OIDs for auth mechanisms

BasicAuth (GSSUP): oid:2.23.130.1.1.1
KRB5: OID: 1.2.840.113554.1.2.2
LTPA: oid:1.3.18.0.2.30.2

更新 2

好的,我为您找到了更好的解决方案。

只需在 session 管理器中设置以下标志:

InvalidateOnUnauthorizedSessionRequestException=true

InvalidateOnUnauthorizedSessionRequestException

Set this property to true if, in response to an unauthorized request, you want the session manager to invalidate a session instead of issuing an UnauthorizedSessionRequestException error message.

When a session is invalidated, the requester can create a new session, but does not have access to any of the previously saved session data. This invalidation allows a single user to continue processing requests after a logout while still protecting session data.

在此处查看详细信息 Session management custom properties

关于session - 身份验证为匿名的用户已尝试访问拥有的 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33244139/

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