我们使用spring security根据来自外部应用程序的一些用户详细信息(如userid)对用户进行身份验证,并使用安全上下文持有者执行授权.我们使用AbstractAuthenticationProcessingFilter的自定义实现和CustomAuthenticationProvider的自定义实现,并将自己的UserDetailsServiceImpl注入到提供程序中,以便从db获取用户详细信息.
当单个用户尝试登录时,它可以正常工作,创建身份验证对象并将其正确设置到SecurityCOntextHolder中.但是当另一个用户尝试登录时,旧的身份验证对象会被新的身份验证对象覆盖.看起来不会在每次用户登录时创建新会话.
过滤器和提供程序的实现如下 -
public class DefaultAuthenticationProcessingFilter extends
AbstractAuthenticationProcessingFilter {
private final static Logger logger = LoggerFactory.getLogger(DefaultAuthenticationProcessingFilter.class);
private static final String INTERCEPTOR_PROCESS_URL = "/sso/landingpage.action";
public DefaultAuthenticationProcessingFilter() {
super(INTERCEPTOR_PROCESS_URL);
}
public DefaultAuthenticationProcessingFilter(
String defaultFilterProcessesUrl) {
super(defaultFilterProcessesUrl);
Assert.notNull(defaultFilterProcessesUrl, "Configuration error :: DefaultFilterProcessesUrl must be specified");
}
/**
* Method to do authentication of user
*/
@Override
public Authentication attemptAuthentication(HttpServletRequest request,
HttpServletResponse response) throws AuthenticationException,
IOException, ServletException {
logger.info("Authenticating the user .....");
Authentication authResult = null;
try {
String eid = request.getParameter("EID"); …Run Code Online (Sandbox Code Playgroud) 我们在 Jquery 中使用短轮询定期向服务器发送 ajax 请求,以检查服务器上是否有任何更新。轮询工作正常,但因此,会话始终保持活动状态。除非用户手动注销或关闭浏览器,否则会话永远不会超时。这可以通过在轮询本身中设置超时来实现,但我们希望在服务器端处理超时逻辑。
有没有办法在这些 ajax 调用期间保持会话空闲。或者我们需要手动处理超时。
我们使用 tomcat 作为应用服务器,使用 spring mvc 作为视图和控制器。一旦创建新会话,我就设置了会话超时。
session.setMaxInactiveInterval(7200); //2小时
在这方面的任何帮助表示赞赏。
谢谢,伊卡纳特