Fakultas Ilmu Komputer UI

Commit 4de8aba0 authored by Muhammad Indra Ramadhan's avatar Muhammad Indra Ramadhan
Browse files

Merge branch 'sso-integration' into 'master'

SSO Integration

See merge request !1
parents ac40be99 bde8dac3
......@@ -2,3 +2,5 @@
/adminer*.php
/editor*.php
/vendor/
/adminer/include/config.php
.volume_db/
\ No newline at end of file
FROM php:7.1.5-apache
RUN apt-get update && apt-get install -y libpq-dev && docker-php-ext-install pdo pdo_pgsql
#set our application folder as an environment variable
ENV APP_HOME /var/www/html
#change uid and gid of apache to docker user uid/gid
RUN usermod -u 1000 www-data && groupmod -g 1000 www-data
# enable apache module rewrite
RUN a2enmod rewrite
#copy source files and run composer
COPY . $APP_HOME
#change ownership of our applications
RUN chown -R www-data:www-data $APP_HOME
\ No newline at end of file
......@@ -48,6 +48,26 @@ function check_invalid_login() {
}
}
$prod = isset($_ENV["PRODUCTION"]);
if ($prod) {
$vendor = $_ENV["VENDOR"];
$server = $_ENV["SERVER"];
$username = $_ENV["USERNAME"];
$password = $_ENV["PASSWORD"];
}
if ($_SESSION["db"][$vendor][$server][$username][$db] == false) {
$_POST["auth"] = [
"driver" => $vendor,
"server" => $server,
"username" => $username,
"password" => $password,
"db" => ""
];
} else if (!isset($_GET["username"]) || !isset($_GET["pgsql"])) {
redirect(auth_url($vendor, $server, $username, ""));
}
$auth = $_POST["auth"];
if ($auth) {
session_regenerate_id(); // defense against session fixation
......
......@@ -55,7 +55,7 @@ if (!defined("SID")) {
$params[] = true; // HttpOnly
}
call_user_func_array('session_set_cookie_params', $params); // ini_set() may be disabled
session_start();
// session_start();
}
// disable magic quotes to be able to use database escaping function
......
<?php
$vendor = "pgsql";
$server = "localhost";
$username = "root";
$password = "root";
$base_url = "http://localhost:3000/adminer";
\ No newline at end of file
......@@ -180,12 +180,9 @@ function page_footer($missing = "") {
<?php switch_lang(); ?>
<?php if ($missing != "auth") { ?>
<form action="" method="post">
<p class="logout">
<input type="submit" name="logout" value="<?php echo lang('Logout'); ?>" id="logout">
<input type="hidden" name="token" value="<?php echo $token; ?>">
<a href="/adminer/sso-logout.php"><?php echo lang('Logout'); ?></a>
</p>
</form>
<?php } ?>
<div id="menu">
<?php $adminer->navigation($missing); ?>
......
......@@ -557,7 +557,7 @@ function cookie($name, $value, $lifetime = 2592000) { // 2592000 - 30 days
*/
function restart_session() {
if (!ini_bool("session.use_cookies")) {
session_start();
// session_start();
}
}
......@@ -570,7 +570,7 @@ function stop_session($force = false) {
if (!$use_cookies || $force) {
session_write_close(); // improves concurrency if a user opens several pages at once, may be restarted later
if ($use_cookies && @ini_set("session.use_cookies", false) === false) { // @ - may be disabled
session_start();
// session_start();
}
}
}
......
......@@ -7,6 +7,19 @@
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
*/
session_start();
require "./vendor/SSO/SSO.php";
$cas_path = "./vendor/phpCAS-1.3.6/CAS.php";
SSO\SSO::setCASPath($cas_path);
include "./sso-login.php";
$prod = isset($_ENV["PRODUCTION"]);
if (!$prod) {
include "./include/config.php";
}
include "./include/bootstrap.inc.php";
include "./include/tmpfile.inc.php";
......
<?php
SSO\SSO::authenticate();
$user = SSO\SSO::getUser();
\ No newline at end of file
<?php
require "./vendor/SSO/SSO.php";
$cas_path = "./vendor/phpCAS-1.3.6/CAS.php";
SSO\SSO::setCASPath($cas_path);
$prod = isset($_ENV["PRODUCTION"]);
if ($prod) {
$base_url = $_ENV["BASE_URL"];
} else {
include "./include/config.php";
}
SSO\SSO::logout($base_url);
<?php
/**
* SSO - Utility library for authentication with SSO-UI
*
* @author Bobby Priambodo <bobby.priambodo@gmail.com>
* @copyright 2015 Bobby Priambodo
* @license MIT
* @package SSO
*
* MIT LICENSE
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace SSO;
use phpCAS;
// ------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------
/**
* CAS server host address
*/
define('CAS_SERVER_HOST', 'sso.ui.ac.id');
/**
* CAS server uri
*/
define('CAS_SERVER_URI', '/cas2');
/**
* CAS server port
*/
define('CAS_SERVER_PORT', 443);
// ------------------------------------------------------------------------
// CAS Initialization
// ------------------------------------------------------------------------
// ONLY DO THIS IF phpCAS EXISTS (i.e. installing via Composer). Thanks to Fariskhi for noticing the bug.
if (class_exists('phpCAS')) {
/**
* Create phpCAS client
*/
phpCAS::client(CAS_VERSION_2_0, CAS_SERVER_HOST, CAS_SERVER_PORT, CAS_SERVER_URI);
/**
* Set no validation.
*/
phpCAS::setNoCasServerValidation();
}
/**
* The SSO class is a simple phpCAS interface for authenticating using
* SSO-UI CAS service.
*
* @class SSO
* @category Authentication
* @package SSO
* @author Bobby Priambodo <bobby.priambodo@gmail.com>
* @license MIT
*/
class SSO
{
/**
* Authenticate the user.
*
* @return bool Authentication
*/
public static function authenticate() {
return phpCAS::forceAuthentication();
}
/**
* Check if the user is already authenticated.
*
* @return bool Authentication
*/
public static function check() {
return phpCAS::checkAuthentication();
}
/**
* Logout from SSO with URL redirection options
*/
public static function logout($url='') {
if ($url === '')
phpCAS::logout();
else
phpCAS::logout(['url' => $url]);
}
/**
* Returns the authenticated user.
*
* @return Object User
*/
public static function getUser() {
$details = phpCAS::getAttributes();
// Create new user object, initially empty.
$user = new \stdClass();
$user->username = phpCAS::getUser();
$user->name = $details['nama'];
$user->role = $details['peran_user'];
if ($user->role === 'mahasiswa') {
$user->npm = $details['npm'];
$user->org_code = $details['kd_org'];
$data = json_decode(file_get_contents( __DIR__ . '/additional-info.json'), true)[$user->org_code];
$user->faculty = $data['faculty'];
$user->study_program = $data['study_program'];
$user->educational_program = $data['educational_program'];
}
else if ($user->role === 'staff') {
$user->nip = $details['nip'];
}
return $user;
}
// ----------------------------------------------------------
// Manual Installation Stuff
// ----------------------------------------------------------
/**
* Sets the path to CAS.php. Use only when not installing via Composer.
*
* @param string $cas_path Path to CAS.php
*/
public static function setCASPath($cas_path) {
require $cas_path;
// Initialize CAS client.
self::init();
}
/**
* Initialize CAS client. Called by setCASPath().
*/
private static function init() {
// Create CAS client.
phpCAS::client(CAS_VERSION_2_0, CAS_SERVER_HOST, CAS_SERVER_PORT, CAS_SERVER_URI);
// Set no validation.
phpCAS::setNoCasServerValidation();
}
}
\ No newline at end of file
{
"04.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Pendidikan Dokter (Medical Science)",
"educational_program":"S1 Reguler (Undergraduate Program)"
},
"05.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Pendidikan Dokter Kelas Khusus Internasional (Medical Science)",
"educational_program":"S1 Kls Internasional (Intl. Class Undergraduate Program)"
},
"07.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Biomedik (Biomedical Sciences)",
"educational_program":"S2 (Graduate Program)"
},
"08.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Gizi (Nutrition)",
"educational_program":"S2 (Graduate Program)"
},
"09.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Kedokteran Kerja (Occupational Medicine)",
"educational_program":"S2 (Graduate Program)"
},
"40.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Pendidikan Kedokteran (Medical Education)",
"educational_program":"S2 (Graduate Program)"
},
"10.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Biomedik (Biomedical Sciences)",
"educational_program":"S3 (Doctoral Program)"
},
"11.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Gizi (Nutrition)",
"educational_program":"S3 (Doctoral Program)"
},
"12.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Kedokteran (Medical Science)",
"educational_program":"S3 (Doctoral Program)"
},
"01.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Perumahsakitan (Hospital Management)",
"educational_program":"D3 (Diploma III)"
},
"02.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Rehabilitasi Medik ()",
"educational_program":"D3 (Diploma III)"
},
"37.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Fisioterapi (Physiotherapy)",
"educational_program":"D3 (Diploma III)"
},
"38.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Okupasi Terapi (Occupational Therapy)",
"educational_program":"D3 (Diploma III)"
},
"06.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Profesi Dokter (Medical Doctor)",
"educational_program":"Profesi (Profession Program)"
},
"13.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Anestesiologi (Anesthesiology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"14.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Bedah (Surgery)",
"educational_program":"Spesialis I (Specialist Program)"
},
"15.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Penyakit Dalam (Internal Medicine)",
"educational_program":"Spesialis I (Specialist Program)"
},
"16.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Kesehatan Anak (Pediatrics)",
"educational_program":"Spesialis I (Specialist Program)"
},
"17.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Obstetri & Ginekologi (Obstetrics & Gynecology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"18.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Penyakit Saraf (Neurology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"19.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Kedokteran Jiwa (Psychiatry)",
"educational_program":"Spesialis I (Specialist Program)"
},
"20.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Kesehatan Mata (Ophthalmology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"21.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Kesehatan Kulit & Kelamin (Dermato & Venereology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"22.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Penyakit Telinga, Hidung & Tenggorok (Otorhinolaryngology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"23.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Penyakit Jantung & Pembuluh Darah (Cardiovascular Medicine)",
"educational_program":"Spesialis I (Specialist Program)"
},
"24.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Pulmonologi dan Ilmu Kedokteran Respirasi (Respiratory)",
"educational_program":"Spesialis I (Specialist Program)"
},
"25.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Radiologi (Radiology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"26.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Kedokteran Forensik (Forensic Medicine)",
"educational_program":"Spesialis I (Specialist Program)"
},
"27.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Patologi Anatomik (Anatomical Pathology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"28.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Patologi Klinik (Clinical Pathology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"29.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Orthopaedi dan Traumatologi (Orthopaedic and Traumatology Surgery)",
"educational_program":"Spesialis I (Specialist Program)"
},
"30.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Urologi (Urology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"31.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Bedah Syaraf (Neurosurgery)",
"educational_program":"Spesialis I (Specialist Program)"
},
"32.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Rehabilitasi Medik (Medical Rehabilitation)",
"educational_program":"Spesialis I (Specialist Program)"
},
"33.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Bedah Plastik (Plastic Surgery)",
"educational_program":"Spesialis I (Specialist Program)"
},
"34.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Kedokteran Olahraga (Sports Medicine)",
"educational_program":"Spesialis I (Specialist Program)"
},
"35.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Mikrobiologi Klinik (Clinical Microbiology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"36.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Farmakologi Klinik (Clinical Pharmacology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"39.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Kedokteran Okupasi (Occupational Medicine)",
"educational_program":"Spesialis I (Specialist Program)"
},
"41.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Bedah Torak Kardiovaskular (Cardiovascular and Thoracic Surgery)",
"educational_program":"Spesialis I (Specialist Program)"
},
"43.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Onkologi Radiasi (Radiation Oncology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"44.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Kedokteran Penerbangan (Aviation Medicine)",
"educational_program":"Spesialis I (Specialist Program)"
},
"45.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Gizi Klinik (Clinical Nutrition)",
"educational_program":"Spesialis I (Specialist Program)"
},
"46.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Parasitologi Klinik (Clinical Parasitology)",
"educational_program":"Spesialis I (Specialist Program)"
},
"47.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Akupuntur Medik (Acupuncture Medic)",
"educational_program":"Spesialis I (Specialist Program)"
},
"03.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Gizi ()",
"educational_program":"D4 (Diploma IV)"
},
"48.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Penyakit Dalam (Internal Medicine)",
"educational_program":"Spesialis 2 (Sub Specialist Program)"
},
"50.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Kesehatan Anak (Pediatrics)",
"educational_program":"Spesialis 2 (Sub Specialist Program)"
},
"51.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Bedah (Surgery)",
"educational_program":"Spesialis 2 (Sub Specialist Program)"
},
"52.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Obstetri & Ginekologi (Obstetrics & Gynecology)",
"educational_program":"Spesialis 2 (Sub Specialist Program)"
},
"53.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Ilmu Kedokteran Jiwa (Psychiatry)",
"educational_program":"Spesialis 2 (Sub Specialist Program)"
},
"54.00.01.01":{
"faculty":"KEDOKTERAN",
"study_program":"Anestesiologi & Terapi Intensif (Anesthesiology & Intensive Therapy)",
"educational_program":"Spesialis 2 (Sub Specialist Program)"
},
"01.00.02.01":{
"faculty":"KEDOKTERAN GIGI",
"study_program":"Pendidikan Dokter Gigi (Dental Education)",
"educational_program":"S1 Reguler (Undergraduate Program)"
},
"03.00.02.01":{
"faculty":"KEDOKTERAN GIGI",
"study_program":"Ilmu Kedokteran Gigi Dasar (Basic Dental Science)",
"educational_program":"S2 (Graduate Program)"
},
"04.00.02.01":{
"faculty":"KEDOKTERAN GIGI",
"study_program":"Ilmu Kedokteran Gigi Komunitas (Community Dental Science)",
"educational_program":"S2 (Graduate Program)"
},
"05.00.02.01":{
"faculty":"KEDOKTERAN GIGI",
"study_program":"Ilmu Kedokteran Gigi (Dental Science)",
"educational_program":"S3 (Doctoral Program)"
},
"02.00.02.01":{
"faculty":"KEDOKTERAN GIGI",
"study_program":"Kedokteran Gigi (Dentistry)",
"educational_program":"Profesi (Profession Program)"
},
"06.00.02.01":{
"faculty":"KEDOKTERAN GIGI",
"study_program":"Ilmu Bedah Mulut (Oral & Maxillo Facial Surgery)",
"educational_program":"Spesialis I (Specialist Program)"
},
"07.00.02.