Parses the global policy configuration and initializes roles and privileges accordingly

@return void
@throws SecurityException
425673
protected function initialize()
    {
        if ($this->initialized) {
            return;
        }

        $this->policyConfiguration = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_POLICY);
        $this->emitConfigurationLoaded($this->policyConfiguration);

        $this->initializePrivilegeTargets();

        $privilegeTargetsForEverybody = $this->privilegeTargets;

        $this->roles = [];
        $everybodyRole = new Role('Neos.Flow:Everybody');
        $everybodyRole->setAbstract(true);
        if (isset($this->policyConfiguration['roles'])) {
            foreach ($this->policyConfiguration['roles'] as $roleIdentifier => $roleConfiguration) {
                if ($roleIdentifier === 'Neos.Flow:Everybody') {
                    $role = $everybodyRole;
                } else {
                    $role = new Role($roleIdentifier);
                    if (isset($roleConfiguration['abstract'])) {
                        $role->setAbstract((boolean)$roleConfiguration['abstract']);
                    }
                }

                if (isset($roleConfiguration['privileges'])) {
                    foreach ($roleConfiguration['privileges'] as $privilegeConfiguration) {
                        $privilegeTargetIdentifier = $privilegeConfiguration['privilegeTarget'];
                        if (!isset($this->privilegeTargets[$privilegeTargetIdentifier])) {
                            throw new SecurityException(sprintf('privilege target "%s", referenced in role configuration "%s" is not defined!', $privilegeTargetIdentifier, $roleIdentifier), 1395869320);
                        }
                        $privilegeTarget = $this->privilegeTargets[$privilegeTargetIdentifier];
                        if (!isset($privilegeConfiguration['permission'])) {
                            throw new SecurityException(sprintf('No permission set for privilegeTarget "%s" in Role "%s"', $privilegeTargetIdentifier, $roleIdentifier), 1395869331);
                        }
                        $privilegeParameters = isset($privilegeConfiguration['parameters']) ? $privilegeConfiguration['parameters'] : [];
                        try {
                            $privilege = $privilegeTarget->createPrivilege($privilegeConfiguration['permission'], $privilegeParameters);
                        } catch (\Exception $exception) {
                            throw new SecurityException(sprintf('Error for privilegeTarget "%s" in Role "%s": %s', $privilegeTargetIdentifier, $roleIdentifier, $exception->getMessage()), 1401886654, $exception);
                        }
                        $role->addPrivilege($privilege);

                        if ($roleIdentifier === 'Neos.Flow:Everybody') {
                            unset($privilegeTargetsForEverybody[$privilegeTargetIdentifier]);
                        }
                    }
                }

                $this->roles[$roleIdentifier] = $role;
            }
        }

        // create ABSTAIN privilege for all uncovered privilegeTargets
        /** @var PrivilegeTarget $privilegeTarget */
        foreach ($privilegeTargetsForEverybody as $privilegeTarget) {
            if ($privilegeTarget->hasParameters()) {
                continue;
            }
            $everybodyRole->addPrivilege($privilegeTarget->createPrivilege(PrivilegeInterface::ABSTAIN));
        }
        $this->roles['Neos.Flow:Everybody'] = $everybodyRole;

        // Set parent roles
        /** @var Role $role */
        foreach ($this->roles as $role) {
            if (isset($this->policyConfiguration['roles'][$role->getIdentifier()]['parentRoles'])) {
                foreach ($this->policyConfiguration['roles'][$role->getIdentifier()]['parentRoles'] as $parentRoleIdentifier) {
                    $role->addParentRole($this->roles[$parentRoleIdentifier]);
                }
            }
        }

        $this->emitRolesInitialized($this->roles);

        $this->initialized = true;
    }
1116200
protected void initialize() throws GeneralSecurityException {
		if(keyPair == null) {
			keyPair = createKeyPair();
		}
		keyAgreement.init(keyPair.getPrivate());
	}
679025
public function init()
    {
        $default = $this->config->get('system.languages.default_lang');
        if (isset($default) && $this->validate($default)) {
            $this->default = $default;
        } else {
            $this->default = reset($this->languages);
        }

        $this->page_extensions = null;

        if (empty($this->languages)) {
            $this->enabled = false;
        }
    }
998402
protected function initSURole() : void
    {
        $this->stdout("Init SU role \n",  Console::FG_YELLOW);
        $this->authManager->removeAll();
        $su = $this->authManager->createRole(Rbac::R_SU);
        $su->description = 'Super User';
        $this->authManager->add($su);
    }
