注销 JSF,在 Glassfish 3 中使用 SSL
我还没有找到这个问题的真正解决方案,即使它确实很常见......
我有这样的上下文:
- 在 Glassfish Server v3.1、JDK6 上运行的 JSF 应用程序。全部在我的带有 WinVista 的个人计算机上(最后一点应该不重要)。
- 使用 SSL 和基本身份验证(容器的安全性),
- 我在支持 bean 中完成了 logout() 方法,使会话无效并发送重定向。
我无法让容器再次显示登录框来验证用户,并且能够更改用户...并且我的用户始终可以返回,按浏览器中的“后退”按钮或仅写入 URL,然后继续执行操作thnigs 那里应该不应该有现有的会话。
我正在获取创建我的支持 bean 的用户的名称:
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 中调用此方法::
public void logout() throws IOException {
// FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
this.name = null;
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)fc.getExternalContext().getSession(false);
session.invalidate();
FacesContext.getCurrentInstance().getExternalContext().redirect("https://localhost:8080/");
}
我正在声明我的支持 bean与:
@Named(value="visitor")
@SessionScoped
...我还从部署描述符进行重定向...并且它是相同的。
如果我关闭浏览器,会话就会丢失,容器会再次询问我用户/密码。
有什么建议吗?
多谢!
亚历杭德罗.
I havent found a real solution for this problem, even when it is really common...
I have this context:
- JSF application running on Glassfish Server v3.1, JDK6. All in my personal computer with WinVista (This last should not be important).
- Using SSL and Basic authentication (Security of the container)
- I have done my logout() method in my backing bean invalidating the session and sending a redirect.
I can not make the container show again the Login box to validate the user, and be able to change of user... And my user always can go back, pressing the BACK button in the browser or just writing the URL, and continue doing thnigs there when is supposed that there should not be a existing session.
I am getting the name of the user the my backing bean is created:
private void setName() {
this.name = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal().getName();
}
And I use this name to perform operations...
Then for logout my xhtml has the code:
<h:panelGroup id="logOut">
<h:form>
<h:commandLink id="linkLogOut" action="#{visitor.logout}" value=" Clic here to Log Out" />
</h:form>
</h:panelGroup>
That calls this method in my bean::
public void logout() throws IOException {
// FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
this.name = null;
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession)fc.getExternalContext().getSession(false);
session.invalidate();
FacesContext.getCurrentInstance().getExternalContext().redirect("https://localhost:8080/");
}
I am declaring my backing bean with:
@Named(value="visitor")
@SessionScoped
...Also I was doing the redirect from the the deployment descriptor... and it was the same.
If I close the browser the the session is lost and the container ask me again for user/pass.
Any suggestions?
Thanks a lot!
Alejandro.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些页面可能会从浏览器缓存中显示,而不是从服务器重新请求。要阻止这种情况,请创建一个
Filter
< /a> 映射到感兴趣的 URL 模式(*.jsf
也许?),并在doFilter()
方法中执行以下工作:在测试之前清除浏览器缓存。
Those pages are likely displayed from the browser cache rather than re-requested from the server. To stop this, create a
Filter
which is mapped on URL pattern of interest (*.jsf
maybe?) and does the following job indoFilter()
method:Clear the browser cache before testing.
非常感谢您的所有回答。
我请了几天假……没有回复这个帖子。
我只是想分享我的解决方案。
基本身份验证绑定到浏览器,一旦您完成登录,应该关闭浏览器以完成注销......这不是那么优雅。
我更改为 FORM 身份验证,创建表单,并将用户信息发布到 servlet,该 servlet 根据我的领域验证用户凭据,并且该 servlet 将用户重定向到应用程序或错误页面。显然,必须在 web.xml 中进行正确的安全约束配置。
我在这里分享我的解决方案:
登录页面:
我的验证 servlet 方法:
以及配置文件的必需部分......
我希望这对其他人有用。
一切顺利,
亚历杭德罗。
Thank you so much for all your answers.
I took some days off... and did not reply this thread.
I just want to share my solution.
Basic authentication is bound to the browser, and once you have done login, should should close the browser to finish the logoff... what is not so elegant.
I changed to FORM authentication, creating my form, and posting the user information to a servlet who validates the user credentials against my realm, and this servlet redirect the user to either the application or to an error page. Obviously the proper configuration ifor security-constrain in web.xml have to be done.
I am sharing my solution here:
Login page:
My validation servlet method:
And the required part of the configuration file....
I hope this can be useful for someone else.
All the best,
Alejandro.