/** * Retreive user attributes. * * @retrun array */ public static function attributes() { if (is_null(self::$attributes)) { if (!self::isAuthenticated()) { throw new AuthSPAuthenticationNotFoundException(); } $attributes = array(); // Wanted attributes foreach (array('HTTP_SHIB_IDENTITY_PROVIDER', 'email', 'http_unscoped_afiliation', 'HTTP_AFFILIATION') as $attr) { // Keys in raw_attributes (can be array of key) $attributes[$attr] = Config::get('auth_sp_fake_' . $attr); } if (!$attributes['email']) { throw new AuthSPMissingAttributeException('email'); } if (!is_array($attributes['email'])) { $attributes['email'] = array($attributes['email']); } foreach ($attributes['email'] as $email) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new AuthSPBadAttributeException('email'); } } if (!$attributes['email']) { $attributes['email'] = substr($attributes['email'], 0, strpos($attributes['email'], '@')); } 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(); } $attributes = array(); // Wanted attributes foreach (array('uid', 'name', 'email') as $attr) { // Keys in raw_attributes (can be array of key) $attributes[$attr] = Config::get('auth_sp_fake_' . $attr); } // Check attributes if (!$attributes['uid']) { throw new AuthSPMissingAttributeException('uid'); } if (!$attributes['email']) { throw new AuthSPMissingAttributeException('email'); } if (!is_array($attributes['email'])) { $attributes['email'] = array($attributes['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, strpos($attributes['email'], '@')); } // Build additionnal attributes $additional_attributes = Config::get('auth_sp_additional_attributes'); if ($additional_attributes) { $additional_attributes_values = (array) Config::get('auth_sp_fake_additional_attributes_values'); $attributes['additional'] = array(); foreach ($additional_attributes as $key => $from) { if (is_numeric($key) && is_callable($from)) { continue; } if (is_callable($from)) { $value = $from(); } elseif (array_key_exists($from, $additional_attributes_values)) { $value = $additional_attributes_values[$from]; } else { $value = null; } $attributes['additional'][is_numeric($key) ? $from : $key] = $value; } } self::$attributes = $attributes; } return self::$attributes; }