Redirect to login on expired/invalid auth
Backend now returns 401 instead of 403 for unauthenticated requests via HttpStatusEntryPoint. UI middleware handles both 401 and 403, triggering token refresh and redirecting to /login on failure. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,11 +9,14 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
|
||||
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.UsernamePasswordAuthenticationFilter;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.CorsConfigurationSource;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -57,6 +60,9 @@ public class SecurityConfig {
|
||||
).permitAll()
|
||||
.anyRequest().authenticated()
|
||||
)
|
||||
.exceptionHandling(ex -> ex
|
||||
.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED))
|
||||
)
|
||||
.addFilterBefore(
|
||||
new JwtAuthenticationFilter(jwtService, registryService),
|
||||
UsernamePasswordAuthenticationFilter.class
|
||||
|
||||
@@ -23,7 +23,7 @@ const authMiddleware: Middleware = {
|
||||
return request;
|
||||
},
|
||||
async onResponse({ response }) {
|
||||
if (response.status === 401) {
|
||||
if (response.status === 401 || response.status === 403) {
|
||||
onUnauthorized();
|
||||
}
|
||||
return response;
|
||||
|
||||
Reference in New Issue
Block a user