Skip to content

Commit

Permalink
updating guard to test
Browse files Browse the repository at this point in the history
  • Loading branch information
tuehoang committed Nov 19, 2024
1 parent 0d1dd3e commit e67d5db
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Boxfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ web1:
php_display_errors: "0"
after_build:
- "mv app/config/database.pagoda.php app/config/database.php"
- "mv app/plugins/guard/config/guard_default.php app/config/guard.php"
- "mv app/config/guard-override.php app/config/guard.php"
cron:
- "*/15 * * * *": "cake/console/cake send_emails"
db1:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM php:8.0-fpm
FROM php:8.3-fpm

RUN apt-get update && apt-get install --no-install-recommends --no-install-suggests -y \
libpng-dev \
Expand Down
104 changes: 104 additions & 0 deletions app/config/guard-override.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

//$config['Guard.AuthModule.Name'] = 'Ldap'; // Using LDAP module
//$config['Guard.AuthModule.Name'] = 'Shibboleth'; // Using Shibboleth module
//$config['Guard.AuthModule.Name'] = getenv('IPEER_AUTH') ? getenv('IPEER_AUTH') : 'Default'; // Using default (build-in) module

$config['Guard.AuthModule.Name'] = 'Default';

$config['Guard.AuthModule.Default'] = array();
$config['Guard.AuthModule.Shibboleth'] = array(
'sessionInitiatorURL' => 'https://%HOST%/Shibboleth.sso/Login',
'logoutURL' => 'https://%HOST%/Shibboleth.sso/Logout',
'fieldMapping' => array(
'eppn' => 'username',
'affiliation' => 'role',
),
'mappingRules' => array(
'eppn' => array('/@ubc.ca/' => ''),
'affiliation' => array('/[email protected]/' => 'admin'),
),
'loginError' => 'You have successfully logged in through Shibboleth. But you do not have access this appliction.',
'loginImageButton' => '',
'loginTextButton' => 'Login',
);

$config['Guard.AuthModule.Ldap'] = array(
'host' => 'ldaps://ldap.school.ca/',
'port' => 636,
'serviceUsername' => 'uid=USERNAME, ou=Special Users, o=school.ca', // username to connect to LDAP
'servicePassword' => 'PASSWORD', // password to connect to LDAP
'baseDn' => 'ou=Campus Login, o=school.ca',
'usernameField' => 'uid',
'attributeSearchFilters' => array(
// 'uid',
),
'attributeMap' => array(
// 'username' => 'uid',
),
'fallbackInternal' => true,
);

$config['Guard.AuthModule.Cwl'] = array(
'sessionInitiatorURL' => 'https://www.auth.cwl.ubc.ca/auth/login',
'applicationID' => 'ServiceName',
'applicationPassword' => 'ServicePassword',
'fieldMapping' => array(
'eppn' => 'username',
'affiliation' => 'role',
),
'mappingRules' => array(
'eppn' => array('/@ubc.ca/' => ''),
'affiliation' => array('/[email protected]/' => 'admin'),
),
'loginError' => 'You have successfully logged in. But you do not have access this appliction.',
'loginImageButton' => '',
'loginTextButton' => 'Login',
// CWL XML-RPC interface URLs: https://www.auth.verf.cwl.ubc.ca/auth/rpc (for verification)
// https://www.auth.cwl.ubc.ca/auth/rpc
'RPCURL' => "https://www.auth.cwl.ubc.ca",
'RPCPath' => "/auth/rpc",

/**
* the name of the function being called through XML-RPC. this is
* prepended with 'session.' later
*/
//$CWLFunctionName => 'getLoginName',
'functionName' => 'getIdentities',

/**
* the application's ID/name and password as given by the CWL team
*/
'applicationID' => '',
'applicationPassword' => '',
);

function override_from_env(&$config) {
$prefix = 'IPEER_AUTH_'.strtoupper($config['Guard.AuthModule.Name']).'_';
$auth_config = &$config['Guard.AuthModule.' . $config['Guard.AuthModule.Name']];
foreach($_ENV as $k => $v) {
if (0 === strpos($k, $prefix)) {
$key_str = substr($k, strlen($prefix)-strlen($k));
$keys = explode('_', $key_str);
$step = &$auth_config;
foreach($keys as $i => $key) {
if (!array_key_exists($key, $step)) {
$step[$key] = ($i == count($keys) - 1) ? $v : array();
}elseif (array_key_exists($key, $step) && $i == count($keys) - 1) {
if (is_bool($step[$key])) {
$step[$key] = filter_var($v, FILTER_VALIDATE_BOOLEAN);
} elseif (is_int($step[$key])) {
$step[$key] = filter_var($v, FILTER_VALIDATE_INT);
} elseif (is_array($step[$key])) {
$step[$key] = json_decode($v, true);
} else {
$step[$key] = $v;
}
}
$step = &$step[$key];
}
}
}
}

override_from_env($config);

0 comments on commit e67d5db

Please sign in to comment.