这里的问题是,当任何 api 被命中时,我们如何强制 tomcat 服务器验证智能卡仍然存在。或者如何在卡被移除后强制重新协商 SSL 以及密码验证。
我正在开发一个应用程序并使用 Tomcat 作为服务器。我必须通过智能卡对用户进行身份验证。因此,当用户点击 Web 应用程序时,浏览器会要求选择证书并要求输入该智能卡的密码。
上述功能运行良好。现在的情况是,每当智能卡被移除时,Tomcat 服务器应该知道它的移除,并要求选择证书并再次验证 pin。
我在注销 API 调用时尝试了以下不同的代码,但似乎没有任何效果:
代码 1:
sc = SSLContext.getInstance("SSL");
int i = sc.getServerSessionContext().getSessionTimeout();
sc.getServerSessionContext().setSessionTimeout(0);
代码 2:
Object sslSessionMgr = paramHttpServletRequest.getAttribute("javax.servlet.request.ssl_session_mgr");
//SSLSessionManager sslSessionMgr = (SSLSessionManager) paramHttpServletRequest.getAttribute("javax.servlet.request.ssl_session_mgr");
if (sslSessionMgr != null) {
try {
Method invalidateSession = Class.forName("org.apache.tomcat.util.net.SSLSessionManager").getMethod("invalidateSession");
invalidateSession.setAccessible(true);
invalidateSession.invoke(sslSessionMgr);
SSLSessionManager a = (SSLSessionManager) sslSessionMgr;
a.invalidateSession();
paramHttpServletResponse.setHeader("Connection", "close");
} catch (Exception e) {
e.printStackTrace();
}
}
代码 3:Cookie 删除
if (paramHttpServletRequest.getCookies() !=null && paramHttpServletRequest.getCookies().length > 0) {
for (Cookie cookie : paramHttpServletRequest.getCookies()) {
if (cookie.getName().equals("JSESSIONID")) {
cookie.setMaxAge(0);
Calendar.getInstance();
paramHttpServletResponse.setHeader("Set-Cookie", "JSESSIONID="+cookie.getValue()+";path=/capehenry;Secure;HttpOnly;expires = Friday, 04-Feb-07 22:03:38 GMT;");
}
}
}
代码 4:
httpSession.setMaxInactiveInterval(1);
请建议如何解决此问题。