-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ASUWebPlatforms/WS2-1205
WS2-1205: Add webspark_cas module.
- Loading branch information
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# WebSpark CAS module | ||
|
||
The WebSpark CAS module contains functionality which allows the Elastic Crawler to bypass the CAS redirect and process the web pages successfully. | ||
|
||
## Setup | ||
|
||
The following setting should be added to the `settings.php` file. If no such setting exists, the default setting will be used. | ||
|
||
```php | ||
$settings['webspark_cas_elastic_crawler_regex'] = '/^Elastic-Crawler .*$/'; | ||
``` | ||
|
||
This setting describes the RegExp used to determine the `Elastic Crawler` request based on its `User-Agent` HTTP Header value. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Drupal\webspark_cas\EventSubscriber; | ||
|
||
use Drupal\cas\Subscriber\CasSubscriber; | ||
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | ||
use Drupal\Core\Site\Settings; | ||
|
||
/** | ||
* WebSpark CAS event subscriber. | ||
*/ | ||
class WebSparkCasSubscriber extends CasSubscriber { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(GetResponseEvent $event) { | ||
if ($this->isElasticCrawlerRequest()) { | ||
return; | ||
} | ||
|
||
return parent::handle($event); | ||
} | ||
|
||
/** | ||
* Checks if it is Elastic Crawler request. | ||
* | ||
* @return bool | ||
* The check result. | ||
*/ | ||
protected function isElasticCrawlerRequest(): bool { | ||
$current_request = $this->requestStack->getCurrentRequest(); | ||
|
||
$defaultPattern = '/^Elastic-Crawler .*$/'; | ||
|
||
// Get the regex from $settings if available. | ||
$elasticPattern = Settings::get('webspark_cas_elastic_crawler_regex', $defaultPattern); | ||
|
||
$agent = $current_request->server->get('HTTP_USER_AGENT'); | ||
if (empty($agent)) { | ||
return FALSE; | ||
} | ||
|
||
if (\preg_match($elasticPattern, $agent)) { | ||
// Allow the Elastic crawler. | ||
return TRUE; | ||
} | ||
|
||
return FALSE; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: WebSpark CAS | ||
type: module | ||
description: WebSpark CAS | ||
package: WebSpark | ||
core: 8.x | ||
core_version_requirement: ^8 || ^9 | ||
dependencies: | ||
- cas:cas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
services: | ||
cas.subscriber: | ||
class: Drupal\webspark_cas\EventSubscriber\WebSparkCasSubscriber | ||
arguments: ['@request_stack', '@current_route_match', '@config.factory', '@current_user', '@plugin.manager.condition', '@cas.helper', '@cas.redirector'] | ||
tags: | ||
- { name: event_subscriber } |