`
peterwanghao
  • 浏览: 123466 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Apache Shiro Web应用整合-Remember Me服务

阅读更多

Shiro提供Remember服务,AuthenticationToken需要实现org.apache.shiro.authc.RememberMeAuthenticationToken接口,此接口提供了一个方法:

boolean isRememberMe();

如果该方法返回true,则Shiro 将会在整个会话中记住终端用户的身份ID

注:经常使用的UsernamePasswordToken 已经实现了RememberMeAuthenticationToken 接口,并支持rememberMe 登录。

编程方式

编程方式支持RememberMe服务,你可以通过类的接口将其值设为true。比如:

UsernamePasswordToken token = new UsernamePasswordToken(username, password);

token.setRememberMe(true);

SecurityUtils.getSubject().login(token);

表单提交方式

Web应用中,默认的认证过滤器是FormAuthenticationFilter。它读取一个名为‘rememberMe’表单值来支持 Remember Me 服务,此值是布尔型。比如在你的页面里有一个名为‘rememberMe’的checkbox

<form ...>

 

   Username: <input type="text" name="username"/> <br/>

   Password: <input type="password" name="password"/>

   ...

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

   ...

</form>

默认的FormAuthenticationFilter会寻找请求参数名为usernamepasswordrememberMe的值。如果你的参数名与这些默认值不同,你可以在FormAuthenticationFilter中进行配置,比如:

[main]

...

authc.loginUrl = /whatever.jsp

authc.usernameParam = somethingOtherThanUsername

authc.passwordParam = somethingOtherThanPassword

authc.rememberMeParam = somethingOtherThanRememberMe

...

 

Cookie方式

你可以通过设定{{RememberMeManager}}的各个cookie 属性来配置rememberMe。例如:

[main]

securityManager.rememberMeManager.cookie.name = foo

securityManager.rememberMeManager.cookie.maxAge = blah

...

请参见CookieRememberMeManager SimpleCookie JavaDoc 支持来获取更多的配置属性。

自定义方式

应该注意到,默认基于cookie RememberMeManager 实现如果不符合你的需求,你可以插入任何你喜欢的插件到 securityManager 当中,就像你配置任何其他对象的引用一样:

[main]

...

rememberMeManager = com.my.impl.RememberMeManager

securityManager.rememberMeManager = $rememberMeManager

 

分享到:
评论

相关推荐

    shiro-web-1.4.0-API文档-中文版.zip

    Maven坐标:org.apache.shiro:shiro-web:1.4.0; 标签:apache、shiro、web、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的...

    shiro-web-1.3.2-API文档-中文版.zip

    对应Maven信息:groupId:org.apache.shiro,artifactId:shiro-web,version:1.3.2 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持...

    shiro-web-1.2.3-API文档-中文版.zip

    Maven坐标:org.apache.shiro:shiro-web:1.2.3; 标签:apache、shiro、web、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的...

    shiro-web-1.2.3-API文档-中英对照版.zip

    Maven坐标:org.apache.shiro:shiro-web:1.2.3; 标签:apache、shiro、web、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中...

    shiro-web-1.4.0-API文档-中英对照版.zip

    Maven坐标:org.apache.shiro:shiro-web:1.4.0; 标签:apache、shiro、web、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中...

    apache-shiro-1-2-x-reference

    Apache Shiro是一个功能强大、灵活的开放式安全框架,干净利落地处理身份验证、授权、企业会话管理和加密。 Shiro可以帮助我们完成:认证、授权、加密、会话管理...【apache-shiro-1-2-x-reference,"waylau"翻译自官网】

    Apache Shiro 身份认证例子-源码

    Apache Shiro 身份认证例子-源码

    shiro-web-1.3.2-API文档-中英对照版.zip

    对应Maven信息:groupId:org.apache.shiro,artifactId:shiro-web,version:1.3.2 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的代码和结构保持...

    shiro-config-core-1.4.0-API文档-中文版.zip

    Maven坐标:org.apache.shiro:shiro-config-core:1.4.0; 标签:apache、shiro、config、core、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性...

    shiro-cache-1.4.0-API文档-中英对照版.zip

    Maven坐标:org.apache.shiro:shiro-cache:1.4.0; 标签:apache、shiro、cache、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,...

    apache-shiro-1-2-x-reference.zip

    shiro官方文档(中文) apache-shiro-1-2-x-reference apache-shiro-1-2-x-reference

    shiro-core-1.4.0-API文档-中文版.zip

    Maven坐标:org.apache.shiro:shiro-core:1.4.0; 标签:apache、shiro、core、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,文档中的...

    shiro-crypto-hash-1.4.0-API文档-中文版.zip

    Maven坐标:org.apache.shiro:shiro-crypto-hash:1.4.0; 标签:apache、shiro、crypto、hash、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性...

    shiro-spring-boot-web-starter-1.4.0.jar

    java运行依赖jar包

    shiro-crypto-cipher-1.4.0-API文档-中文版.zip

    Maven坐标:org.apache.shiro:shiro-crypto-cipher:1.4.0; 标签:apache、shiro、crypto、cipher、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 ...

    shiro-crypto-core-1.4.0-API文档-中文版.zip

    Maven坐标:org.apache.shiro:shiro-crypto-core:1.4.0; 标签:apache、shiro、crypto、core、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性...

    shiro-config-core-1.4.0-API文档-中英对照版.zip

    Maven坐标:org.apache.shiro:shiro-config-core:1.4.0; 标签:apache、shiro、config、core、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 ...

    shiro-ehcache-1.4.0-API文档-中文版.zip

    Maven坐标:org.apache.shiro:shiro-ehcache:1.4.0; 标签:apache、shiro、ehcache、中文文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 人性化翻译,...

    shiro-crypto-core-1.4.0-API文档-中英对照版.zip

    Maven坐标:org.apache.shiro:shiro-crypto-core:1.4.0; 标签:apache、shiro、crypto、core、中英对照文档、jar包、java; 使用方法:解压翻译后的API文档,用浏览器打开“index.html”文件,即可纵览文档内容。 ...

    Apache Shiro 身份认证例子- Web应用

    可直接拷贝到Tomcat下运行,默认用户名/口令:admin/admin

Global site tag (gtag.js) - Google Analytics