Search in sources :

Example 1 with ErrorJson

use of org.eclipse.openvsx.json.ErrorJson in project openvsx by eclipse.

the class UserAPI method getAuthError.

/**
 * Retrieve the last authentication error and return its details.
 */
@GetMapping(path = "/user/auth-error", produces = MediaType.APPLICATION_JSON_VALUE)
public ErrorJson getAuthError(HttpServletRequest request) {
    var authException = request.getSession().getAttribute(WebAttributes.AUTHENTICATION_EXCEPTION);
    if (!(authException instanceof AuthenticationException))
        throw new ResponseStatusException(HttpStatus.NOT_FOUND);
    var json = new ErrorJson();
    json.message = ((AuthenticationException) authException).getMessage();
    if (authException instanceof CodedAuthException)
        json.code = ((CodedAuthException) authException).getCode();
    return json;
}
Also used : CodedAuthException(org.eclipse.openvsx.security.CodedAuthException) ErrorJson(org.eclipse.openvsx.json.ErrorJson) AuthenticationException(org.springframework.security.core.AuthenticationException) ResponseStatusException(org.springframework.web.server.ResponseStatusException) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ErrorJson (org.eclipse.openvsx.json.ErrorJson)1 CodedAuthException (org.eclipse.openvsx.security.CodedAuthException)1 AuthenticationException (org.springframework.security.core.AuthenticationException)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 ResponseStatusException (org.springframework.web.server.ResponseStatusException)1