spring security 配置了permitAll 还是会访问登录控制器,请问怎么回事。
列入我访问getImgCode方法,登录控制器也会打印,请教哪里需配置出现问题了。
配置如下:
spring security
http.authorizeRequests()
// 如果有允许匿名的url,填在下面
.antMatchers("/druid/**").permitAll()
.antMatchers("/getVerifyCode").permitAll()
.antMatchers("/getImgCode").permitAll()
.antMatchers("/getVerifyCode1").permitAll()
.antMatchers("/getVerifyGifCode").permitAll()
.antMatchers("/login/invalid").permitAll()
// .antMatchers("/admin1/**").hasRole("USER")
//尚未匹配的任何URL都要求用户进行身份验证
.anyRequest().authenticated()
//添加无权限时的处理
.and().exceptionHandling()
.accessDeniedHandler(accessDeniedHandler)
....省略
控制器:
@RequestMapping("/login")
public String showLogin() {
Authentication auth=SecurityContextHolder.getContext().getAuthentication();
if (!(auth instanceof AnonymousAuthenticationToken)) {
logger.info("当前登陆用户:" + auth.getName());
return "redirect:/";
}
logger.info("--------------------------------");
logger.info("--------------login------------------");
logger.info("-------------------------------");
return "user/login";
}