Beispiel #1
0
 /**
  * @param string $context
  * @param SecurityContextConfiguration $configuration
  * @return Security
  */
 public function create($context, SecurityContextConfiguration $configuration)
 {
     $persistences = $this->repositories->createPersistenceRepository($context);
     $roles = $this->repositories->createRoleRepository($context);
     $users = $this->repositories->createUserRepository($context, $persistences, $roles);
     $sentinel = new Sentinel($persistences, $users, $roles, $this->repositories->createActivationRepository($context), $this->container->make(Dispatcher::class));
     foreach ($configuration->listCheckpoints() as $key => $checkpoint) {
         $sentinel->addCheckpoint($key, $this->makeCheckpoint($checkpoint, $configuration));
     }
     $sentinel->setReminderRepository($this->repositories->createReminderRepository($context, $users));
     $sentinel->setRequestCredentials(function () {
         $request = $this->container->make('request');
         $login = $request->getUser();
         $password = $request->getPassword();
         if ($login === null && $password === null) {
             return;
         }
         return compact('login', 'password');
     });
     $sentinel->creatingBasicResponse(function () {
         $headers = ['WWW-Authenticate' => 'Basic'];
         return new Response('Invalid credentials.', 401, $headers);
     });
     $security = new Security($sentinel, $this->repositories->createPermissionRepository($context));
     $this->bindUrlGenerator($security);
     $security->setLoginRoute($configuration->getLoginRoute());
     return $security;
 }
 /**
  * Garbage collect activations and reminders.
  *
  * @param SecurityApi                  $security
  * @param SecurityContextConfiguration $configuration
  */
 protected function garbageCollect(SecurityApi $security, SecurityContextConfiguration $configuration)
 {
     try {
         $activations = $security->activations();
         $reminders = $security->reminders();
         $this->sweep($activations, $configuration->getActivationsLottery());
         $this->sweep($reminders, $configuration->getRemindersLottery());
     } catch (\Exception $e) {
         // Silently fail and report, but still serve the content.
         $this->logger->error("Unable to garbage collect reminders or activations: " . $e->getMessage(), $e->getTrace());
     }
 }
Beispiel #3
0
 /**
  * @param SecurityContextConfiguration $configuration
  * @throws \BadMethodCallException
  */
 private function updateMappings(SecurityContextConfiguration $configuration)
 {
     $mappings = $configuration->getMappings();
     if (!$configuration->isRolesEnabled()) {
         $this->validateAndCall($mappings['user'], 'disableRoles');
     }
     if (!$configuration->isThrottlesEnabled()) {
         $this->validateAndCall($mappings['user'], 'disableThrottles');
     }
     if (!$configuration->isPermissionsEnabled()) {
         $this->validateAndCall($mappings['user'], 'disablePermissions');
         if (isset($mappings['role'])) {
             $this->validateAndCall($mappings['role'], 'disablePermissions');
         }
     }
     if ($table = $configuration->getTable('usersRoles')) {
         $this->validateAndCall($mappings['user'], 'changeRolesJoinTable', $table);
         if (isset($mappings['role'])) {
             $this->validateAndCall($mappings['role'], 'changeRolesJoinTable', $table);
         }
     }
     $mappingObjects = [];
     foreach ($mappings as $entity => $mapping) {
         $entityMapping = $this->makeMapping($mapping);
         if ($entityMapping instanceof CustomTableMapping && ($table = $configuration->getTable($entity))) {
             $entityMapping->setTable($table);
         }
         $mappingObjects[] = $entityMapping;
     }
     $this->addMappings($mappingObjects);
 }