【shiro】登录经历的流程(执行ShiroAccountRealm doGetAuthenticationInfo经历的过程)

http://jinnianshilongnian.iteye.com/blog/2025656 拦截器机制。

在这里
@Bean(name = "shiroFilter")
public ShiroFilterFactoryBean getShiroFilter() {
  ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
  shiroFilterFactoryBean.setSecurityManager(getDefaultWebSecurityManager());
  shiroFilterFactoryBean.setLoginUrl("/login");
  shiroFilterFactoryBean.setSuccessUrl("/index");
  Map<String, Filter> filters = new HashMap<>();
  filters.put("authc", getFormAuthenticationCaptchaFilter()); //******************************//
  filters.put("logout", getLogoutFilter());
  shiroFilterFactoryBean.setFilters(filters);
  shiroFilterFactoryBean.setFilterChainDefinitionMap(getFilterChainDefinitionMap());
  return shiroFilterFactoryBean;
}
private Map<String, String> getFilterChainDefinitionMap() {
  Map<String, String> filterChainDefinitionMap = new LinkedHashMap<String, String>();
  filterChainDefinitionMap.put("/login", "authc"); //******************************//
  filterChainDefinitionMap.put("/logout", "logout");
  filterChainDefinitionMap.put("/druid", "anon");
  filterChainDefinitionMap.put("/olv3", "anon");
  filterChainDefinitionMap.put("/*", "anon");
  return filterChainDefinitionMap;
}

————————————————————————————————————————————————————————
FormAuthenticationCaptchaFilter
继承自 FormAuthenticationFilter
继承自 AuthenticatingFilter
继承自 AuthenticationFilter
继承自 AccessControlFilter

isAccessAllowed和onAccessDenied是AccessControlFilter的方法
【-A-】调用 FormAuthenticationFilter onAccessDenied 方法
return executeLogin(request, response);

【-B-】调用 AuthenticatingFilter executeLogin 方法
AuthenticationToken token = createToken(request, response);
Subject subject = getSubject(request, response);
subject.login(token);

【-C-】Subject是一个接口
实际调用DelegatingSubject的login方法
Subject subject = securityManager.login(this, token);

【-D-】SecurityManager是一个接口
实际调用DefaultSecurityManager的login方法
AuthenticationInfo info;
info = authenticate(token);

【-E-】调用 AuthenticatingSecurityManager 的authenticate方法
return调用Authenticator接口的authenticate方法,
实际调用AbstractAuthenticator类的authenticate方法,
AuthenticationInfo info;
info = doAuthenticate(token);

【-F-】调用ModularRealmAuthenticator的doAuthenticate方法,
调用assertRealmsConfigured();
Collection<Realm> realms = getRealms();
if (realms.size() == 1) {
  return doSingleRealmAuthentication(realms.iterator().next(), authenticationToken);
} else {
  return doMultiRealmAuthentication(realms, authenticationToken);
}

【-G-】调用doSingleRealmAuthentication(Realm realm, AuthenticationToken token)
AuthenticationInfo info = realm.getAuthenticationInfo(token);

【-H-】调用Realm接口的getAuthenticationInfo(token)方法
实际调用AuthenticatingRealm的getAuthenticationInfo(token)方法
AuthenticationInfo info = getCachedAuthenticationInfo(token);
if (info == null) {
//otherwise not cached, perform the lookup:
info = doGetAuthenticationInfo(token);

【-I-】调用ShiroAccountRealm的doGetAuthenticationInfo(token)方法
而此方法是自己写的!!!
AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username, user.getPassword(), this.getName());
返回authcInfo 继续再往上返回。

时间: 2024-07-31 19:26:59

【shiro】登录经历的流程(执行ShiroAccountRealm doGetAuthenticationInfo经历的过程)的相关文章

简单两步快速实现shiro的配置和使用,包含登录验证、角色验证、权限验证以及shiro登录注销流程(基于spring的方式,使用maven构建)

前言: shiro因为其简单.可靠.实现方便而成为现在最常用的安全框架,那么这篇文章除了会用简洁明了的方式讲一下基于spring的shiro详细配置和登录注销功能使用之外,也会根据惯例在文章最后总结一下shiro的大致配置使用流程,希望本篇文章能够后能给大家一种原来shiro这么简单的错觉感觉. 注意:该篇文章的开始是建立在一个完备的spring+mybatis的开发环境中,除了shiro之外的配置基本不会涉及到.做好自己--eguid原创文章 一.依赖的jar包 本篇文章使用shiro-1.4

