spring security 注解方式配置 匿名用户访问方法,如何配置?以下代码无效

以下代码无效

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
                .anonymous()
                .authorities("ROLE_ANONYMOUS").and()
                .authorizeRequests()
                .antMatchers(
                        "/","/login**", "/webjars*", "/static*",
                        "/profile/register**","/user/IsRegistered**","/profile/save**","/topic/zone*//**","/topic**","/topic/getTopicList**","/topic/detail**","/topic/getOne*//**","/topic/getCommentList**","/topic/saveTopicComment**").permitAll()
                .anyRequest()
                .authenticated().
                and().formLogin().loginPage("/login").failureUrl("/login?error").defaultSuccessUrl("/topic/zone")
                .and().exceptionHandling()
                .and().logout().logoutUrl("/logout").invalidateHttpSession(true).logoutSuccessUrl("/login")

                .and()
                .csrf()
                .csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse());
        //    http.addFilterAfter(tokenFilter(), BasicAuthenticationFilter.class);

        http.csrf().disable();
        http.headers().frameOptions().sameOrigin();
    }
@Slf4j
@Controller("chatController")
@RequestMapping(value="/chat")
public class IndexController  extends AbstractController {

    @Secured( value={"ROLE_ANONYMOUS"})
    @RequestMapping(value="")
    public String index(Model model){
        super.setUser(model);
        return "chat/index";
    }
}
阅读 6.2k
1 个回答
新手上路,请多包涵

我这也是,怎么解决

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题