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

CAS authentification method #313

Open
wants to merge 1 commit 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
7 changes: 7 additions & 0 deletions application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@
$config['oauth2_client_id'] = '';
$config['oauth2_client_secret'] = '';

//____________________________________________________________________________
//CAS configuration
$config['cas_enabled'] = FALSE;
$config['cas_host'] = "";
$config['cas_port'] = 443;
$config['cas_folder'] = "";

//____________________________________________________________________________
//SAML configuration
$config['saml_enabled'] = FALSE;
Expand Down
44 changes: 43 additions & 1 deletion application/controllers/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function login() {
if ($this->config->item('saml_enabled') === TRUE) {
redirect('api/sso');
}
//The login form is not used with CAS authentication mode
if ($this->config->item('cas_enabled') === TRUE) {
redirect('api/cas');
}
//If we are already connected (login bookmarked), then redirect to home
if ($this->session->userdata('logged_in') === TRUE) {
redirect('home');
Expand Down Expand Up @@ -184,7 +188,20 @@ public function login() {
*/
public function logout() {
$this->session->sess_destroy();
redirect('session/login');

if ($this->config->item('cas_enabled') === TRUE) {
// Init Client CAS
@\phpCAS::client("2.0", $this->config->item('cas_host'), $this->config->item('cas_port'), $this->config->item('cas_folder'), false);
@\phpCAS::setNoCasServerValidation();


// Logout
$url=$this->config->item('base_url')."/session/login";
@\phpCAS::logout(array("service"=>$url));
}
else {
redirect('session/login');
}
}

/**
Expand Down Expand Up @@ -448,4 +465,29 @@ public function acs() {
}
}

/**
* CAS SSO endpoint that starts the login via SSO
* @author arnaud FORNEROT <[email protected]>
*/
public function cas() {
// Init Client CAS
@\phpCAS::client("2.0", $this->config->item('cas_host'), $this->config->item('cas_port'), $this->config->item('cas_folder'), false);
@\phpCAS::setNoCasServerValidation();

// Authentification
@\phpCAS::forceAuthentication();

// Récupération UID
$user = @\phpCAS::getUser();

// Authentification dans Jorani
$this->load->model('users_model');
$loggedin = $this->users_model->checkCredentialsLDAP($user);
if ($loggedin === TRUE) {
$this->redirectToLastPage();
}
else {
echo "<div style='font-family:Helvetica; text-align:center; margin-top:50px'>Votre compte n'existe pas dans Jorani<br>Vous devez demander à un administrateur de créer votre compte si vous souhaitez y accèder.</div>";
}
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"respect/validation": "^1.1.31",
"onelogin/php-saml": "^3.4.1",
"zircote/swagger-php": "^3.0.1",
"phpmailer/phpmailer": "^6.1.8"
"phpmailer/phpmailer": "^6.1.8",
"jasig/phpcas": "^1.3"
},
"require-dev": {
"guzzlehttp/guzzle": "^6.3.3",
Expand Down
Loading