| 1 |
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file |
| 2 |
from __future__ import absolute_import |
| 3 |
|
| 4 |
import os |
| 5 |
|
| 6 |
from ipaserver.custodia import log |
| 7 |
from ipaserver.custodia.plugin import HTTPAuthorizer |
| 8 |
|
| 9 |
|
| 10 |
class SimplePathAuthz(HTTPAuthorizer): |
| 11 |
# keep SimplePathAuthz an old-style plugin for now. |
| 12 |
# KEMKeysStore and IPAKEMKeys haven't been ported. |
| 13 |
|
| 14 |
def __init__(self, config): |
| 15 |
super(SimplePathAuthz, self).__init__(config) |
| 16 |
self.paths = [] |
| 17 |
if 'paths' in self.config: |
| 18 |
self.paths = self.config['paths'].split() |
| 19 |
|
| 20 |
def handle(self, request): |
| 21 |
reqpath = path = request.get('path', '') |
| 22 |
|
| 23 |
# if an authorized path does not end in / |
| 24 |
# check if it matches fullpath for strict match |
| 25 |
for authz in self.paths: |
| 26 |
if authz.endswith('/'): |
| 27 |
continue |
| 28 |
if authz.endswith('.'): |
| 29 |
# special case to match a path ending in / |
| 30 |
authz = authz[:-1] |
| 31 |
if authz == path: |
| 32 |
self.audit_svc_access(log.AUDIT_SVC_AUTHZ_PASS, |
| 33 |
request['client_id'], path) |
| 34 |
return True |
| 35 |
|
| 36 |
while path != '': |
| 37 |
if path in self.paths: |
| 38 |
self.audit_svc_access(log.AUDIT_SVC_AUTHZ_PASS, |
| 39 |
request['client_id'], path) |
| 40 |
return True |
| 41 |
if path == '/': |
| 42 |
path = '' |
| 43 |
else: |
| 44 |
path, _head = os.path.split(path) |
| 45 |
|
| 46 |
self.logger.debug('No path in %s matched %s', self.paths, reqpath) |
| 47 |
return None |