def requires_auth(function):
""" Bind against LDAP to validate users credentials """
@wraps(function)
def decorated(*args, **kwargs):
logger = logging.getLogger("ca_server")
auth = request.authorization
ldap = LdapClient()
if not auth or not ldap.check_auth(auth.username, auth.password):
output = DataBag()
output.set_error("Access denied")
if hasattr(auth, "username"):
logger.info("requires_auth: access denied {}".format(auth.username))
else:
logger.info("requires_auth: access denied")
return output.get_json()
return function(auth.username)
return decorated
评论列表
文章目录