From cc4f4f2fe14cb56611d42af34b0baa51bd6632aa Mon Sep 17 00:00:00 2001 From: Jonathan Nieder Date: Tue, 2 Jun 2015 16:40:23 -0700 Subject: [PATCH] Use message from ServiceNotAuthorizedException, ServiceNotEnabledException When sending an error response due to ServiceNotAuthorizedException or ServiceNotEnabledException, usually we send a default message. In the ServiceNotEnabledException case, we use 403 Git access forbidden except in a dumb-HTTP-specific filter where we use the servlet container's default 403 response: 403 Forbidden In the ServiceNotAuthorizedException case, we use the servlet container's default 401 response: 401 Unauthorized There is one exception: a ServiceNotEnabledException when handling a smart HTTP /info/refs request uses the message from the exception: 403 Service not enabled Be more consistent by always using the message from the exception. This way, authors of a RepositoryResolver, UploadPackFactory, or ReceivePackFactory can provide a more detailed message when appropriate. The defaults are 401 Unauthorized 403 Service not enabled Change-Id: Id1fe1c2042fb96487c3671c1965c8a65c4b8e1b8 Signed-off-by: Jonathan Nieder --- .../src/org/eclipse/jgit/http/server/AsIsFileFilter.java | 4 ++-- .../org/eclipse/jgit/http/server/ReceivePackServlet.java | 5 ++--- .../org/eclipse/jgit/http/server/RepositoryFilter.java | 4 ++-- .../eclipse/jgit/http/server/SmartServiceInfoRefs.java | 8 +++----- .../org/eclipse/jgit/http/server/UploadPackServlet.java | 5 ++--- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java index e8d809659..d33362b4b 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java @@ -87,9 +87,9 @@ public void doFilter(ServletRequest request, ServletResponse response, asIs.access(req, db); chain.doFilter(request, response); } catch (ServiceNotAuthorizedException e) { - res.sendError(SC_UNAUTHORIZED); + res.sendError(SC_UNAUTHORIZED, e.getMessage()); } catch (ServiceNotEnabledException e) { - res.sendError(SC_FORBIDDEN); + res.sendError(SC_FORBIDDEN, e.getMessage()); } } } diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java index 030287b5c..41217d997 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java @@ -137,11 +137,10 @@ public void doFilter(ServletRequest request, ServletResponse response, try { rp = receivePackFactory.create(req, getRepository(req)); } catch (ServiceNotAuthorizedException e) { - rsp.sendError(SC_UNAUTHORIZED); + rsp.sendError(SC_UNAUTHORIZED, e.getMessage()); return; - } catch (ServiceNotEnabledException e) { - sendError(req, rsp, SC_FORBIDDEN); + sendError(req, rsp, SC_FORBIDDEN, e.getMessage()); return; } diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java index 58404020c..a021c1ff5 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java @@ -137,10 +137,10 @@ public void doFilter(final ServletRequest request, sendError(req, res, SC_NOT_FOUND); return; } catch (ServiceNotEnabledException e) { - sendError(req, res, SC_FORBIDDEN); + sendError(req, res, SC_FORBIDDEN, e.getMessage()); return; } catch (ServiceNotAuthorizedException e) { - res.sendError(SC_UNAUTHORIZED); + res.sendError(SC_UNAUTHORIZED, e.getMessage()); return; } catch (ServiceMayNotContinueException e) { sendError(req, res, SC_FORBIDDEN, e.getMessage()); diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java index 51332194b..7d4f21b5c 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java @@ -98,7 +98,7 @@ public void doFilter(ServletRequest request, ServletResponse response, try { begin(req, db); } catch (ServiceNotAuthorizedException e) { - res.sendError(SC_UNAUTHORIZED); + res.sendError(SC_UNAUTHORIZED, e.getMessage()); return; } catch (ServiceNotEnabledException e) { sendError(req, res, SC_FORBIDDEN, e.getMessage()); @@ -132,11 +132,9 @@ private void service(ServletRequest request, ServletResponse response) advertise(req, new PacketLineOutRefAdvertiser(out)); buf.close(); } catch (ServiceNotAuthorizedException e) { - res.sendError(SC_UNAUTHORIZED); - + res.sendError(SC_UNAUTHORIZED, e.getMessage()); } catch (ServiceNotEnabledException e) { - sendError(req, res, SC_FORBIDDEN); - + sendError(req, res, SC_FORBIDDEN, e.getMessage()); } catch (ServiceMayNotContinueException e) { if (e.isOutput()) buf.close(); diff --git a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java index 44d4b1bcf..8c27b712b 100644 --- a/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java +++ b/org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java @@ -137,11 +137,10 @@ public void doFilter(ServletRequest request, ServletResponse response, try { rp = uploadPackFactory.create(req, getRepository(req)); } catch (ServiceNotAuthorizedException e) { - rsp.sendError(SC_UNAUTHORIZED); + rsp.sendError(SC_UNAUTHORIZED, e.getMessage()); return; - } catch (ServiceNotEnabledException e) { - sendError(req, rsp, SC_FORBIDDEN); + sendError(req, rsp, SC_FORBIDDEN, e.getMessage()); return; }