2015-10-20 75 views
1

在我登录之前,我可以在我的安全约束目录之外打任何内容。如果我尝试去安全约束目录内的一个位置,它会将我重定向到表单登录页面。正如你所期望的那样。经过身份验证的用户已尝试访问所拥有的会话

一旦登录,我就可以开始我的业务,​​并在我的安全约束条件之外和内部寻找资源。

但是,当LTPA令牌到期(仍然有一个活动会话),我试图去一个无限制的页面,让我们说像被重定向到登录页面,我得到的标题错误。

所以我想弄清楚一些事情: 1.我可以让LTPA令牌不像我的会话那样过期吗? 2.当LTPA令牌执行时,我可以过期吗? 3.为什么我无法匿名访问不受限制的页面?很明显,我的LTPA令牌已过期,并尝试重定向我登录。在哪一点失败。

好吧,所以得到了一个过滤器的地方。过滤器将未登录的人重定向到登录页面。但问题再次是一旦ltpa令牌过期,该行失败((HttpServletRequest) request).getSession(false)抛出标题中的异常UnauthorizedSessionRequestException。正如你所看到的,我试图捕捉那个错误并且注销。哪一个,woops,抛出另一个UnauthorizedSessionRequestException。那我该如何不使用会话呢?

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

这个jsf如何关联?你的问题没有显示任何关系 – Kukeltje

+0

这是一个JSF应用程序,我认为这是相关的信息。 –

+0

如果它与问题相关,这是恰当的。你还可以添加'java','energy','global-warming'(由燃烧运行java所需的化石燃料引起;-))。请删除它 – Kukeltje

回答

1

我可以得到LTPA令牌不会过期像我的会议?

不幸的是没有。 LTPA令牌具有固定超时,并且会话具有不活动超时。如果需要,可以将LTPA令牌超时例如延长到8小时以避免过期。

为什么我无法匿名访问无限制的页面?

因为它试图访问以前与认证用户关联的会话。您可以通过禁用Servers > Server Types > WebSphere application servers > server_name > Session management中的Security integration设置来允许匿名访问会话。

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

它很清楚地认识到我的LTPA令牌已过期并尝试重定向我登录。在哪一点失败。

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

UPDATE

所以,如果你想成为预防,可以检查LTPA失效,并基于该注销用户标记过期,例如5分钟之前之前。当然,如果用户在5分钟内不活动,你仍然会得到这个例外,但是对于90%的情况来说,这应该足够了。

获得令牌期满使用下面的代码(伪代码):

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

好吧,我发现你更好的解决方案。

只需设置会话管理器中的下列标志:

InvalidateOnUnauthorizedSessionRequestException=true

InvalidateOnUnauthorizedSessionRequestException

如果在响应未经授权的请求, 你希望会话此属性设置为true经理无效会话而不是 发出UnauthorizedSessionRequestException错误消息。

当会话失效时,请求者可以创建一个新会话, ,但不能访问任何先前保存的会话数据。 该失效允许单个用户在注销后继续处理请求 ,同时仍保护会话数据。

见这里Session management custom properties

+0

1.我希望有一种方法可以在没有用户重新登录的情况下以编程方式重新生成LTPA令牌。并且使用其他业务应用程序延长群集的超时时间将会很麻烦。 2.我宁愿不开放匿名访问会话。第二个选项已启用。如果禁用,则获得SECJ0369E:使用LTPA时身份验证失败。异常是com.ibm.websphere.wim.exception.WIMException。我认为这是因为登录页面帖子不再获取认证信息。 3.我正在使用JSF 2.2。我没有找到像这样的选项。 –

+0

另外,感谢您的回复。我也尝试在网站上添加一个过滤器,这会使登录页面上的会话无效。但它看起来像过滤器没有得到调用之前我得到的错误。 –

+0

我试了一些更多的过滤器,并打了一个死胡同。查看更新的原始帖子。 –

0

对于Webshepre 8.5的详细信息。转至服务器>服务器类型> WebSphere应用程序服务器>服务器名称(服务器)>会话管理(看右边菜单上) 自定义属性 - >添加新的特性

Name =InvalidateOnUnauthorizedSessionRequestException 
Value=true. 

保存并重新启动Eclipse中的服务器。 我在SOAPUI中测试webservice时遇到了这个问题。

相关问题