Closed JustVibhor closed 10 months ago
It seems a syntax issue. The requestMatchers method in the authorizeHttpRequests configuration typically expects a RequestMatcher object, not a string. If you want to match a specific path, you can use antMatchers.
Here's a corrected version:
return httpSecurity
.authorizeHttpRequests(auth -> auth
.antMatchers("/authenticate").permitAll()
.requestMatchers(PathRequest.toH2Console()).permitAll()
.antMatchers(HttpMethod.OPTIONS,"/**")
.permitAll()
.anyRequest()
.authenticated())
.csrf(AbstractHttpConfigurer::disable)
.sessionManagement(session -> session.
sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.oauth2ResourceServer(
OAuth2ResourceServerConfigurer::jwt)
.httpBasic(
Customizer.withDefaults())
.headers(header -> {header.
frameOptions().sameOrigin();})
.build();
And add the H2 dependency. If you encounter a 500 response when accessing the todo APIs, it works fine for me.
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
Thanks a lot it does work !!
Having a problem using auth.requestMatchers its not accepting string as an argument, I tried using antMachers but was showing no response to the post request
` public SecurityFilterChain securityFilterChain(HttpSecurity httpSecurity, HandlerMappingIntrospector introspector) throws Exception {
pom.xml
` <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
`