如何使用apache shiro永久登录 [英] How to stay logged in permanently using apache shiro

查看:295
本文介绍了如何使用apache shiro永久登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户第一次使用apache shiro登录时,需要知道如何在我的Java EE应用程序中永久保持登录状态

A need to know how to stay logged in permanently in my Java EE application when the user logged in at first time using apache shiro

有什么想法吗?

推荐答案

Shiro支持记住我"功能.只需在登录表单中提供一个名称为rememberMe的复选框:

Shiro supports "Remember me" facility. Just provide a checkbox with name rememberMe in the login form:

<input type="checkbox" name="rememberMe" value="true" />

如果要按以下方式使用JSF <h:selectBooleanCheckbox>

If you want to use JSF <h:selectBooleanCheckbox> as follows,

<h:form id="login">
    <h:selectBooleanCheckbox id="rememberMe" />

然后,您需要更改shiro.ini以在[main]下添加以下条目:

Then you need to alter the shiro.ini to add the following entry under [main]:

authc.rememberMeParam = login:rememberMe

其中login:rememberMe是复选框由JSF生成的客户端ID,代表实际的HTTP请求参数名称.

where login:rememberMe is the JSF-generated client ID of the checkbox, representing the actual HTTP request parameter name.

如果要默认检查它,请在HTML输入中使用checked="checked",或在JSF组件中提供一个boolean=true属性.

If you want to have it checked by default, use checked="checked" in the HTML input, or provide a boolean=true property in the JSF component.

这篇关于如何使用apache shiro永久登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