79382407

Date: 2025-01-23 20:00:48
Score: 1
Natty:
Report link

Assuming on the code you provide in the question, there is lack of Spring Security Filter, which would authenticate the request. Your security filter chain might be such as:

@Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http, MyCustomJwtAuthenticationFilter jwtFilter) throws Exception {
        http.csrf(csrf -> csrf.disable())
                .authorizeHttpRequests(auth -> auth
                        .requestMatchers("/api/auth/register", "/api/auth/login").permitAll()
                        .requestMatchers("/api/game/**").authenticated()
                        .anyRequest().authenticated()
                        .addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class));

        http.sessionManagement(session -> session
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS));

        return http.build();
    }

Emphasize your attention on .addFilterBefore, here you will use your filter to authenticate your request.

Example of implementing JWT: https://medium.com/@tericcabrel/implement-jwt-authentication-in-a-spring-boot-3-application-5839e4fd8fac

Resource for learning more about Spring Filters: https://docs.spring.io/spring-security/reference/servlet/architecture.html

Reasons:
  • Blacklisted phrase (0.5): medium.com
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Rob Sil