注销JSF,在Glassfish 3中使用SSL
我还没有找到解决这个问题的真正办法,即使它真的很普遍 我有这样的背景:注销JSF,在Glassfish 3中使用SSL,jsf,logout,Jsf,Logout,我还没有找到解决这个问题的真正办法,即使它真的很普遍 我有这样的背景: 运行在Glassfish服务器v3.1、JDK6上的JSF应用程序。在我的个人电脑中使用WinVista(最后一个应该不重要) 使用SSL和基本身份验证(容器的安全性) 我已经在支持bean中完成了logout()方法,使会话无效并发送重定向 我不能让容器再次显示登录框来验证用户,并且可以更改用户的身份。。。我的用户总是可以返回,按浏览器中的“后退”按钮或只写URL,然后在假定不应该存在会话的情况下继续在那里进行操作 我
- 运行在Glassfish服务器v3.1、JDK6上的JSF应用程序。在我的个人电脑中使用WinVista(最后一个应该不重要)
- 使用SSL和基本身份验证(容器的安全性)
- 我已经在支持bean中完成了logout()方法,使会话无效并发送重定向
private void setName() {
this.name = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
}
我用这个名字来执行操作
那么对于注销,我的xhtml有以下代码:
<h:panelGroup id="logOut">
<h:form>
<h:commandLink id="linkLogOut" action="#{visitor.logout}" value=" Clic here to Log Out" />
</h:form>
</h:panelGroup>
我声明我的支持bean具有:
@Named(value="visitor")
@SessionScoped
…同时,我正在从部署描述符执行重定向。。。而且是一样的
如果我关闭浏览器,会话将丢失,容器将再次询问我用户/通行证
有什么建议吗
非常感谢
亚历杭德罗
我不能让容器再次显示登录框来验证用户,并且可以更改用户的身份。。。我的用户总是可以返回,按浏览器中的“后退”按钮或只写URL,然后在假定不应该存在会话的情况下继续在那里进行操作
这些页面可能从浏览器缓存中显示,而不是从服务器重新请求。要停止此操作,请创建一个映射到感兴趣的URL模式(*.jsf
maybe?),并在doFilter()
方法中执行以下工作:
HttpServletResponse httpResponse = (HttpServletResponse) response;
httpResponse.setHeader("Cache-Control", "no-cache,no-store,must-revalidate"); // HTTP 1.1
httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0
httpResponse.setDateHeader("Expires", 0); // Proxies.
chain.doFilter(request, response);
测试前请清除浏览器缓存。非常感谢您的回答 我请了几天假。。。没有回复这个帖子 我只想分享我的解决方案 基本身份验证绑定到浏览器,一旦您完成登录,应关闭浏览器以完成注销。。。什么不那么优雅 我改为表单身份验证,创建表单,并将用户信息发布到一个servlet,该servlet根据我的领域验证用户凭据,该servlet将用户重定向到应用程序或错误页面。显然,必须对web.xml中的安全约束进行适当的配置 我在这里分享我的解决方案: 登录页面:
<!-- This is the login page that implement the "Form Base" login -->
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>Login Form</title>
</h:head>
<h:body>
<h2>Welcome to the secure messaging service!:</h2>
<form name="loginForm" method="POST" action="j_security_check">
<p><strong>Please type your user name: </strong>
<input type="text" name="j_username" size="25" /></p>
<p><strong>Please type your password: </strong>
<input type="password" size="15" name="j_password" /></p>
<p>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
</p>
</form>
</h:body>
以及配置文件的必需部分
<security-constraint>
<display-name>Web Interface</display-name>
<web-resource-collection>
<web-resource-name>SSL Pages</web-resource-name>
<description/>
<url-pattern>/</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>All site is restricted</description>
<role-name>user</role-name>
</auth-constraint>
<user-data-constraint>
<description>Secure connection is required</description>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>webapps</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/error.xhtml</form-error-page>
</form-login-config>
</login-config>
网络界面
SSL页面
/
所有网站均受限制
使用者
需要安全连接
保密的
类型
网络应用
/login.xhtml
/error.xhtml
我希望这对其他人有用
祝你一切顺利
亚历杭德罗
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
String username;
String password;
username = request.getParameter("j_username").toString();
password = request.getParameter("j_password").toString();
request.login(username, password);
response.sendRedirect("/SecureMessageWebInterface/");
} catch (Exception e) {
response.sendRedirect("error.xhtml");
}
}
<security-constraint>
<display-name>Web Interface</display-name>
<web-resource-collection>
<web-resource-name>SSL Pages</web-resource-name>
<description/>
<url-pattern>/</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>All site is restricted</description>
<role-name>user</role-name>
</auth-constraint>
<user-data-constraint>
<description>Secure connection is required</description>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>webapps</realm-name>
<form-login-config>
<form-login-page>/login.xhtml</form-login-page>
<form-error-page>/error.xhtml</form-error-page>
</form-login-config>
</login-config>