|
|
@@ -55,13 +55,6 @@ VERSION = "git"
|
|
|
# tries to access information they don't have rights to
|
|
|
NOT_ALLOWED = (client.FORBIDDEN, {}, None)
|
|
|
|
|
|
-# Standard "authenticate" response that is returned when a user tries to access
|
|
|
-# non-public information w/o submitting proper authentication credentials
|
|
|
-WRONG_CREDENTIALS = (
|
|
|
- client.UNAUTHORIZED,
|
|
|
- {"WWW-Authenticate": "Basic realm=\"%s\"" % config.get("server", "realm")},
|
|
|
- None)
|
|
|
-
|
|
|
|
|
|
class HTTPServer(wsgiref.simple_server.WSGIServer, object):
|
|
|
"""HTTP server."""
|
|
|
@@ -285,25 +278,28 @@ class Application(object):
|
|
|
else:
|
|
|
user = password = None
|
|
|
|
|
|
- if not items or function == self.options or \
|
|
|
- auth.is_authenticated(user, password):
|
|
|
-
|
|
|
- read_allowed_items, write_allowed_items = \
|
|
|
- self.collect_allowed_items(items, user)
|
|
|
+ read_allowed_items, write_allowed_items = \
|
|
|
+ self.collect_allowed_items(items, user)
|
|
|
|
|
|
- if read_allowed_items or write_allowed_items or \
|
|
|
- function == self.options or not items:
|
|
|
- # Collections found, or OPTIONS request, or no items at all
|
|
|
- status, headers, answer = function(
|
|
|
- environ, read_allowed_items, write_allowed_items, content,
|
|
|
- user)
|
|
|
- else:
|
|
|
- # Good user but has no rights to any of the given collections
|
|
|
- status, headers, answer = NOT_ALLOWED
|
|
|
+ if ((read_allowed_items or write_allowed_items)
|
|
|
+ and auth.is_authenticated(user, password)) or \
|
|
|
+ function == self.options or not items:
|
|
|
+ # Collections found, or OPTIONS request, or no items at all
|
|
|
+ status, headers, answer = function(
|
|
|
+ environ, read_allowed_items, write_allowed_items, content,
|
|
|
+ user)
|
|
|
else:
|
|
|
+ status, headers, answer = NOT_ALLOWED
|
|
|
+
|
|
|
+ if (status, headers, answer) == NOT_ALLOWED and \
|
|
|
+ not auth.is_authenticated(user, password):
|
|
|
# Unknown or unauthorized user
|
|
|
log.LOGGER.info("%s refused" % (user or "Anonymous user"))
|
|
|
- status, headers, answer = WRONG_CREDENTIALS
|
|
|
+ status = client.UNAUTHORIZED
|
|
|
+ headers = {
|
|
|
+ "WWW-Authenticate":
|
|
|
+ "Basic realm=\"%s\"" % config.get("server", "realm")}
|
|
|
+ answer = None
|
|
|
|
|
|
# Set content length
|
|
|
if answer:
|