Merge branch 'sch_sso' into 'develop'

SSO CAS Login

See merge request !49
parents 50c623c6 140d97e2
......@@ -8,6 +8,7 @@ drupal/modules/*
!drupal/modules/epal/
!drupal/modules/epalreadydata/
!drupal/modules/oauthost/
!drupal/modules/casost/
!drupal/modules/epaldeploysystem/
# Logs
......
name: casost
type: module
description: Authentication Provider OST
core: 8.x
package: casost
entity.casost_config.add_form:
route_name: entity.casost_config.add_form
title: 'Add CASOST Config'
appears_on:
- entity.casost_config.collection
entity.casost_session.add_form:
route_name: entity.casost_session.add_form
title: 'Add CASOST Session'
appears_on:
- entity.casost_session.collection
# CASOST Config menu items definition
entity.casost_config.collection:
title: 'CASOST Config list'
route_name: entity.casost_config.collection
description: 'List CASOST Config entities'
parent: system.admin_structure
weight: 100
casost_config.admin.structure.settings:
title: CASOST Config settings
description: 'Configure CASOST Config entities'
route_name: casost_config.settings
parent: system.admin_structure
# CASOST Session menu items definition
entity.casost_session.collection:
title: 'CASOST Session list'
route_name: entity.casost_session.collection
description: 'List CASOST Session entities'
parent: system.admin_structure
weight: 100
casost_session.admin.structure.settings:
title: CASOST Session settings
description: 'Configure CASOST Session entities'
route_name: casost_session.settings
parent: system.admin_structure
# CASOST Config routing definition
casost_config.settings_tab:
route_name: casost_config.settings
title: 'Settings'
base_route: casost_config.settings
entity.casost_config.canonical:
route_name: entity.casost_config.canonical
base_route: entity.casost_config.canonical
title: 'View'
entity.casost_config.edit_form:
route_name: entity.casost_config.edit_form
base_route: entity.casost_config.canonical
title: 'Edit'
entity.casost_config.delete_form:
route_name: entity.casost_config.delete_form
base_route: entity.casost_config.canonical
title: Delete
weight: 10
# CASOST Session routing definition
casost_session.settings_tab:
route_name: casost_session.settings
title: 'Settings'
base_route: casost_session.settings
entity.casost_session.canonical:
route_name: entity.casost_session.canonical
base_route: entity.casost_session.canonical
title: 'View'
entity.casost_session.edit_form:
route_name: entity.casost_session.edit_form
base_route: entity.casost_session.canonical
title: 'Edit'
entity.casost_session.delete_form:
route_name: entity.casost_session.delete_form
base_route: entity.casost_session.canonical
title: Delete
weight: 10
<?php
/**
* @file
* Contains casost.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function casost_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the casost module.
case 'help.page.casost':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Authentication Provider OST') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function casost_theme() {
return [
'casost' => [
'template' => 'casost',
'render element' => 'children',
],
];
}
add casost config entities:
title: 'Create new CASOST Config entities'
administer casost config entities:
title: 'Administer CASOST Config entities'
description: 'Allow to access the administration form to configure CASOST Config entities.'
restrict access: true
delete casost config entities:
title: 'Delete CASOST Config entities'
edit casost config entities:
title: 'Edit CASOST Config entities'
access casost config overview:
title: 'Access the CASOST Config overview page'
view published casost config entities:
title: 'View published CASOST Config entities'
view unpublished casost config entities:
title: 'View unpublished CASOST Config entities'
add casost session entities:
title: 'Create new CASOST Session entities'
administer casost session entities:
title: 'Administer CASOST Session entities'
description: 'Allow to access the administration form to configure CASOST Session entities.'
restrict access: true
delete casost session entities:
title: 'Delete CASOST Session entities'
edit casost session entities:
title: 'Edit CASOST Session entities'
access casost session overview:
title: 'Access the CASOST Session overview page'
view published casost session entities:
title: 'View published CASOST Session entities'
view unpublished casost session entities:
title: 'View unpublished CASOST Session entities'
casost.log_in_go:
path: /cas/login
defaults:
_controller: '\Drupal\casost\Controller\CASLogin::loginGo'
requirements:
_access: 'TRUE'
casost.log_out_go:
path: /cas/logout
options:
_auth: [ 'basic_auth' ]
defaults:
_controller: '\Drupal\casost\Controller\CASLogout::logoutGo'
requirements:
_user_is_logged_in: 'TRUE'
services:
logger.channel.cas:
parent: 'logger.channel_base'
arguments: ['epal']
<?php
/**
* @file
* Contains casost_config.page.inc.
*
* Page callback for CASOST Config entities.
*/
use Drupal\Core\Render\Element;
/**
* Prepares variables for CASOST Config templates.
*
* Default template: casost_config.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_casost_config(array &$variables) {
// Fetch CASOSTConfig Entity Object.
$casost_config = $variables['elements']['#casost_config'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
<?php
/**
* @file
* Contains casost_session.page.inc.
*
* Page callback for CASOST Session entities.
*/
use Drupal\Core\Render\Element;
/**
* Prepares variables for CASOST Session templates.
*
* Default template: casost_session.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_casost_session(array &$variables) {
// Fetch CASOSTSession Entity Object.
$casost_session = $variables['elements']['#casost_session'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
{
"name": "drupal/casost",
"type": "drupal-module",
"description": "Authentication Provider OST",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/casost",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/casost",
"source": "http://cgit.drupalcode.org/casost"
},
"require": { }
}
<?php
namespace Drupal\casost;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Access controller for the CASOST Config entity.
*
* @see \Drupal\casost\Entity\CASOSTConfig.
*/
class CASOSTConfigAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\casost\Entity\CASOSTConfigInterface $entity */
switch ($operation) {
case 'view':
if (!$entity->isPublished()) {
return AccessResult::allowedIfHasPermission($account, 'view unpublished casost config entities');
}
return AccessResult::allowedIfHasPermission($account, 'view published casost config entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit casost config entities');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete casost config entities');
}
// Unknown operation, no opinion.
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add casost config entities');
}
}
<?php
namespace Drupal\casost;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for CASOST Config entities.
*
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class CASOSTConfigHtmlRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
$entity_type_id = $entity_type->id();
if ($collection_route = $this->getCollectionRoute($entity_type)) {
$collection->add("entity.{$entity_type_id}.collection", $collection_route);
}
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
$collection->add("$entity_type_id.settings", $settings_form_route);
}
return $collection;
}
/**
* Gets the collection route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getCollectionRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('collection'));
$route
->setDefaults([
'_entity_list' => $entity_type_id,
'_title' => "{$entity_type->getLabel()} list",
])
->setRequirement('_permission', 'access casost config overview')
->setOption('_admin_route', TRUE);
return $route;
}
}
/**
* Gets the settings form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
if (!$entity_type->getBundleEntityType()) {
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
$route
->setDefaults([
'_form' => 'Drupal\casost\Form\CASOSTConfigSettingsForm',
'_title' => "{$entity_type->getLabel()} settings",
])
->setRequirement('_permission', $entity_type->getAdminPermission())
->setOption('_admin_route', TRUE);
return $route;
}
}
}
<?php
namespace Drupal\casost;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Routing\LinkGeneratorTrait;
use Drupal\Core\Url;
/**
* Defines a class to build a listing of CASOST Config entities.
*
* @ingroup casost
*/
class CASOSTConfigListBuilder extends EntityListBuilder {
use LinkGeneratorTrait;
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['id'] = $this->t('CASOST Config ID');
$header['name'] = $this->t('Name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var $entity \Drupal\casost\Entity\CASOSTConfig */
$row['id'] = $entity->id();
$row['name'] = $this->l(
$entity->label(),
new Url(
'entity.casost_config.edit_form', array(
'casost_config' => $entity->id(),
)
)
);
return $row + parent::buildRow($entity);
}
}
<?php
namespace Drupal\casost;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Access controller for the CASOST Session entity.
*
* @see \Drupal\casost\Entity\CASOSTSession.
*/
class CASOSTSessionAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\casost\Entity\CASOSTSessionInterface $entity */
switch ($operation) {
case 'view':
if (!$entity->isPublished()) {
return AccessResult::allowedIfHasPermission($account, 'view unpublished casost session entities');
}
return AccessResult::allowedIfHasPermission($account, 'view published casost session entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit casost session entities');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete casost session entities');
}
// Unknown operation, no opinion.
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add casost session entities');
}
}
<?php
namespace Drupal\casost;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for CASOST Session entities.
*
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class CASOSTSessionHtmlRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
$entity_type_id = $entity_type->id();
if ($collection_route = $this->getCollectionRoute($entity_type)) {
$collection->add("entity.{$entity_type_id}.collection", $collection_route);
}
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
$collection->add("$entity_type_id.settings", $settings_form_route);
}
return $collection;
}
/**
* Gets the collection route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getCollectionRoute(EntityTypeInterface $entity_type) {
if ($entity_type->hasLinkTemplate('collection') && $entity_type->hasListBuilderClass()) {
$entity_type_id = $entity_type->id();
$route = new Route($entity_type->getLinkTemplate('collection'));
$route
->setDefaults([
'_entity_list' => $entity_type_id,
'_title' => "{$entity_type->getLabel()} list",
])
->setRequirement('_permission', 'access casost session overview')
->setOption('_admin_route', TRUE);
return $route;
}
}
/**
* Gets the settings form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
if (!$entity_type->getBundleEntityType()) {
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
$route
->setDefaults([
'_form' => 'Drupal\casost\Form\CASOSTSessionSettingsForm',
'_title' => "{$entity_type->getLabel()} settings",
])
->setRequirement('_permission', $entity_type->getAdminPermission())
->setOption('_admin_route', TRUE);
return $route;
}
}
}
<?php
namespace Drupal\casost;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Routing\LinkGeneratorTrait;
use Drupal\Core\Url;
/**
* Defines a class to build a listing of CASOST Session entities.
*
* @ingroup casost
*/
class CASOSTSessionListBuilder extends EntityListBuilder {
use LinkGeneratorTrait;