我正在创建一个带有验证的用户登录。但是当我做安全部分时,我遇到了一个问题。
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/auth/login", "/auth/signup", "/auth/verify").permitAll()
.antMatchers(HttpMethod.GET, "/movies/**").permitAll()
.anyRequest().authenticated()
.and()
.addFilter(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class);
这里我得到错误:
The method addFilter(Filter) in the type HttpSecurity is not applicable for the arguments (JwtTokenFilter, Class<UsernamePasswordAuthenticationFilter>)
如果有人提出解决方案,我们将不胜感激,并且非常欢迎。
尝试
addFilterAfter()
。请仔细阅读文档以更好地理解它:https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/web/HttpSecurityBuilder.html
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/auth/login", "/auth/signup", "/auth/verify").permitAll()
.antMatchers(HttpMethod.GET, "/movies/**").permitAll()
.anyRequest().authenticated()
.and()
.addFilterAfter(jwtTokenFilter, UsernamePasswordAuthenticationFilter.class);