Spring Security permitAll() not allowing anonymous access

前端 未结 4 1936
无人共我
无人共我 2020-12-08 02:04

I have a single method that I want to allow both anonymous and authenticated access to.

I am using Spring Security 3.2.4 with java based configuration.

The o

相关标签:
4条回答
  • 2020-12-08 02:21
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.anonymous().and()...;
    }
    
    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().mvcMatchers("/ping**");
    }
    
    0 讨论(0)
  • 2020-12-08 02:35

    Need to add .annonymous()

    http
        .addFilterBefore(muiltpartFilter, ChannelProcessingFilter.class)
        .addFilterBefore(cf, ChannelProcessingFilter.class)
        .anonymous().and()
        .authorizeRequests().anyRequest().authenticated().and()
            .authorizeRequests()
                .antMatchers("/ping**")
                .permitAll()
                .and()
            .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
            .logout()
                .logoutUrl("/logout")
            .logoutSuccessUrl("/login");
    

    Referred from: https://stackoverflow.com/a/25280897/256245

    0 讨论(0)
  • 2020-12-08 02:36

    The permission order is important, it works when I configure it like this:

    .authorizeRequests()
            .antMatchers("/ping**")
            .permitAll()
            .and()
    .authorizeRequests()
            .anyRequest()
            .authenticated()
            .and()
    
    0 讨论(0)
  • 2020-12-08 02:36

    I saw the same issue. Make sure you didn't call
    super.configure(http);
    anyRequest().authenticated();
    is called by default.

    0 讨论(0)
提交回复
热议问题