package org.zalando.problem.spring.web.advice.security; import org.springframework.http.ResponseEntity; import org.springframework.security.core.AuthenticationException; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.NativeWebRequest; import org.zalando.problem.Problem; import org.zalando.problem.spring.web.advice.AdviceTrait; import javax.ws.rs.core.Response; /** * Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet * been provided. */ public interface AuthenticationAdviceTrait extends AdviceTrait { @ExceptionHandler default ResponseEntity<Problem> handleAuthentication(final AuthenticationException e, final NativeWebRequest request) { return create(Response.Status.UNAUTHORIZED, e, request); } }