jbittel/django-mama-cas

Allow service backends to have access to the current request or user

stsewd opened this issue · 0 comments

Hi, thank you for maintaining mama CAS!

Currently, service backends have access to the service only.

class SettingsBackend(object):
def get_callbacks(self, service):
return services.get_config(service, 'CALLBACKS')
def get_logout_url(self, service):
return services.get_config(service, 'LOGOUT_URL')
def logout_allowed(self, service):
return services.get_config(service, 'LOGOUT_ALLOW')
def proxy_allowed(self, service):
return services.get_config(service, 'PROXY_ALLOW')
def proxy_callback_allowed(self, service, pgturl):
try:
return services.get_config(service, 'PROXY_PATTERN').match(pgturl)
except AttributeError:
return False
def service_allowed(self, service):
if not service:
return False
return services.is_valid(service)

It can be useful to have access to the current user to check if that user is allowed to access the given service.

Maybe the current user can be passed in the constructor or on each method call.

backend = import_string(backend_path)()

if not service_allowed(service):