gpt4 book ai didi

java - 如何解决shiro的重复提交问题?

转载 作者:行者123 更新时间:2023-12-02 11:04:05 24 4
gpt4 key购买 nike

在 Spring ,我做了一个 HandlerInterceptor 来解决请求的重复提交,当我尝试在 Spring 中集成 shiro 时,我发现了一个问题,那就是如果我使用匿名过滤器进行重复提交(例如/登录),代码运行良好,但是如果我使用自定义过滤器来处理请求,则请求始终待处理...

处理程序拦截器:

public class RepeatSubmitHandler implements HandlerInterceptor {

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
log.info("preHandler was working....");
}

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
log.info("afterCompletion was working...");
}
}

shiro配置:

@Bean("shiroFilter")
public ShiroFilterFactoryBean shirFilter(SecurityManager securityManager) {
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
shiroFilter.setSecurityManager(securityManager);

Map<String, Filter> filters = shiroFilter.getFilters();
filters.put("oauth2", new OAuth2Filter());
shiroFilter.setFilters(filters);

Map<String, String> filterMap = new LinkedHashMap<>();
//anon filter, shiro default filter
filterMap.put("/api/sys/login", "anon");
//custom filter
filterMap.put("/**", "oauth2");
shiroFilter.setFilterChainDefinitionMap(filterMap);

return shiroFilter;
}

Controller :

@PostMapping("/login")
public RestResponse login(@RequestBody SysLoginVo loginForm) {
log.info("login was working...");
}

@GetMapping("/nav")
public RestResponse nav() throws InterruptedException {
log.info("nav was working...");
}

带有匿名过滤器的控制台来处理重复提交:这是我的目的

    preHandler was working....
login was working...

preHandler was working....
preHandler was working....
preHandler was working....

afterCompletion was working...

带有自定义过滤器的控制台来处理重复提交:

    preHandler was working....
nav was working...
afterCompletion was working...

preHandler was working....
nav was working...
afterCompletion was working...

最佳答案

好吧,是我的错,原因与shiro无关,仅针对get请求,对于发送get请求,请求将处于pending状态

关于java - 如何解决shiro的重复提交问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51108736/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com