在使用jwt认证过程中,后端不用记录httpSession,也就可以禁用session,shiro有自带的session,同样也可以禁用。
1 2 3 4 5 6 7 8
| @Bean protected ShiroFilterChainDefinition shiroFilterChainDefinition() { DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition(); chainDefinition.addPathDefinition("/login", "anon"); chainDefinition.addPathDefinition("/logout", "anyRole[user]"); chainDefinition.addPathDefinition("/**", "noSessionCreation,anyRole[user]"); return chainDefinition; }
|
noSessionCreation是在请求中关闭session的意思。
同时,还要注入名为SessionStorageEvaluator的bean
1 2 3 4 5 6 7 8 9 10
|
@Bean protected SessionStorageEvaluator sessionStorageEvaluator() { DefaultWebSessionStorageEvaluator sessionStorageEvaluator = new DefaultWebSessionStorageEvaluator(); sessionStorageEvaluator.setSessionStorageEnabled(false); return sessionStorageEvaluator; }
|