Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Missing Authorization header Spring Boot CORS

I'm developing an application using Spring Boot on backend and React on frontend. I'm having some issues with CORS and authorization: in particular, when I make a request from the frontend I put the Authorization header which contains the JWT token for authentication. Here an example from the code:

async function getUserInfo (username) {
const url = baseURL + "/users/" + username
const jwt = sessionStorage.getItem('token')

let [err, response] = await to(fetch(url), {
    method: 'GET',
    headers: {
        'Authorization': 'Bearer ' + jwt,
        'Content-Type': 'application/json'
    }
})

...

}

When the request arrives to the backend, this header is missing and authentication fails. To configure CORS on Spring Boot, I use the @CrossOrigin annotation:

@CrossOrigin(origins = ["*"], allowedHeaders = ["*"], exposedHeaders = ["*"])
@RestController
class UserController (
    val userDetailsService: UserDetailsServiceImpl,
    val authenticationManager: AuthenticationManager,
    val jwtUtils: JwtUtils
) {
 
...
 
}

The Security configuration is the following:

override fun configure(http: HttpSecurity) {
    //csrf is enable by default
    http.cors().and().csrf().disable()
        .exceptionHandling().authenticationEntryPoint(authEntryPoint)
        .and()
        .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
        .and()
        .authorizeRequests()
        .antMatchers("/auth/**")
        .permitAll()
        .and()
        .authorizeRequests()
        .antMatchers("/users/{username}/**")
        .hasAuthority("ADMIN")
        .and()
        .authorizeRequests()
        .antMatchers("/**")
        .hasAuthority("CUSTOMER")
        .and()
        .logout()
        .permitAll()

    http.addFilterBefore(JwtAuthenticationTokenFilter(jwtUtils),
        UsernamePasswordAuthenticationFilter::class.java)
}

The requests are made using an ADMIN user on the endpoint /users/{username}, as shown in the frontend code.

How can I solve this problem?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!