protected function Resource::initAuthenticationManager in RESTful 7.2
Initializes the authentication manager and adds the appropriate providers.
This will return an AuthenticationManagerInterface if the current resource needs to be authenticated. To skip authentication completely do not set authenticationTypes and set authenticationOptional to TRUE.
1 call to Resource::initAuthenticationManager()
- Resource::__construct in src/
Plugin/ resource/ Resource.php - Constructs a Drupal\Component\Plugin\PluginBase object.
File
- src/
Plugin/ resource/ Resource.php, line 624 - Contains \Drupal\restful\Plugin\resource\Resource.
Class
Namespace
Drupal\restful\Plugin\resourceCode
protected function initAuthenticationManager() {
$this->authenticationManager = new AuthenticationManager();
$plugin_definition = $this
->getPluginDefinition();
$authentication_types = $plugin_definition['authenticationTypes'];
$authentication_optional = $plugin_definition['authenticationOptional'];
$this->authenticationManager
->setIsOptional($authentication_optional);
if (empty($authentication_types)) {
if (empty($authentication_optional)) {
// Fail early, fail good.
throw new UnauthorizedException('There are no authentication providers and authentication is not optional.');
}
return;
}
if ($authentication_types === TRUE) {
// Add all the available authentication providers to the manager.
$this->authenticationManager
->addAllAuthenticationProviders();
return;
}
foreach ($authentication_types as $authentication_type) {
// Read the authentication providers and add them to the manager.
$this->authenticationManager
->addAuthenticationProvider($authentication_type);
}
}