869481
protected function init()
    {
        $this->hasFields('eid', 'secret', 'mode', 'pcStorage', 'pcURI');

        if (!is_int($this->config['eid'])) {
            $this->config['eid'] = intval($this->config['eid']);
        }

        if ($this->config['eid'] <= 0) {
            throw new Klarna_ConfigFieldMissingException('eid');
        }

        if (!is_string($this->config['secret'])) {
            $this->config['secret'] = strval($this->config['secret']);
        }

        if (strlen($this->config['secret']) == 0) {
            throw new Klarna_ConfigFieldMissingException('secret');
        }

        //Set the shop id and secret.
        $this->_eid = $this->config['eid'];
        $this->_secret = $this->config['secret'];

        //Set the country specific attributes.
        try {
            $this->hasFields('country', 'language', 'currency');

            //If hasFields doesn't throw exception we can set them all.
            $this->setCountry($this->config['country']);
            $this->setLanguage($this->config['language']);
            $this->setCurrency($this->config['currency']);
        } catch(Exception $e) {
            //fields missing for country, language or currency
            $this->_country = $this->_language = $this->_currency = null;
        }

        //Set addr and port according to mode.
        $this->mode = (int)$this->config['mode'];

        $this->_url = array();

        // If a custom url has been added to the config, use that as xmlrpc
        // recipient.
        if (isset($this->config['url'])) {
            $this->_url = parse_url($this->config['url']);
            if ($this->_url === false) {
                $message = "Configuration value 'url' could not be parsed. " .
                    "(Was: '{$this->config['url']}')";
                Klarna::printDebug(__METHOD__, $message);
                throw new InvalidArgumentException($message);
            }
        } else {

            $this->_url['scheme'] = 'https';

            if ($this->mode === self::LIVE) {
                $this->_url['host'] = self::$_live_addr;
            } else {
                $this->_url['host'] = self::$_beta_addr;
            }

            if (isset($this->config['ssl'])
                && (bool)$this->config['ssl'] === false
            ) {
                $this->_url['scheme'] = 'http';
            }
        }

        // If no port has been specified, deduce from url scheme
        if (!array_key_exists('port', $this->_url)) {
            if ($this->_url['scheme'] === 'https') {
                $this->_url['port'] = 443;
            } else {
                $this->_url['port'] = 80;
            }
        }

        try {
            $this->hasFields('xmlrpcDebug');
            Klarna::$xmlrpcDebug = $this->config['xmlrpcDebug'];
        } catch(Exception $e) {
            //No 'xmlrpcDebug' field ignore it...
        }

        try {
            $this->hasFields('debug');
            Klarna::$debug = $this->config['debug'];
        } catch(Exception $e) {
            //No 'debug' field ignore it...
        }

        $this->pcStorage = $this->config['pcStorage'];
        $this->pcURI = $this->config['pcURI'];

        // Default path to '/' if not set.
        if (!array_key_exists('path', $this->_url)) {
            $this->_url['path'] = '/';
        }

        $this->xmlrpc = new xmlrpc_client(
            $this->_url['path'],
            $this->_url['host'],
            $this->_url['port'],
            $this->_url['scheme']
        );

        $this->xmlrpc->setSSLVerifyHost(2);

        $this->xmlrpc->request_charset_encoding = 'ISO-8859-1';
    }
248563
public function boot()
    {
        parent::registerPolicies();

        $authPolicies = [
            DashboardPolicy::class      => DashboardPolicy::policies(),
            UsersPolicy::class          => UsersPolicy::policies(),
            RolesPolicy::class          => RolesPolicy::policies(),
            PermissionsPolicy::class    => PermissionsPolicy::policies(),
            PasswordResetsPolicy::class => PasswordResetsPolicy::policies()
        ];

        foreach ($authPolicies as $class => $policies) {
            $this->defineMany($class, $policies);
        }
    }
1226756
protected function setup()
    {
        if (null === $this->getIdentity()) {
            throw new Exception\RuntimeException('A value for the identity was not provided');
        }

        if (null === $this->getCredential()) {
            throw new Exception\RuntimeException('A credential value was not provided');
        }

        $this->storeAuthenticationResult(AuthenticationResult::FAILURE_UNCATEGORIZED);
    }
581239
protected function initConfig(): void
    {
        $configFile = $this->getRootRelatedPath($this->getConfigFileName());

        $this->assertFileIsReadable($configFile);

        self::$config = (array)(include $configFile);
    }
1024020
public function init() {

		parent::init();

		// Views
		$this->setViewPath( '@cmsgears/module-core/admin/views/role' );

		// Permission
		$this->crudPermission = CoreGlobal::PERM_RBAC;

		// Config
		$this->type		= CoreGlobal::TYPE_SYSTEM;
		$this->apixBase	= 'core/role';

		// Services
		$this->modelService = Yii::$app->factory->get( 'roleService' );

		$this->permissionService	= Yii::$app->factory->get( 'permissionService' );
		$this->hierarchyService		= Yii::$app->factory->get( 'modelHierarchyService' );
	}
