2018-06-27 12:29:21 +02:00
|
|
|
package eu.eudat.controllers.controllerhandler;
|
|
|
|
|
|
|
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
2020-01-28 17:33:50 +01:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2018-06-27 12:29:21 +02:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
|
2023-10-03 16:29:45 +02:00
|
|
|
import jakarta.annotation.Priority;
|
2018-09-18 14:41:24 +02:00
|
|
|
|
2018-06-27 12:29:21 +02:00
|
|
|
/**
|
|
|
|
* Created by ikalyvas on 6/12/2018.
|
|
|
|
*/
|
|
|
|
@ControllerAdvice
|
2018-09-18 14:41:24 +02:00
|
|
|
@Priority(4)
|
2018-06-27 12:29:21 +02:00
|
|
|
public class ControllerUnauthorisedHandler {
|
2020-01-28 17:33:50 +01:00
|
|
|
private static final Logger logger = LoggerFactory.getLogger(ControllerUnauthorisedHandler.class);
|
2018-06-27 12:29:21 +02:00
|
|
|
|
|
|
|
@Autowired
|
2020-06-29 12:00:34 +02:00
|
|
|
public ControllerUnauthorisedHandler() {
|
2018-06-27 12:29:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionHandler(UnauthorisedException.class)
|
|
|
|
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
|
|
|
@ResponseBody
|
|
|
|
public void processValidationError(UnauthorisedException ex) {
|
2020-01-28 17:33:50 +01:00
|
|
|
logger.error(ex.getMessage(), ex);
|
2018-06-27 12:29:21 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|