最近开发一个小项目采用springboot2+shiro前后端分离的方式进行。由于访问使用https证书形式。结果在上线时遇到登录信息过期后shiro设置的跳转接口时重定向为http。从而https访问http报错。网上找了很多都没有一个很好的解决办法。
一开始想通过redirectHttp10Compatible:解决https环境下使用redirect重定向地址变为http的协议,无法访问服务的问题 设置为false,即关闭了对http1.0协议的兼容支持 ,实际测试不管用。没办法只能重写shiro源码内的方法了。
方法一:重写FormAuthenticationFilter
原理:
假设在shiro.xml中配置了 /** = authc,而默认authc对应org.apache.shiro.web.filter.authc.FormAuthenticationFilter过滤器则表示所有路径都被此过滤器拦截。
第一步:新建一个MyFormAuthenticationFilter类extends FormAuthenticationFilter代码如下:
public class MyFormAuthenticationFilter extends FormAuthenticationFilter { private static final Logger log = LoggerFactory.getLogger(MyFormAuthenticationFilter.class); @Override protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException { HttpServletRequest httpRequest &