756545
public function Initialize() {
      parent::Initialize();
      Gdn_Theme::Section('Dashboard');
      if ($this->Menu)
         $this->Menu->HighlightRoute('/dashboard/authentication');
         
      $this->EnableSlicing($this);
      
      $Authenticators = Gdn::Authenticator()->GetAvailable();
      $this->ChooserList = array();
      $this->ConfigureList = array();
      foreach ($Authenticators as $AuthAlias => $AuthConfig) {
         $this->ChooserList[$AuthAlias] = $AuthConfig['Name'];
         $Authenticator = Gdn::Authenticator()->AuthenticateWith($AuthAlias);
         $ConfigURL = (is_a($Authenticator, "Gdn_Authenticator") && method_exists($Authenticator, 'AuthenticatorConfiguration')) ? $Authenticator->AuthenticatorConfiguration($this) : FALSE;
         $this->ConfigureList[$AuthAlias] = $ConfigURL;
      }
      $this->CurrentAuthenticationAlias = Gdn::Authenticator()->AuthenticateWith('default')->GetAuthenticationSchemeAlias();
   }
155260
public function init() {

		parent::init();

		// Permission
		$this->crudPermission = CoreGlobal::PERM_USER;

		// Config
		$this->layout = CoreGlobalWeb::LAYOUT_PUBLIC;

		// Services
		$this->modelService = Yii::$app->factory->get( 'pageService' );

		$this->templateService = Yii::$app->factory->get( 'templateService' );
	}
195315
public function initSecurity()
    {
        $nb_engine = CNabuEngine::getEngine();
        $nb_session = $this->nb_application->getSession();

        $this->nb_role = $nb_session->getVariable(self::VAR_SESSION_ROLE, null);
        $this->nb_site_role = $nb_session->getVariable(self::VAR_SESSION_SITE_ROLE, null);
        $this->nb_user = $nb_session->getVariable(self::VAR_SESSION_USER, null);
        $this->nb_site_user = $nb_session->getVariable(self::VAR_SESSION_SITE_USER, null);
        $this->nb_work_customer = $nb_session->getVariable(self::VAR_SESSION_WORK_CUSTOMER, null);
    }
358384
public function loadConfiguration(): void
	{
		$builder = $this->getContainerBuilder();
		$config = $this->validateConfig($this->defaults);

		Validators::assertField($config, 'enabled', 'bool');
		Validators::assertField($config, 'users', 'array');

		// Skip if its disabled
		if ($config['enabled'] !== true) return;

		// Throws if there's no user
		if ($config['users'] === []) throw new LogicException('You have to define any user or disable extension');

		$def = $builder->addDefinition($this->prefix('authenticator'))
			->setType(BasicAuthenticator::class)
			->setArguments([$config['title']]);

		foreach ($config['users'] as $user => $values) {
			if (is_string($values)) {
				trigger_error('Usage of `$username => $password` is deprecated, use `$username => ["password" => $password]` instead', E_USER_DEPRECATED);
				$password = $values;
				$unsecured = true;
			} else {
				$password = $values['password'];
				$unsecured = $values['unsecured'] ?? false;
			}
			$def->addSetup('addUser', [$user, $password, $unsecured]);
		}
	}
24743
protected function initPermissions()
    {
        if (isset($this->settings) && $this->settings->exists('permissions') && !self::$init_stages[$this->name]['permissions']) {

            $permissions = [
                'admin'
            ];

            if ($this->settings->exists('config')) {
                $permissions[] = 'config';
            }

            $permissions = array_merge($permissions, $this->settings->get('permissions'));

            $this->permissions = new Permissions();
            $this->permissions->set($permissions);

            // Set flat that permission init is done
            self::$init_stages[$this->name]['perms'] = true;
        }
    }
1045316
protected function config()
    {
        $this->globals['CFG'] =& load_class('Config', 'core');

        $this->globals['UNI'] =& load_class('Utf8', 'core');

        $this->globals['SEC'] =& load_class('Security', 'core');

        $this->core();
    }
98024
public function onConfigUpdated()
    {
        parent::onConfigUpdated();
        if (Daemon::$process instanceof \PHPDaemon\Thread\Worker) {
            $pool = $this;
            FileSystem::readfile($this->config->file->value, function ($file, $data) use ($pool) {
                $pool->policyData = $data;
                $pool->enable();
            });
        }
    }
834308
protected function setRoleConfig() {
    if (strlen($this->getConfig()) == 0) {
      // check added nodes for Role instances
      foreach ($this->getAddedNodes() as $relationName => $nodes) {
        foreach ($nodes as $node) {
          if ($node instanceof Role) {
            $roleName = $node->getName();
            $roleConfigs = self::getRoleConfigs();
            if (isset($roleConfigs[$roleName])) {
              $this->setConfig($roleConfigs[$roleName]);
              break;
            }
          }
        }
      }
    }
  }