如何使用apache shiro永久登录 [英] How to stay logged in permanently using 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屋!