You are here

public function CasAttributesSubscriber::onPostLogin in CAS Attributes 2.x

Same name and namespace in other branches
  1. 8 src/Subscriber/CasAttributesSubscriber.php \Drupal\cas_attributes\Subscriber\CasAttributesSubscriber::onPostLogin()

Save attributes to user session if sitewide token support is enabled.

Parameters

\Drupal\cas\Event\CasPostLoginEvent $casPostLoginEvent: The post login event from CAS.

File

src/Subscriber/CasAttributesSubscriber.php, line 367

Class

CasAttributesSubscriber
Provides a CasAttributesSubscriber.

Namespace

Drupal\cas_attributes\Subscriber

Code

public function onPostLogin(CasPostLoginEvent $casPostLoginEvent) {
  if ($this->settings
    ->get('sitewide_token_support')) {
    $session = $this->requestStack
      ->getCurrentRequest()
      ->getSession();
    $attributes = $casPostLoginEvent
      ->getCasPropertyBag()
      ->getAttributes();
    $token_allowed_attributes = $this->settings
      ->get('token_allowed_attributes');
    if (!empty($token_allowed_attributes)) {

      // Change to all lowercase faciliate case insensitive matching.
      $token_allowed_attributes = array_map('mb_strtolower', $token_allowed_attributes);
      foreach ($attributes as $key => $value) {
        if (!in_array(mb_strtolower($key), $token_allowed_attributes)) {
          unset($attributes[$key]);
        }
      }
    }
    $session
      ->set('cas_attributes', $attributes);
  }
}