This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/saml_idp/registry.py

29 lines
938 B
Python
Raw Normal View History

2018-11-16 08:10:35 +00:00
"""Registers and loads Processor classes from settings."""
from logging import getLogger
from passbook.lib.utils.reflection import path_to_class
from passbook.saml_idp.exceptions import CannotHandleAssertion
2018-11-26 16:17:32 +00:00
from passbook.saml_idp.models import SAMLProvider
2018-11-16 08:10:35 +00:00
LOGGER = getLogger(__name__)
def get_processor(remote):
"""Get an instance of the processor with config."""
proc = path_to_class(remote.processor_path)
return proc(remote)
def find_processor(request):
"""Returns the Processor instance that is willing to handle this request."""
2018-11-26 16:17:32 +00:00
for remote in SAMLProvider.objects.all():
2018-11-16 08:10:35 +00:00
proc = get_processor(remote)
try:
if proc.can_handle(request):
return proc, remote
except CannotHandleAssertion as exc:
# Log these, but keep looking.
LOGGER.debug('%s %s', proc, exc)
raise CannotHandleAssertion('No Processors to handle this request.')