*/ namespace oat\tao\model\auth; use oat\oatbox\service\ConfigurableService; /** * Class AbstractAuthService * @package oat\tao\model\auth */ abstract class AbstractAuthService extends ConfigurableService { const OPTION_TYPES = 'types'; const OPTION_DEFAULT_TYPE = 'type'; /** * Get all available type from config * * @return array of the auth types from the configuration file */ public function getTypes() { return $this->hasOption(self::OPTION_TYPES) ? $this->getOption(self::OPTION_TYPES) : []; } /** * Get the authType form config * * @param \core_kernel_classes_Resource|null $resource * @return AbstractAuthType * @throws \common_Exception */ public function getAuthType(\core_kernel_classes_Resource $resource = null) { if ($resource) { $authTypeUri = $resource->getUri(); foreach ($this->getOption(self::OPTION_TYPES) as $type) { if ($type instanceof AbstractAuthType && $type->getAuthClass()->getUri() == $authTypeUri) { $authType = $type; } } } else { $authType = $this->getOption(self::OPTION_DEFAULT_TYPE); } if (!isset($authType) || !is_a($authType, AbstractAuthType::class)) { throw new \common_Exception('Auth type not defined'); } return $authType; } }