Daniel Garcia Costa 1 jaar geleden
bovenliggende
commit
9266a3d712
1 gewijzigde bestanden met toevoegingen van 11 en 0 verwijderingen
  1. 11 0
      src/main/java/es/uv/garcosda/config/WebConfigSecurity.java

+ 11 - 0
src/main/java/es/uv/garcosda/config/WebConfigSecurity.java

@@ -2,6 +2,7 @@ package es.uv.garcosda.config;
 
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+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;
@@ -9,6 +10,8 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.security.web.server.SecurityWebFilterChain;
 
+import reactor.core.publisher.Mono;
+
 @EnableReactiveMethodSecurity
 @EnableWebFluxSecurity
 @Configuration
@@ -29,6 +32,14 @@ public class WebConfigSecurity {
 				   )
 				   .httpBasic()
 				   .and()
+               	   .exceptionHandling()
+               	       .authenticationEntryPoint((swe, e) -> Mono.fromRunnable(() -> {
+               			    swe.getResponse().setStatusCode(HttpStatus.UNAUTHORIZED);
+               		    }))
+               	       .accessDeniedHandler((swe, e) -> Mono.fromRunnable(() -> {
+               			    swe.getResponse().setStatusCode(HttpStatus.FORBIDDEN);
+               		    }))
+				   .and()
 				   .build();
 	}