【发布时间】:2014-11-04 14:17:51
【问题描述】:
我正在使用 Apache Tomcat 和 Java EE 开发一个简单的 Web 应用程序。
我正在使用我自己的 JDBC 域领域来保护和验证用户,并且我正在使用带有 j_security_check 的基本身份验证方法。
我已经实现了一个注销 Servlet,一切正常。但是当我注销并尝试再次登录时,应用程序或浏览器正在使用以前的凭据,甚至没有要求我输入另一个凭据。它只是使用使用的最新凭据自动登录。只有当我重置服务器并关闭浏览器 (Chrome) 时,tomcat 才会再次要求提供凭据。
我的目标是防止这种自动登录过程。 ¿ 我是不是做错了什么?
更新:我的注销 Servlet 正在执行以下操作:
response.setHeader("Cache-Control", "no-cache, no-store");
response.setHeader("Pragma", "no-cache");
request.getSession().removeAttribute("logonSessData");
request.getSession().invalidate();
response.sendRedirect(request.getContextPath() + "/index.jsp");
我的登录 web.xml 看起来像这样:
<security-constraint>
<display-name>userConstraint</display-name>
<web-resource-collection>
<web-resource-name>User pages</web-resource-name>
<description/>
<url-pattern>/users/*</url-pattern>
<url-pattern>/retos/misiones/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description/>
<role-name>user</role-name>
</auth-constraint>
<user-data-constraint>
<description/>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>SPERO</realm-name>
</login-config>
<security-role>
<description>Usuario registrado de SPERO</description>
<role-name>user</role-name>
</security-role>
<resource-ref>
<description>Spero DataBase Connection Pool</description>
<res-ref-name>jdbc/spero</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
【问题讨论】:
-
您的注销 servlet 做什么?它是否正确地使会话无效?
-
是的,我已经检查过,当我发送错误的凭据数据时,容器会拒绝访问。所以我确定这不是身份验证问题
标签: java apache jsp tomcat j-security-check