Skip to content

Commit

Permalink
Getting config only one time (cache it)
Browse files Browse the repository at this point in the history
  • Loading branch information
xaionaro committed Oct 7, 2016
1 parent 3c6b939 commit 3b9821b
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions cas_authn/cas_authn.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class cas_authn extends rcube_plugin {

private $cas_inited;
private $_cache_cfg = null;

/**
* Initialize plugin
Expand All @@ -46,8 +47,20 @@ function init() {
$this->add_hook('template_object_loginform', array($this, 'add_cas_login_html'));
}

/**
* Gets config and caches
*
* @return array configuration array
*/
function getCfg() {
if (is_null($_cache_cfg)) {
$_cache_cfg = rcmail::get_instance()->config->all();
}
return $_cache_cfg;
}

function isDisabled() {
$cfg = rcmail::get_instance()->config->all();
$cfg = $this->getCfg();
if (is_array($cfg['cas_disable_for_domains'])) {
foreach ($cfg['cas_disable_for_domains'] as $domain_pattern) {
if (preg_match($domain_pattern, $_SERVER['SERVER_NAME'])) {
Expand Down Expand Up @@ -122,7 +135,7 @@ function startup($args) {
$user = phpCAS::getUser();
$pass = '';
// retrieve credentials, either a Proxy Ticket or 'masteruser' password
$cfg = rcmail::get_instance()->config->all();
$cfg = $this->getCfg();
if ($cfg['cas_proxy']) {
$_SESSION['cas_pt'][php_uname('n')] = phpCAS::retrievePT($cfg['cas_imap_name'], $err_code, $output);
$pass = $_SESSION['cas_pt'][php_uname('n')];
Expand Down Expand Up @@ -175,7 +188,7 @@ function startup($args) {
*/
function imap_connect($args) {
// retrieve configuration
$cfg = rcmail::get_instance()->config->all();
$cfg = $this->getCfg();

// RoundCube is acting as CAS proxy
if ($cfg['cas_proxy']) {
Expand Down Expand Up @@ -237,7 +250,7 @@ function imap_connect($args) {
*/
function smtp_connect($args) {
// retrieve configuration
$cfg = rcmail::get_instance()->config->all();
$cfg = $this->getCfg();

// RoundCube is acting as CAS proxy and performing SMTP authn
if ($cfg['cas_proxy'] && $args['smtp_user'] && $args['smtp_pass']) {
Expand Down Expand Up @@ -267,7 +280,7 @@ function smtp_connect($args) {
*/
function sieverules_connect($args) {
// retrieve configuration
$cfg = rcmail::get_instance()->config->all();
$cfg = $this->getCfg();

// RoundCube is acting as CAS proxy
if ($cfg['opt_cas_proxy']) {
Expand All @@ -293,7 +306,7 @@ function add_cas_login_html($args) {
$RCMAIL = rcmail::get_instance();
$this->add_texts('localization');
// retrieve configuration
$cfg = rcmail::get_instance()->config->all();
$cfg = $this->getCfg();

// Force CAS authn?
if($cfg["cas_force"]) {
Expand Down Expand Up @@ -329,7 +342,7 @@ private function cas_init() {
session_destroy();
}

$cfg = rcmail::get_instance()->config->all();
$cfg = $this->getCfg();

// include phpCAS
require_once('CAS.php');
Expand Down Expand Up @@ -420,7 +433,7 @@ private function generate_url($params) {
$delm = '&';
}
}
$cfg = rcmail::get_instance()->config->all();
$cfg = $this->getCfg();
if ( $cfg['cas_webmail_server_name'] ) {
$serverName = $cfg['cas_webmail_server_name'];
} else {
Expand Down

0 comments on commit 3b9821b

Please sign in to comment.