/** * Retreive user attributes. * * @retrun array */ public static function attributes() { if (is_null(self::$attributes)) { if (!self::isAuthenticated()) { throw new AuthSPAuthenticationNotFoundException(); } self::load(); $attributes = array('idp' => getenv('Shib-Identity-Provider'), 'http_unscoped_affiliation' => getenv('unscoped-affiliation'), 'http_affiliation' => getenv('affiliation')); // Wanted attributes foreach (array('email') as $attr) { // Keys in raw_attributes (can be array of key) $keys = self::$config[$attr . '_attribute']; if (!is_array($keys)) { $keys = array($keys); } $values = array(); foreach ($keys as $key) { // For all possible keys for attribute $value = explode(';', getenv($key)); foreach ($value as $v) { $values[] = $v; } // Gather values of all successive possible keys as array } $values = array_filter(array_map('trim', $values)); // Remove empty values $attributes[$attr] = count($values) ? $values : null; } if (!$attributes['email']) { throw new AuthSPMissingAttributeException('email'); } foreach ($attributes['email'] as $email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new AuthSPBadAttributeException('email'); } } if (!isset($attributes['name'])) { $attributes['name'] = substr($attributes['email'][0], 0, strpos($attributes['email'][0], '@')); } self::$attributes = $attributes; } return self::$attributes; }
/** * Retreive user attributes. * * @retrun array */ public static function attributes() { if (is_null(self::$attributes)) { if (!self::isAuthenticated()) { throw new AuthSPAuthenticationNotFoundException(); } self::load(); $attributes = array('idp' => getenv('Shib-Identity-Provider')); // Wanted attributes foreach (array('uid', 'name', 'email') as $attr) { // Keys in raw_attributes (can be array of key) $keys = self::$config[$attr . '_attribute']; if (!is_array($keys)) { $keys = array($keys); } $values = array(); foreach ($keys as $key) { // For all possible keys for attribute $value = explode(';', getenv($key)); foreach ($value as $v) { $values[] = $v; } // Gather values of all successive possible keys as array } $values = array_filter(array_map('trim', $values)); // Remove empty values $attributes[$attr] = count($values) ? $values : null; } // Proccess received attributes if (is_array($attributes['uid'])) { $attributes['uid'] = array_shift($attributes['uid']); } if (is_array($attributes['name'])) { $attributes['name'] = array_shift($attributes['name']); } if (!$attributes['uid']) { throw new AuthSPMissingAttributeException('uid'); } if (!$attributes['email']) { throw new AuthSPMissingAttributeException('email'); } foreach ($attributes['email'] as $email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new AuthSPBadAttributeException('email'); } } if (!$attributes['name']) { $attributes['name'] = substr($attributes['email'][0], 0, strpos($attributes['email'][0], '@')); } // Gather additionnal attributes if required $additional_attributes = Config::get('auth_sp_additional_attributes'); if ($additional_attributes) { $attributes['additional'] = array(); foreach ($additional_attributes as $key => $from) { if (is_numeric($key) && is_callable($from)) { continue; } if (is_callable($from) && !is_string($from)) { $value = $from($attributes); } else { $value = explode(';', getenv($from)); if (count($value) == 1) { $value = array_shift($value); } } $attributes['additional'][is_numeric($key) ? $from : $key] = $value; } } self::$attributes = $attributes; } return self::$attributes; }