[Fix] Return 403 instead of 401 for StrolchAccessDeniedException

This commit is contained in:
Robert von Burg 2021-02-08 16:11:09 +01:00
parent ff0f6b57eb
commit f19484abc0
1 changed files with 10 additions and 4 deletions

View File

@ -24,6 +24,7 @@ import javax.ws.rs.ext.Provider;
import java.text.MessageFormat;
import li.strolch.exception.StrolchAccessDeniedException;
import li.strolch.exception.StrolchNotAuthenticatedException;
import li.strolch.privilege.model.Restrictable;
import li.strolch.rest.helper.ResponseUtil;
import org.slf4j.Logger;
@ -59,7 +60,12 @@ public class StrolchRestfulExceptionMapper implements ExceptionMapper<Exception>
sb.append(restrictable.getPrivilegeValue());
}
return Response.status(Status.UNAUTHORIZED).entity(sb.toString()).type(MediaType.TEXT_PLAIN).build();
return Response.status(Status.FORBIDDEN).entity(sb.toString()).type(MediaType.TEXT_PLAIN).build();
} else if (ex instanceof StrolchNotAuthenticatedException) {
StrolchNotAuthenticatedException e = (StrolchNotAuthenticatedException) ex;
logger.error("User tried to access resource, but was not authenticated: " + ex.getMessage());
return Response.status(Status.UNAUTHORIZED).entity(e.getMessage()).type(MediaType.TEXT_PLAIN).build();
}
return ResponseUtil.toResponse(ex);