有什么区别HttpSecurity和antMatcher()功能?
任何人都可以解释何时使用它们?
cors()filter类的configure方法WebSecurityConfigurerAdapter和 create beanWebMvcConfigurer和 overrideaddCorsMappings方法有什么区别?当我们使用哪个?谁能解释一下?
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("http://localhost:3000");
}
};
}
Run Code Online (Sandbox Code Playgroud)
对比
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and()
.csrf().disable()
.authorizeRequests()
.mvcMatchers("/rest/**").authenticated()
.anyRequest().permitAll()
.and()
.oauth2ResourceServer().jwt().jwtAuthenticationConverter(this.jwtAuthenticationConverter())
;
}
Run Code Online (Sandbox Code Playgroud)
}