Compile error in (Step 25 - Getting Started with JWT and Spring Security)
Compile error details : the line # 152 : .requestMatchers("/authenticate").permitAll() the error details : java: method requestMatchers in class org.springframework.security.config.annotation.web.AbstractRequestMatcherRegistry<C> cannot be applied to given types; required: org.springframework.security.web.util.matcher.RequestMatcher[] found: java.lang.String reason: varargs mismatch; java.lang.String cannot be converted to org.springframework.security.web.util.matcher.RequestMatcher
the problem description : the requestMatchers(String) method is not available in the version of Spring Security 6+. Starting with Spring Security 6, the requestMatchers method has been updated to be more type-safe and flexible
Any advice Please !!
Hey @MouathMohammad I was having a similar issue before this step with the Basic Authentication.
This issue arises because of the version of Spring Security being used (I am using Spring Security Config v6.0.0-M6 as of writing this response).
Since making the switch from .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() to .requestMatchers(HttpMethod.OPTIONS, "/**").permitAll() it will generate an error like the one you are reporting because Spring Security 6's implementation of this does not require a String value passed to .requestMatchers() but a RequestMatcher object.
From AbstractRequestMatcherRegistry.class:
public C requestMatchers(RequestMatcher... requestMatchers) {
Assert.state(!this.anyRequestConfigured, "Can't configure requestMatchers after anyRequest");
return this.chainRequestMatchers(Arrays.asList(requestMatchers));
}
Since Spring Security API's has been updated I have implemented this line:
.requestMatchers(new AntPathRequestMatcher("/**", HttpMethod.OPTIONS.name())).permitAll()
Using the method overload will resolve the issue you are facing.
@MaestroAD can I start working on this issue?