springmvc集成shiro登录失败处理

一般的登录流程会有:用户名不存在,密码错误,验证码错误等.. 在集成shiro后,应用程序的外部访问权限以及访问控制交给了shiro来管理. shiro提供了两个主要功能:认证(Authentication)和授权(Authorization);认证的作用是证明自身可以访问,一般是用户名加密码,授权的作用是谁可以访问哪些资源,通过开发者自己的用户角色权限系统来控制. shiro的会话管理和缓存管理不在本文范围内. 下面通过登录失败的处理流程来介绍springmvc与shiro的集成. 项目依赖:

Shiro 登录认证源码详解

Shiro 登录认证源码详解 Apache Shiro 是一个强大且灵活的 Java 开源安全框架,拥有登录认证.授权管理.企业级会话管理和加密等功能,相比 Spring Security 来说要更加的简单. 本文主要介绍 Shiro 的登录认证(Authentication)功能,主要从 Shiro 设计的角度去看这个登录认证的过程. 一.Shiro 总览 首先,我们思考整个认证过程的业务逻辑: 获取用户输入的用户名,密码: 从服务器数据源中获取相应的用户名和密码: 判断密码是否匹配,决定是否

shiro登录认证过程讲解

先粘出登录的代码 1. 可以看到已经获取到了username和password ,为了接下来的认证过程,我们需要获取subject对象,也就是代表当前登录用户,并且要将username和password两个变量设置到UsernamePasswordToken对象的token中, 调用SecurityUtils.getSubject().login(token)方法,将 token传入 接下来看看login方法的实现: 主要还是用到了securityManager安全管理器 进入securityM

SpringMVC+Apache Shiro+JPA(hibernate)案例教学(三)给Shiro登录验证加上验证码

序: 给Shiro加入验证码,有多种方式,当然你也可以通过继承修改FormAuthenticationFilter类,通过Shiro去验证验证码.具体实现请百度: 应用Shiro到Web Application(验证码实现) 而今天我要说的,既然使用的SpringMVC,为什么不直接在Controller中就处理验证码验证,让事情变的更简单一点呢? 一.新建ValidateCode.java验证码工具类 package org.shiro.demo.util; import java.util.

shiro登录后 /favicon.ico的问题

出现上述问题的原因是: 基本大多数浏览器都会请求favicon.ico这个图标文件用来展示在浏览器的URL地址前面,而这个文件被shiro保护了 解决方法:配置/favicon.ico匿名访问 /favicon.ico = anon 或者 在应用的web.xml中配置 <mime-mapping><extension>ico</extension><mime-type>image/x-icon</mime-type></mime-mappi

使用Shiro登录成功后,跳转到之前访问的页面实现

转:http://blog.csdn.net/lhacker/article/details/20450855 很多时候,我们需要做到,当用户登录成功后,跳转回登录前的页面.如果用户是点击"登录"链接去到登录页面进行登录的,我们很容易跟踪用户的登录前的页面.比如,在"登录"链接后加一个url参数,如:http://www.xxx.com/login.html?url=http://www.xxx.com/xx.html,这个url就是当前页面.用户浏览不同页面,&q

登录Windows界面前执行自定义脚本

通常情况下,进入Windows界面之前都有一个登录过程,如何在登录前让系统执行脚本呢?下面介绍一种方法. 1.打开组策略,在Run(运行)中输入GREDIT.MSC,点击确认. 2.依次点击Computer Configuration -> Windows Settings -> Scripts(Startup/Shutdown) 3.在右侧双击Stratup,出现如图弹窗,可在此添加cmd或者PowerShell脚本. 4.点击确认 重启,在下次登录Windows界面前,系统会自动执行所添加

Python远程登录Linux操作系统,执行命令、创建目录、上传及下载文件

主要是创建文件: #! /bin/bash # -*- coding: utf-8 -*- import paramiko import os ssh = paramiko.SSHClient() key = paramiko.AutoAddPolicy() ssh.set_missing_host_key_policy(key) pkey = paramiko.RSAKey.from_private_key_file('/root/.ssh/id_rsa') paramiko.util.log