2018-06-27 12:29:21 +02:00
|
|
|
package eu.eudat.controllers.controllerhandler;
|
|
|
|
|
|
|
|
import eu.eudat.core.logger.Logger;
|
|
|
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2018-09-18 14:41:24 +02:00
|
|
|
import org.springframework.core.annotation.Order;
|
2018-06-27 12:29:21 +02:00
|
|
|
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;
|
|
|
|
|
2018-09-18 14:41:24 +02:00
|
|
|
import javax.annotation.Priority;
|
|
|
|
|
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 {
|
|
|
|
|
|
|
|
private Logger logger;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
public ControllerUnauthorisedHandler(Logger logger) {
|
|
|
|
this.logger = logger;
|
|
|
|
}
|
|
|
|
|
|
|
|
@ExceptionHandler(UnauthorisedException.class)
|
|
|
|
@ResponseStatus(HttpStatus.UNAUTHORIZED)
|
|
|
|
@ResponseBody
|
|
|
|
public void processValidationError(UnauthorisedException ex) {
|
|
|
|
this.logger.error(ex, ex.getMessage());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|