源码解读
认证:
subject.login
DelegatingSubject ->login()
DefaultSecurityManager->login()
AuthenticatingSecurityManager->authenticate()
AbstractAuthenticator->authenticate()
ModularRealmAuthenticator->doAuthenticate()
ModularRealmAuthenticator->doSingleRealmAuthentication()
AuthenticatingRealm->getAuthenticationInfo
授权:
subject.checkRole("admin")
DelegatingSubject ->checkRole()
AuthorizingSecurityManager->checkRole()
ModularRealmAuthorizer->checkRole()
AuthorizingRealm->hasRole()
AuthorizingRealm->doGetAuthorizationInfo()
shiro内置过滤器Filter
核心过滤器类:DefaultFilter,配置那个路径对哪个拦截器进行处理
authc:org.apache.shiro.web.filter.authc.FormAuthenticationFilter
需要认证登录才能访问
user:org.apache.shiro.web.filter.authc.UserFilter
用户拦截器,表示必须存在用户
anon:org.apacje.shiro.web.filter.authc.AnonymourFilter
匿名拦截器,不需要登录即可访问的资源,匿名用户或游客,一般用于过滤静态资源
roles:org.apache.shiro.web.filter.authz.RolesAuthorizationFIlter
角色授权拦截器
验证用户是否拥有角色,参数可写多个,表示某些角色才能通过,多个参数时写roles["admin,user"],.当有多个参数时必须每个参数都通过才算通过
perms:org.apache.shiro.web.filter.authz.PermissionsAuthorizationFilter
权限授权拦截器,验证用户是否拥有权限
参数可写多个,表示需要某些权限才能通过,多个参数时写perms["user,admin"],当有多个参数时必须每个参数都通过才算通过
authcBasic:org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter
httpBasic身份验证拦截器
logout:org.apache.shiro.web.filter.authc.LogoutFilter
退出拦截器,执行后会直接跳转到shiroFilterFactoryBean.setLoginUrl();设置的url
port:org.apache.shiro.web.filter.authz.PortFilter
端口拦截器,可通过的端口
ssl:org.apache.shiro.web.filter.authz.SslFilter
ssl拦截器,只有请求协议时https才能通过
Filter配置路径
路径通配符支持?,*,**,注意通配符匹配不包括目录分隔符“/”
*可以匹配所有,不加*可以进行前缀匹配,但多个冒号就需要多个*来匹配
URL权限采取第一次匹配优先的方式
?:匹配第一个字符,如/user?,匹配/user,但不匹配/user/;
*:匹配零个或多个字符串,如/add*,匹配/addtest,但不匹配/user/1
**:匹配路径中的零个或多个路径,如/user/**将匹配/user/xxx或/user/xxx/yyy