You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
Java
37 lines
1.1 KiB
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.core.annotation.Order;
|
|
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;
|
|
|
|
import javax.annotation.Priority;
|
|
|
|
/**
|
|
* Created by ikalyvas on 6/12/2018.
|
|
*/
|
|
@ControllerAdvice
|
|
@Priority(4)
|
|
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;
|
|
}
|
|
}
|