I am using a working JWT authentication of my web application with the following configuration:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.exceptionHandling()
.authenticationEntryPoint(
(req, rsp, e) -> p.sendError(HttpServletResponse.SC_UNAUTHORIZED))
.and()
.addFilter(new UsernamePasswordAuthenticationFilter(authenticationManager(),
jwtConfig))
.addFilterAfter(new JwtTokenAuthenticationFilter(jwtConfig),
UsernamePasswordAuthenticationFilter.class)
.authorizeRequests()
.antMatchers(HttpMethod.POST, jwtConfig.getUri()).permitAll()
.anyRequest().authenticated();
}
As of SessionCreationPolicy.STATELESS
i am expecting that Spring will not create a session itself. However, if i access any other resource than /login
, i still see the following entry in the response header:
set-cookie: JSESSIONID=...; Path=/; HttpOnly
Can someone explain where this is coming from (maybe not from Spring) and if it does still come from Spring what needs to be changed?
Edit:
Testing in my controller, the session is still injected as indicated by the above token being present. I still have no clue where this is coming from.
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public void create(HttpSession session) {
if (session != null) {
System.out.println("Session is existing"); // executes
}
}