Skip to content

Commit

Permalink
secuity - default response 401
Browse files Browse the repository at this point in the history
  • Loading branch information
chinnawatsut committed Mar 29, 2024
1 parent 4fa0af2 commit 89d899a
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.HttpStatusEntryPoint;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;

@EnableWebSecurity
Expand All @@ -32,6 +34,10 @@ SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Excepti
.sessionManagement(
session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.addFilterBefore(jwtAuthFilter, BasicAuthenticationFilter.class)
.exceptionHandling(
e ->
e.authenticationEntryPoint(
new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED)))
.build();
}
}

0 comments on commit 89d899a

Please sign in to comment.