Shiro的认证过程
发表于:2025-12-03 作者:千家信息网编辑
千家信息网最后更新 2025年12月03日,这篇文章主要讲解了"Shiro的认证过程",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Shiro的认证过程"吧!Shiro的架构了解之后,走一下deb
千家信息网最后更新 2025年12月03日Shiro的认证过程
这篇文章主要讲解了"Shiro的认证过程",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"Shiro的认证过程"吧!
Shiro的架构了解之后,走一下debug,跟一下认证的流程。使用Realm来认证用户名密码。
使用realm访问数据库里的数据
获取当前的subject
校验subject是否已经登录
若没有认证则封装用户名密码
1.0创建表单页面 存储提交
2.0请求提交到mvc的handler
3.0获取用户名密码
4.0执行登录:调用subject的login(token)
5.0自定义realm,从数据库获取对应记录,返回给shiro
Realm实现类AuthenticatingRealm

protected abstract AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken var1) throws AuthenticationException;
实现该方法
6.0Shiro完成对密码的比对
currentUser.login(token);login方法的实现void login(AuthenticationToken var1) throws AuthenticationException;
向下走,看下实现
public void login(AuthenticationToken token) throws AuthenticationException {this.clearRunAsIdentitiesInternal();Subject subject = this.securityManager.login(this, token);String host = null;PrincipalCollection principals;if (subject instanceof DelegatingSubject) {DelegatingSubject delegating = (DelegatingSubject)subject;principals = delegating.principals;host = delegating.host;} else {principals = subject.getPrincipals();}if (principals != null && !principals.isEmpty()) {this.principals = principals;this.authenticated = true;if (token instanceof HostAuthenticationToken) {host = ((HostAuthenticationToken)token).getHost();}if (host != null) {this.host = host;}Session session = subject.getSession(false);if (session != null) {this.session = this.decorate(session);} else {this.session = null;}} else {String msg = "Principals returned from securityManager.login( token ) returned a null or empty value. This value must be non null and populated with one or more elements.";throw new IllegalStateException(msg);}}
info = this.authenticate(token);public AuthenticationInfo authenticate(AuthenticationToken token) throws AuthenticationException {return this.authenticator.authenticate(token);}
最终调用的
==============public final AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {AuthenticationInfo info = this.getCachedAuthenticationInfo(token);if (info == null) {info = this.doGetAuthenticationInfo(token);log.debug("Looked up AuthenticationInfo [{}] from doGetAuthenticationInfo", info);if (token != null && info != null) {this.cacheAuthenticationInfoIfPossible(token, info);}} else {log.debug("Using cached authentication info [{}] to perform credentials matching.", info);}if (info != null) {this.assertCredentialsMatch(token, info);} else {log.debug("No AuthenticationInfo found for submitted AuthenticationToken [{}]. Returning null.", token);}return info;}
int i = token.hashCode();此时的hashcode与 info = this.doGetAuthenticationInfo(token);doGetAuthenticationInfo获取的token是一致的
但是会由于缓存 不能达到登录后在返回同样验证的效果
Shiro如何比对密码
token中保存了从数据库获取的密码 以及从前台传过来的密码
然后进行比对
密码的比对
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) { Object tokenCredentials = getCredentials(token); Object accountCredentials = getCredentials(info); return equals(tokenCredentials, accountCredentials);}public void setCredentialsMatcher(CredentialsMatcher credentialsMatcher) { this.credentialsMatcher = credentialsMatcher;}
认证流程走完,能够明确Shiro还是需要数据库中的数据来跟前台数据进行比对密码,如果不能跳转页面或者走到方法,需要在applicationcontext.xml中配置URL
感谢各位的阅读,以上就是"Shiro的认证过程"的内容了,经过本文的学习后,相信大家对Shiro的认证过程这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
密码
认证
数据
过程
数据库
方法
用户
用户名
学习
登录
内容
前台
流程
页面
验证
一致
就是
思路
情况
效果
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
研究生学 网络安全 天赋
《网络安全法》漫画
郑州应用软件开发报价
黑箱数据库
打印机主机服务器脱机
旧电脑如何做服务器
网络安全是一种义务么
阿里云esc服务器首次登陆密码
台达服务器机柜
mkdir命令使用网络安全
数据库异常类型
互联网科技公司放贷的危害
川羽网络技术有限公司怎么样
android软件开发费用
为什么快手上显示服务器繁忙
浙江诚信网络技术服务常见问题
2k19连接不上服务器
长沙有应聘网络技术的吗
sql数据库pdf
动态 数据库
灵武市app软件开发价格
统筹协调网络安全部门
阿里云数据库控制台删改记录
邯郸有哪个软件开发学校
80年代 中国网络安全
北京网络安全员培训
软件工程 软件开发的阶段
移动网络安全演练方案
加格达奇天气预报软件开发
数据库的数据是列表吗