@Component
public class ShiroRealm
extends org.apache.shiro.realm.AuthorizingRealm
构造器和说明 |
---|
ShiroRealm() |
限定符和类型 | 方法和说明 |
---|---|
LoginUser |
checkUserTokenIsEffect(java.lang.String token)
校验token的有效性
|
void |
clearCache(org.apache.shiro.subject.PrincipalCollection principals)
清除当前用户的权限认证缓存
|
protected org.apache.shiro.authc.AuthenticationInfo |
doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken auth)
用户信息认证是在用户进行登录的时候进行验证(不存redis)
也就是说验证用户输入的账号和密码是否正确,错误抛出异常
|
protected org.apache.shiro.authz.AuthorizationInfo |
doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection principals)
权限信息认证(包括角色以及权限)是用户访问controller的时候才进行验证(redis存储的此处权限信息)
触发检测用户权限时才会调用此方法,例如checkRole,checkPermission
|
boolean |
jwtTokenRefresh(java.lang.String token,
java.lang.String userName,
java.lang.String passWord)
JWTToken刷新生命周期 (实现: 用户在线操作不掉线功能)
1、登录成功后将用户的JWT生成的Token作为k、v存储到cache缓存里面(这时候k、v值一样),缓存有效期设置为Jwt有效时间的2倍
2、当该用户再次请求时,通过JWTFilter层层校验之后会进入到doGetAuthenticationInfo进行身份验证
3、当该用户这次请求jwt生成的token值已经超时,但该token对应cache中的k还是存在,则表示该用户一直在操作只是JWT的token失效了,程序会给token对应的k映射的v值重新生成JWTToken并覆盖v值,该缓存生命周期重新计算
4、当该用户这次请求jwt在生成的token值已经超时,并在cache中不存在对应的k,则表示该用户账户空闲超时,返回用户信息已失效,请重新登录。
|
boolean |
supports(org.apache.shiro.authc.AuthenticationToken token)
必须重写此方法,不然Shiro会报错
|
afterCacheManagerSet, checkPermission, checkPermission, checkPermission, checkPermissions, checkPermissions, checkPermissions, checkRole, checkRole, checkRoles, checkRoles, checkRoles, clearCachedAuthorizationInfo, doClearCache, getAuthorizationCache, getAuthorizationCacheKey, getAuthorizationCacheName, getAuthorizationInfo, getPermissionResolver, getPermissions, getRolePermissionResolver, hasAllRoles, hasRole, hasRole, hasRoles, hasRoles, isAuthorizationCachingEnabled, isPermitted, isPermitted, isPermitted, isPermitted, isPermitted, isPermitted, isPermittedAll, isPermittedAll, isPermittedAll, onInit, setAuthorizationCache, setAuthorizationCacheName, setAuthorizationCachingEnabled, setName, setPermissionResolver, setRolePermissionResolver
assertCredentialsMatch, clearCachedAuthenticationInfo, getAuthenticationCache, getAuthenticationCacheKey, getAuthenticationCacheKey, getAuthenticationCacheName, getAuthenticationInfo, getAuthenticationTokenClass, getCredentialsMatcher, init, isAuthenticationCachingEnabled, isAuthenticationCachingEnabled, setAuthenticationCache, setAuthenticationCacheName, setAuthenticationCachingEnabled, setAuthenticationTokenClass, setCredentialsMatcher
getAvailablePrincipal, getCacheManager, getName, isCachingEnabled, onLogout, setCacheManager, setCachingEnabled
public boolean supports(org.apache.shiro.authc.AuthenticationToken token)
supports
在接口中 org.apache.shiro.realm.Realm
supports
在类中 org.apache.shiro.realm.AuthenticatingRealm
protected org.apache.shiro.authz.AuthorizationInfo doGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection principals)
doGetAuthorizationInfo
在类中 org.apache.shiro.realm.AuthorizingRealm
principals
- 身份信息protected org.apache.shiro.authc.AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken auth) throws org.apache.shiro.authc.AuthenticationException
doGetAuthenticationInfo
在类中 org.apache.shiro.realm.AuthenticatingRealm
auth
- 用户登录的账号密码信息org.apache.shiro.authc.AuthenticationException
public LoginUser checkUserTokenIsEffect(java.lang.String token) throws org.apache.shiro.authc.AuthenticationException
token
- org.apache.shiro.authc.AuthenticationException
public boolean jwtTokenRefresh(java.lang.String token, java.lang.String userName, java.lang.String passWord)
userName
- passWord
- public void clearCache(org.apache.shiro.subject.PrincipalCollection principals)
clearCache
在类中 org.apache.shiro.realm.CachingRealm
principals
- 权限信息