]> source.dussan.org Git - jgit.git/commitdiff
Use message from ServiceNotAuthorizedException, ServiceNotEnabledException 79/49279/1
authorJonathan Nieder <jrn@google.com>
Tue, 2 Jun 2015 23:40:23 +0000 (16:40 -0700)
committerJonathan Nieder <jrn@google.com>
Tue, 2 Jun 2015 23:54:08 +0000 (16:54 -0700)
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 <jrn@google.com>
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/AsIsFileFilter.java
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/ReceivePackServlet.java
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/RepositoryFilter.java
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/SmartServiceInfoRefs.java
org.eclipse.jgit.http.server/src/org/eclipse/jgit/http/server/UploadPackServlet.java

index e8d809659b46144a766a2f7e87ac3776a0320947..d33362b4b45cddb8cedf67e398652c1a51be89db 100644 (file)
@@ -87,9 +87,9 @@ class AsIsFileFilter implements Filter {
                        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());
                }
        }
 }
index 030287b5cf508e3daf4d183b649a00c696530765..41217d9971356e3476f77f30553fc0d746092b28 100644 (file)
@@ -137,11 +137,10 @@ class ReceivePackServlet extends HttpServlet {
                        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;
                        }
 
index 58404020cd25b0fedaad64fbc09f20776cb5df6b..a021c1ff5ecdcec3df66b162ca1fd8f6f630aaa5 100644 (file)
@@ -137,10 +137,10 @@ public class RepositoryFilter implements Filter {
                        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());
index 51332194b8b6695bc9df1fafd7e7b854c4c96539..7d4f21b5c44c5e9f96c3c83f6486954a1c40160a 100644 (file)
@@ -98,7 +98,7 @@ abstract class SmartServiceInfoRefs implements Filter {
                        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 @@ abstract class SmartServiceInfoRefs implements Filter {
                        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();
index 44d4b1bcfa3ea1d56200cf879710d1eec4ba4a47..8c27b712ba9783779e010355678c568395b8ba61 100644 (file)
@@ -137,11 +137,10 @@ class UploadPackServlet extends HttpServlet {
                        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;
                        }