Skip to content

Commit

Permalink
Merge pull request #1 from OS2web/sprint-2
Browse files Browse the repository at this point in the history
OS2Forms Sprint 2
  • Loading branch information
andriyun authored Dec 12, 2019
2 parents 6c01bdc + 31cffd6 commit 51dad60
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 14 deletions.
37 changes: 37 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
language: php

sudo: false

php:
- 7.2

install:
- composer global require drush/drush:8.x-dev drupal/coder mglaman/drupal-check friendsoftwig/twigcs
- export PATH="$HOME/.config/composer/vendor/bin:$PATH"
- phpcs --config-set installed_paths ../../drupal/coder/coder_sniffer
- phpenv rehash
- nvm install node
- nvm use node
- npm install --global yarn
- cd ../ && drush dl drupal-8 --drupal-project-rename=drupal
- cd drupal
- DRUPAL_ROOT=$(pwd)
- export REPOSITORIES='"repositories":\ \['
- export REPOSITORIES_REPLACE='"repositories":\[\{"type":"path","url":"..\/os2web_simplesaml","options":\{"symlink":false\}\},'
- export REQUIRE='"require":\ {'
- export REQUIRE_REPLACE='"require":{"os2web\/os2web_simplesaml":"\*",'
- sed -i "s/$REPOSITORIES/$REPOSITORIES_REPLACE/g" composer.json
- sed -i "s/$REQUIRE/$REQUIRE_REPLACE/g" composer.json
- composer update
- PROJECT_PATH=$DRUPAL_ROOT/modules/contrib/os2web_simplesaml
- cd $DRUPAL_ROOT/core
- yarn install
- npm install --global eslint-config-drupal-bundle stylelint

script:
- phpcs --standard=Drupal --ignore=*.md $PROJECT_PATH
- twigcs $PROJECT_PATH
- cd $DRUPAL_ROOT/core
- eslint $PROJECT_PATH
- stylelint --aei $PROJECT_PATH/**/*.css
- drupal-check $PROJECT_PATH
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#Module purpose
# OS2Web SimpleSAML Drupal module [![Build Status](https://travis-ci.org/OS2web/os2web_simplesaml.svg?branch=8.x)](https://travis-ci.org/OS2web/os2web_simplesaml)

## Module purpose

The aim of this module is to enhance integration with **simplesamlphp_auth** module, by force triggering **SimpleSAML auth page** redirect when certain criteria are met.

#How does it work
## How does it work

Module performs checks on a single redirect triggering page. In order for it to work the cache for anonymous user for that page response is programmatically killed.

Expand All @@ -16,7 +18,7 @@ To improve the performance, the redirect decision is stored in cookies to a limi

Additionally module provides a special field for user entity, called **SimpleSAML UID** that allows to create a **SimpleSAML mapping** with the existing Drupal users.

#Additional setings
## Additional setings

- **IP's whitelist**
Comma separate values of IP or IP ranges that will be redirected to SimpleSAML auth page.
Expand All @@ -25,3 +27,35 @@ A certain page that triggers the redirect to SimpleSAML auth page if the criteri
- **Cookies TTL**
Stores the redirect response in the cookies for a certain period of time (_defaults: 5min_).

## Install

Module is available to download via composer.
```
composer require os2web/os2web_simplesaml
drush en os2web_simplesaml
```

## Update
Updating process for OS2Web SimpleSAML module is similar to usual Drupal 8 module.
Use Composer's built-in command for listing packages that have updates available:

```
composer outdated os2web/os2web_simplesaml
```

