【Shiro】shiro自己结合项目的不完全总结。。。


1.filter

2.subject

3.user

4./login authc

5./logout logout

先记录关键词。

 

开始的时候就初始化。

有的通过 .xml配置shiro

有的通过 .java配置shiro,这个项目使用。ShiroConfiguration.java

 

@Bean(name = "shiroFilter")   安全认证过滤器。
shiroFilterFactoryBean.setLoginUrl("/login");
shiroFilterFactoryBean.setSuccessUrl("/index");
Map<String, Filter> filters = new HashMap<>();
filters.put("authc", getFormAuthenticationCaptchaFilter());
filters.put("logout", getLogoutFilter());

一共16个配置项:
ShiroConfiguration.java

1.  @Bean(name = "cacheImpl") 加载cache配置文件
2.  @Bean(name = "springCacheManager")* ehcache manager
3.  @Bean(name = "cacheManager") * 自定义cacheManager
4.  @Bean(name = "sessionIdGenerator") * sessionid 生成器
5.  @Bean(name = "sessionDAO") * sessionDao
6.  @Bean(name = "credentialsMatcher")
7.  @Bean(name = "shiroAccountRealm") * realm 权限验证
          @DependsOn(value = "lifecycleBeanPostProcessor")
8.  @Bean(name = "sessionIdCookie") * 指定本系统SESSIONID, 默认为: JSESSIONID 问题: 与SERVLET容器名冲突, 如JETTY, TOMCAT 等默认JSESSIONID, 当跳       出SHIRO SERVLET时如ERROR-PAGE容器会为JSESSIONID重新分配值导致登录会话丢失!
9.   @Bean(name = "sessionManager") * 自定义回话管理
10.  @Bean(name = "securityManager") * shiro安全管理器
11.  FormAuthenticationCaptchaFilter * 验证码过滤器
12.  LogoutFilter * 登出过滤器
13.  public ShiroFilterFactoryBean getShiroFilter() * 安全认证过滤器
14.  getFilterChainDefinitionMap * 过滤连接配置
15.  @Bean(name = "lifecycleBeanPostProcessor")
    getLifecycleBeanPostProcessor
16.   @Bean
    @DependsOn("lifecycleBeanPostProcessor")
    getDefaultAdvisorAutoProxyCreator

1.login 2.token 3.match 4.subject 5.Security Manager 6.AuthenticationInfo Realm
登录的流程:
【-1-】。 "/login"触发authc 
filterChainDefinitionMap.put("/login", "authc");
而authc 在这被赋予意义。
Map<String, Filter> filters = new HashMap<>();
filters.put("authc", getFormAuthenticationCaptchaFilter());
【-2-】。进入shiro,先创建token。
AuthenticationToken createToken
先到 AuthenticatingFilter executeLogin,
AuthenticationToken token = createToken(request, response);
【-3-】。match
【-4-】。
Subject subject = getSubject(request, response);
subject.login(token);
————【DelegatingSubject.java】Subject subject = securityManager.login(this, token);

-5-】——————【SecurityManager.java】public Subject login(Subject subject, AuthenticationToken token){}
【-6-】—————— doGetAuthenticationInfo

ShiroAccountRealm.java】doGetAuthenticationInfo
AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(username, user.getPassword(), this.getName());
ShiroSessionUtils.setAsLogin(user);


ShiroAccountRealm 继承 AuthorizingRealm 继承 AuthenticatingRealm
【-A-】在AuthenticatingRealm 中,有doGetAuthenticationInfo的抽象函数:
protected abstract AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException;
【-B-】在AuthorizingRealm 中,无doGetAuthenticationInfo的实现。
【-C-】在ShiroAccountRealm 中,有doGetAuthenticationInfo的实现。
在AuthenticatingRealm中,调用info = doGetAuthenticationInfo(token),就是调用了
ShiroAccountRealm 的doGetAuthenticationInfo()方法。

怎么到的AuthenticatingRealm?
看另一篇。。。
http://www.cnblogs.com/CESC4/p/7597563.html

 

 















posted @ 2017-09-26 13:50  Legolas_4  阅读(466)  评论(0编辑  收藏  举报