一、web.xml中配置:html
二、shiro-spring.xml:web
SpringShiroFilter对 象,即Spring配置文件中的shiroFilter对象,该过滤器拥有三个重要对象:spring
SecurityManager、apache
PathMatchingFilterChainResolver、 缓存
FilterChainManagerapp
当匹配到过滤链中的aauthc对应的url时,会执行匹配对应<entry key="authc" value-ref="formAuthenticationFilter"/>,既然是filter,那么最jsp
重要的就是doFilter方法了,通过执行父类的一系列方法后最终执行到FormAuthenticationFilter类中的onAccessDenied方法的async
接着执行父类AuthenticatingFilter中的executeLogin()方法,建立token的方法createToken()能够重写放回自定义实现UsernamePasswordToken的this
类MyUsernamePasswordToken(能够实现实际的业务逻辑)url
接着执行subject的实现类DelegatingSubject中的login()方法
接着执行securityManager实现类DefaultSecurityManager的login()方法
接着执行AuthenticatingSecurityManager中的authenticate( )方法,该方法this.authenticator返回的是ModularRealmAuthenticator
执行ModularRealmAuthenticator中的authenticaticate( )方法,由于其继承AbstractAuthenticator,因此执行AbstractAuthenticator中的authenticaticate( )
接着执行ModularRealmAuthenticator中的doAuthenticate( )方法
其中realm.getAuthenticationInfo( ),realm为Realm接口,实际上调用的是其实现类AuthenticatingRealm中的getAuthenticationInfo( )方法
上述代码AuthenticationInfo info = getCachedAuthenticationInfo(token);从缓存中获取认证信息,若是未获取到,则调用doGetAuthenticationInfo(token)
方法获取认证信息,获取到认证信息info后执行assertCredentialsMatch( )方法
getCredentialsMatcher( )返回咱们自定义实现SimpleCredentialsMatcher的类MyCredentialsMatcher,接着cm.doCredentialMatch( )调用实现类方法
校验成功后则执行下面的跳转方法onLoginSuccess( )
接着执行实现FormAuthenticationFilter的方法
认证成功执行FormAuthenticationFilter中的onLoginSuccess()方法,调用issueSuccessRedirect( ),
接着执行AuthenticationFilter中的issueSuccessRedirect( )
认证失败则执行FormAuthenticationFilter中的onLoginFailure方法,接着执行FormAuthenticationFilter中的setFailureAttribute( )方法
getFailureKeyAttribute( )方法返回的事一个final字符窜:DEFAULT_ERROR_KEY_ATTRIBUTE_NAME
接着在LoginController中获取到key对应的值进行异常抛出
参考文献:http://www.cnblogs.com/ccfdod/p/6436353.html
http://blog.csdn.net/xtayfjpk/article/details/53729135
http://jinnianshilongnian.iteye.com/blog/2029717