add exception handling
This commit is contained in:
@@ -24,6 +24,7 @@ public class AuthenticationManager implements ReactiveAuthenticationManager {
|
||||
private JWTUtil jwtUtil;
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Mono<Authentication> authenticate(Authentication authentication) {
|
||||
String authToken = authentication.getCredentials().toString();
|
||||
|
||||
|
||||
@@ -3,11 +3,14 @@ package com.ard333.springbootwebfluxjjwt.security;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableReactiveMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
|
||||
import org.springframework.security.config.web.server.ServerHttpSecurity;
|
||||
import org.springframework.security.web.server.SecurityWebFilterChain;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ard333
|
||||
@@ -24,7 +27,18 @@ public class WebSecurityConfig {
|
||||
|
||||
@Bean
|
||||
public SecurityWebFilterChain securitygWebFilterChain(ServerHttpSecurity http) {
|
||||
return http.csrf().disable()
|
||||
return http
|
||||
.exceptionHandling()
|
||||
.authenticationEntryPoint((swe, e) -> {
|
||||
return Mono.fromRunnable(() -> {
|
||||
swe.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
|
||||
});
|
||||
}).accessDeniedHandler((swe, e) -> {
|
||||
return Mono.fromRunnable(() -> {
|
||||
swe.getResponse().setStatusCode(HttpStatus.FORBIDDEN);
|
||||
});
|
||||
}).and()
|
||||
.csrf().disable()
|
||||
.formLogin().disable()
|
||||
.httpBasic().disable()
|
||||
.authenticationManager(authenticationManager)
|
||||
|
||||
Reference in New Issue
Block a user