Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3655

Spring Boot 3: Exclude REST Endpoints from Authorization

$
0
0

I am using Spring Boot 3 for my REST application and want to exclude some REST Endpoints from Authorization.

Take this REST Controller as an example:

@RestController@RequestMapping("/api/rest/products")class ProductController { ... }

My Security config looks like this:

@Beanpublic SecurityFilterChain securityFilterChain(HttpSecurity http) {    http.authorizeHttpRequests(authorize -> authorize.                    requestMatchers("/api/rest/products").permitAll()                    .anyRequest().authenticated()    );    ...}

But this doesn't work. The /products endpoint still demands an Authorization Header. It only works when I provide a regex like this:

requestMatchers("**").permitAll()

Now all endpoints won't require the Auth header. What am I doing wrong? I haven't yet found a proper string to only exclude the /products endpoint.


Viewing all articles
Browse latest Browse all 3655

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>