33 lines
1006 B
Java
33 lines
1006 B
Java
|
package eu.eudat.controllers.controllerhandler;
|
||
|
|
||
|
import eu.eudat.core.logger.Logger;
|
||
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||
|
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;
|
||
|
|
||
|
/**
|
||
|
* Created by ikalyvas on 6/12/2018.
|
||
|
*/
|
||
|
@ControllerAdvice
|
||
|
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;
|
||
|
}
|
||
|
}
|