## Automated testing and code quality
See [OS2Web testing and CI information](https://github.com/OS2Web/docs#testing-and-ci)

## Contribution

Project is opened for new features and os course bugfixes.
If you have any suggestion or you found a bug in project, you are very welcome
to create an issue in github repository issue tracker.
For issue description there is expected that you will provide clear and
sufficient information about your feature request or bug report.

### Code review policy
See [OS2Web code review policy](https://github.com/OS2Web/docs#code-review)

### Git name convention
See [OS2Web git name convention](https://github.com/OS2Web/docs#git-guideline)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Enhances integration with simplesamlphp_auth module, by force triggering SimpleSAML auth page redirect when certain criteria are met",
"minimum-stability": "dev",
"prefer-stable": true,
"license": "GPL-2.0+",
"license": "EUPL-1.2",
"require": {
"drupal/simplesamlphp_auth": "^3.1"
}
Expand Down
1 change: 1 addition & 0 deletions os2web_simplesaml.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type: module
description: Enhances integration with simplesamlphp_auth module, by force triggering SimpleSAML auth page redirect when certain criteria are met.
package: OS2Web
core: 8.x
core_version_requirement: ^8 || ^9
configure: simplesamlphp_auth.admin_settings_local

dependencies:
Expand Down
20 changes: 10 additions & 10 deletions os2web_simplesaml.module
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ use Drupal\Core\Url;
function os2web_simplesaml_form_simplesamlphp_auth_local_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$config = \Drupal::config('os2web_simplesaml.settings');

$form['os2web_simplesaml_additional_settings'] = array(
$form['os2web_simplesaml_additional_settings'] = [
'#type' => 'fieldset',
'#title' => t('OS2Web SimpleSAML additional settings'),
);
$form['os2web_simplesaml_additional_settings']['redirect_ips'] = array(
];
$form['os2web_simplesaml_additional_settings']['redirect_ips'] = [
'#type' => 'textfield',
'#title' => t("Redirect IP's to SimpleSAML login"),
'#default_value' => $config->get('redirect_ips'),
'#description' => t('Comma separated. Ex. 192.168.1.1,192.168.2.1'),
);
$form['os2web_simplesaml_additional_settings']['redirect_trigger_path'] = array(
];
$form['os2web_simplesaml_additional_settings']['redirect_trigger_path'] = [
'#type' => 'textfield',
'#title' => t('Redirect triggering path'),
'#default_value' => $config->get('redirect_trigger_path'),
'#description' => t('The path that will trigger the redirect. NB! The caching for that path will be programmatically disabled.'),
'#required' => TRUE,
);
$form['os2web_simplesaml_additional_settings']['redirect_cookies_ttl'] = array(
];
$form['os2web_simplesaml_additional_settings']['redirect_cookies_ttl'] = [
'#type' => 'number',
'#min' => 0,
'#step' => 10,
'#title' => t('Redirect cookies time to live (TTL)'),
'#default_value' => $config->get('redirect_cookies_ttl'),
'#description' => t('Number of seconds, after which the positive or negative redirect decision will expire. Setting long time improves the performance, but IP rules change will take longer to become active for all users.'),
'#required' => TRUE,
);
];

$form['#validate'][] = 'os2web_simplesaml_form_validate';
$form['#submit'][] = 'os2web_simplesaml_form_submit';
Expand Down Expand Up @@ -143,7 +143,7 @@ function os2web_simplesaml_form_user_register_form_alter(&$form, FormStateInterf
*
* @see os2web_simplesaml_user_form_submit()
*/
function os2web_simplesaml_user_form_includes(&$form) {
function os2web_simplesaml_user_form_includes(array &$form) {
// Getting SimpleSAML existing authname to use as an example.
$query = \Drupal::database()->select('authmap', 'am')
->fields('am', ['authname'])
Expand All @@ -155,7 +155,7 @@ function os2web_simplesaml_user_form_includes(&$form) {
'#type' => 'textfield',
'#title' => t('SimpleSAML UID'),
'#access' => \Drupal::currentUser()->hasPermission('change saml authentication setting'),
'#description' => $simplesamlExample ? t('Example of the existing SimpleSAML entry from authmap table: <b>@simplesaml</b>', array('@simplesaml' => $simplesamlExample)) : t('Provide a string serves the UID of the user.')
'#description' => $simplesamlExample ? t('Example of the existing SimpleSAML entry from authmap table: <b>@simplesaml</b>', ['@simplesaml' => $simplesamlExample]) : t('Provide a string serves the UID of the user.'),
];

// Adding custom validation.
Expand Down

0 comments on commit 51dad60

Please sign in to comment.