要设置接口不需要token认证,可以在Spring Boot的配置类中添加一个WebSecurityConfigurerAdapter的实现类,并在configure方法中配置不需要认证的接口路径。具体代码如下:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers("/ext_auth/strategy/{uuid}").permitAll() // 设置不需要认证的接口路径
                .anyRequest().authenticated()
                .and()
                .csrf().disable();
    }
}

在上面的代码中,/ext_auth/strategy/{uuid}路径被设置为不需要认证,其他路径需要进行认证。同时,关闭了CSRF防护

package comchinamobiledeepwatchlancelotservicecontrollerimpl;import comchinamobiledeepwatchlancelotapiapiobjectsrspSimpleKvRsp;import comchinamobiledeepwatchlancelotcoredtoflowinExtInfAuthStrategyUpse

原文地址: https://www.cveoy.top/t/topic/iwwB 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录