Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keycloak support 2021 09 29 #342

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ php_myemsl.ini
*.local
application/config/production/*
application/config/development/*
application/third_party/*
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: php
php:
- "5.6"
- "7.1"
install:
- composer require squizlabs/php_codesniffer:2.9.1
- composer require squizlabs/php_codesniffer
- composer require codeclimate/php-test-reporter --dev
- phpenv rehash
script: bash -xe test-everything.sh
9 changes: 5 additions & 4 deletions application/config/pacifica.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
$cart_port = getenv('CART_PORT');
$cart_dl_port = getenv('CART_DOWNLOAD_PORT');
$site_theme_name = getenv('SITE_THEME');
// $site_theme_name = 'external';
// $site_theme_name = 'myemsl';

$files_dl_port = getenv('FILE_DOWNLOAD_PORT');

Expand All @@ -45,7 +43,6 @@
$config['site_slogan'] = 'EMSL User Portal Data Retrieval';
$config['ui_instrument_desc'] = 'Select an Instrument';
$config['ui_project_desc'] = 'Select a Project';
// $config['main_overview_template'] = "external_view.html";
} elseif ($site_theme_name == 'myemsl') {
$config['theme_name'] = 'myemsl';
$config['site_identifier'] = "MyEMSL";
Expand All @@ -60,7 +57,7 @@
$config['ui_project_desc'] = 'Select a Project';
}

$config['application_version'] = "2.7.5";
$config['application_version'] = "2.8.0";

$config['cookie_encryption_key'] = "eus_rocks_2019!!!";
$config['cookie_name'] = "EUS_ID";
Expand All @@ -69,3 +66,7 @@
$config['enable_single_file_download'] = false;
$config['enable_require_credentials_for_cart_download'] = false;
$config['nexus_backend_url'] = "https://nexus-dev-srv.emsl.pnl.gov";
$config['nexus_portal_url'] = "https://nexus-dev.emsl.pnl.gov/Portal";
$config['cart_data_url'] = "/get_active_cart_information_by_user_id";
$config['cart_data_add_url'] = "/add_new_cart_tracking_information";
$config['cart_deactivate_url'] = "/deactivate_cart_by_cart_uuid";
4 changes: 2 additions & 2 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,14 @@
$route['view/(:any)'] = "status_api/view/$1";
$route['released_data'] = "status_api/overview";
$route['released_data/(:any)'] = "status_api/view/$1";
$route['view/t/(:any)'] = "status_api/view/$1";
$route['view/j/(:any)'] = "status_api/view/$1";
$route['overview'] = "status_api/overview";
$route['data_release'] = "status_api/data_release";
$route['data_release/(:num)'] = "status_api/data_release_single_item/$1";
$route['doi_minting'] = "status_api/doi_minting";
$route['update_local_records/(:num)'] = "ajax_api/save_transient_doi_details/$1";
$route['file_tree'] = "status_api/get_lazy_load_folder";
$route['cart_listing'] = "cart_api/listing";
$route['api/checkauth'] = "cart_api/check_download_authorization/1";
$route['cart/checkauth'] = "cart_api/check_download_authorization";
$route['cart/delete/(:any)/(:any)'] = "cart_api/delete/$1/$2";
$route['cart/(:any)/(:any)'] = "cart_api/$1/$2";
Expand Down
8 changes: 5 additions & 3 deletions application/controllers/Ajax_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ class Ajax_api extends Baseline_api_controller
*/
public function __construct()
{

parent::__construct();
$this->load->model('status_api_model', 'status');
$this->load->model('Myemsl_api_model', 'myemsl');
$this->load->helper('network');
$this->load->library('PHPRequests');
$this->user_relationships = [];
Expand Down Expand Up @@ -150,7 +148,11 @@ public function set_release_state($transaction_id, $release_state)
$this->user_relationships = get_relationship_list();
}
$transaction_info = $this->status->get_transaction_details($transaction_id);
$associated_projects_list = array_map('strval', array_keys($this->user_info['projects']));
$associated_project_list = [];
foreach ($this->user_info['projects'] as $project_entry) {
$associated_projects_list[] = $project_entry['id'];
}
//$associated_projects_list = array_map('strval', array_keys($this->user_info['projects']));
if (!in_array($transaction_info['project'], $associated_projects_list)) {
//user is not authorized to release this transaction
$this->output->set_status_header(403, "You are not authorized to release transaction {$transaction_id}");
Expand Down
24 changes: 13 additions & 11 deletions application/controllers/Baseline_api_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* @link http://github.com/EMSL-MSC/pacifica-upload-status
*/

ini_set("default_socket_timeout", 30);

class Baseline_api_controller extends CI_Controller
{
Expand All @@ -40,6 +39,7 @@ public function __construct()
{
parent::__construct();
//get user info
ini_set("default_socket_timeout", 30);
date_default_timezone_set($this->config->item('local_timezone'));
$this->load->model('System_setup_model', 'setup');
$this->load->helper(
Expand All @@ -55,39 +55,41 @@ public function __construct()
$this->ingester_url_base = str_replace('tcp:', 'http:', getenv('INGESTER_PORT') ?: 'http://127.0.0.1:8066');
$this->file_url_base = $this->config->item('external_file_url');
$this->cart_url_base = $this->config->item('external_cart_url');
$this->drhub_url_base = $this->config->item('drhub_url_base');
$this->user_id = get_user();
$user_info = get_user();
if ($user_info) {
$this->user_id = $user_info["user_id"];
}
$this->ingester_messages = $this->config->item('ingest_status_messages');
$this->git_hash = get_current_git_hash();
$this->application_version = $this->config->item('application_version');
$this->page_address = implode('/', $this->uri->rsegments);

$this->benchmark->mark('get_user_details_start');
$user_info = get_user_details($this->user_id);
$this->username = $user_info['first_name'] ?: 'Anonymous Stranger';
$this->is_emsl_staff = $user_info['emsl_employee'] == 'Y' ? true : false;
$this->email = $user_info['email_address'];
$this->fullname = "{$this->username} {$user_info['last_name']}";
$user_info['full_name'] = $this->fullname;
$this->email = $user_info['email_address'] ?: "";
$this->project_list = $user_info['projects'] ?: [];
$this->fullname = $user_info["simple_display_name"] ?: 'Anonymous Stranger';
$user_info['full_name'] = $this->fullname ;
$user_info['network_id'] = !empty($user_info['network_id']) ? $user_info['network_id'] : '';
$this->user_info = $user_info;

if (isset($_SERVER['PATH_INFO'])) {
$current_path_info = ltrim($_SERVER['PATH_INFO'], '/');
} else {
$current_path_info = './';
}

$this->nav_info['current_page_info']['logged_in_user'] = "{$this->fullname}";
$this->nav_info['current_page_info']['logged_in_user_id'] = $user_info['network_id'] ?: "";
$this->benchmark->mark('get_user_details_end');
$this->nav_info['current_page_info']['logged_in_user_id']
= $user_info['network_id'] ?: $user_info["email_address"] ?: "";

$this->page_data = array();
$this->page_data['nexus_auth_redirect'] = $this->config->item('nexus_portal_url');
$this->page_data['navData'] = $this->nav_info;
$this->page_data['infoData'] = array(
'current_credentials' => $this->user_id,
'full_name' => $this->fullname
);
$this->page_data['project_list'] = $this->project_list;
$this->page_data['username'] = $this->username;
$this->page_data['fullname'] = $this->fullname;
$this->page_data['load_prototype'] = false;
Expand Down
3 changes: 2 additions & 1 deletion application/controllers/Baseline_user_api_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
* @link http://github.com/EMSL-MSC/pacifica-upload-status
*/
require_once 'Baseline_api_controller.php';
require_once 'Baseline_api_controller.php';

/**
* Status API is a CI Controller class that extends Baseline_controller.
Expand Down Expand Up @@ -67,6 +67,7 @@ public function __construct()
$this->page_data['script_uris'] = array(
'/resources/scripts/spinner/spin.min.js',
'/resources/scripts/fancytree/dist/jquery.fancytree-all.js',
'/resources/scripts/fancytree/dist/modules/jquery.fancytree.persist.js',
'/resources/scripts/jquery-crypt/jquery.crypt.js',
'/resources/scripts/select2-4/dist/js/select2.js',
'/resources/scripts/bootstrap-daterangepicker/daterangepicker.js'
Expand Down
51 changes: 28 additions & 23 deletions application/controllers/Cart_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct()
{
parent::__construct();
$this->load->model('Cart_api_model', 'cart');
$this->load->helper(array('url', 'network', 'item', 'myemsl_api'));
$this->load->helper(array('url', 'network', 'item', 'user', 'myemsl_api'));
$this->eus_cookie_name = $this->config->item('cookie_name');
$this->eus_login_redirect_url = $this->config->item('cookie_redirect_url');
$this->eus_cookie_encryption_key = $this->config->item('cookie_encryption_key');
Expand All @@ -57,10 +57,11 @@ public function __construct()
*
* @author Ken Auberry <[email protected]>
*/
public function listing($cart_owner_identifier)
public function listing()
{
$accept = $this->input->get_request_header('Accept');
$cart_list = $this->cart->cart_status($cart_owner_identifier);
// $accept = $this->input->get_request_header('Accept');
log_message('info', "IN cart_api/listing");
$cart_list = $this->cart->cart_status();
if (stristr(strtolower($accept), 'json')) {
//looks like a json request
transmit_array_with_json_header($cart_list);
Expand Down Expand Up @@ -89,16 +90,17 @@ public function create($cart_owner_identifier)
echo "That's not how you use this function!!!";
exit();
}
// Check to make sure the auth cookie is set, and make sure that the encoded value is opcache_invalidate
// Check to make sure the auth cookie is set, and make sure that the encoded value is ok
// How are we making use of this information? Does it go somewhere in the database?
if ($this->config->item('enable_require_credentials_for_cart_download')) {
$user_block = $this->check_download_authorization(false);
$user_id = $user_block['eus_id'];
if ($user_id) {
$user_info = get_user_details_simple($user_id);
} else {
$this->output->set_status_header(302, "Unknown EUS User");
print("");
if (!$this->user_id || $this->user_id == 0) {
$this->output->set_status_header(403, "Unknown EUS User");
$response = [
'message' => 'No Credentials found for this user'
];
transmit_array_with_json_header($response);
return;
}
}
Expand All @@ -109,7 +111,9 @@ public function create($cart_owner_identifier)
echo "Hey! There's no real data here!";
}
// var_dump($this->input->request_headers());
$cart_uuid_info = $this->cart->cart_create($cart_owner_identifier, $this->input->raw_input_stream);
$cart_local_uuid = guidv4();
$cart_uuid_info = $this->cart->cart_create($cart_local_uuid, $this->input->raw_input_stream);
log_message('info', json_encode($cart_uuid_info));
transmit_array_with_json_header($cart_uuid_info);
}

Expand All @@ -120,26 +124,27 @@ public function create($cart_owner_identifier)
*
* @author Ken Auberry <[email protected]>
*/
public function check_download_authorization($show_output = true)
public function check_download_authorization($show_output = false)
{
$retval = [
"redirect_url" => $this->eus_login_redirect_url,
"eus_id" => null
];
// $this->user_id = false;
if (!$this->config->item('enable_require_credentials_for_cart_download')) {
$retval['eus_id'] = 0;
} else if (!$this->config->item('enable_cookie_redirect')) {
if (array_key_exists('OIDC_access_token', $_SERVER)) {
$retval = get_user_details($_SERVER["REMOTE_USER"]);
$retval['eus_id'] = $this->user_id;
$retval = array_merge($retval, $this->user_info);
} else if (!$this->config->item('enable_require_credentials_for_cart_download')) {
$retval['eus_id'] = 0;
} else {
$eus_user_info = get_user_from_cookie();
if ($eus_user_info) {
$this->user_info = $eus_user_info;
$retval = array_merge($retval, $eus_user_info);
}
$retval['eus_id'] = 0;
}
// echo strpos(uri_string(), 'cart/checkauth');
if (strpos(uri_string(), 'cart/checkauth') !== false) {
// if (substr(uri_string(), 0, 5) == 'cart/checkauth') {
$new_loc = $_SERVER['QUERY_STRING'];
$new_loc = str_replace('redirectUri=', "", $new_loc);
// $new_loc = str_replace($_SERVER["REQUEST_SCHEME"]."://", "", $new_loc);
// $new_loc = str_replace($_SERVER["SERVER_NAME"]."/", "", $new_loc);
redirect($new_loc);
}
if ($show_output) {
$this->output->set_content_type('application/json');
Expand Down
4 changes: 0 additions & 4 deletions application/controllers/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
* @link http://github.com/EMSL-MSC/pacifica-upload-status
*/

if (!is_cli()) {
exit('No URL-based access allowed');
}

/**
* System_setup is an access class for managing initial system setup from the CLI
*
Expand Down
Loading