2021-06-11 01:01:27 -05:00
|
|
|
# Copyright (C) 2015 Custodia Project Contributors - see LICENSE file
|
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2021-06-11 01:52:23 -05:00
|
|
|
from ipaserver.custodia import log
|
|
|
|
from ipaserver.custodia.plugin import HTTPAuthorizer
|
2021-06-11 01:01:27 -05:00
|
|
|
|
|
|
|
|
|
|
|
class SimplePathAuthz(HTTPAuthorizer):
|
|
|
|
# keep SimplePathAuthz an old-style plugin for now.
|
|
|
|
# KEMKeysStore and IPAKEMKeys haven't been ported.
|
|
|
|
|
|
|
|
def __init__(self, config):
|
|
|
|
super(SimplePathAuthz, self).__init__(config)
|
|
|
|
self.paths = []
|
|
|
|
if 'paths' in self.config:
|
|
|
|
self.paths = self.config['paths'].split()
|
|
|
|
|
|
|
|
def handle(self, request):
|
|
|
|
reqpath = path = request.get('path', '')
|
|
|
|
|
|
|
|
# if an authorized path does not end in /
|
|
|
|
# check if it matches fullpath for strict match
|
2022-02-21 06:36:10 -06:00
|
|
|
for authz in self.paths:
|
2021-06-11 01:01:27 -05:00
|
|
|
if authz.endswith('/'):
|
|
|
|
continue
|
|
|
|
if authz.endswith('.'):
|
|
|
|
# special case to match a path ending in /
|
|
|
|
authz = authz[:-1]
|
|
|
|
if authz == path:
|
|
|
|
self.audit_svc_access(log.AUDIT_SVC_AUTHZ_PASS,
|
|
|
|
request['client_id'], path)
|
|
|
|
return True
|
|
|
|
|
|
|
|
while path != '':
|
|
|
|
if path in self.paths:
|
|
|
|
self.audit_svc_access(log.AUDIT_SVC_AUTHZ_PASS,
|
|
|
|
request['client_id'], path)
|
|
|
|
return True
|
|
|
|
if path == '/':
|
|
|
|
path = ''
|
|
|
|
else:
|
2021-06-11 01:43:23 -05:00
|
|
|
path, _head = os.path.split(path)
|
2021-06-11 01:01:27 -05:00
|
|
|
|
|
|
|
self.logger.debug('No path in %s matched %s', self.paths, reqpath)
|
|
|
|
return None
|