Skip to content

Commit da6f589

Browse files
DMaesterBalazs Dianiska
authored andcommitted
Issue #2074641 by brad.bulger, DMaester: configurable logging levels
1 parent aa52c56 commit da6f589

File tree

4 files changed

+73
-31
lines changed

4 files changed

+73
-31
lines changed

simplesamlphp_auth.admin.inc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@ function simplesamlphp_auth_settings_basic() {
4848
'#default_value' => variable_get('simplesamlphp_auth_login_path', 'saml_login'),
4949
'#description' => t('Path for logging into SAML - Do not include proceeding slash.'),
5050
);
51-
51+
$form['simplesamlphp_auth_grp_debug'] = array(
52+
'#type' => 'fieldset',
53+
'#title' => t('Debugging'),
54+
'#collapsible' => FALSE,
55+
'#collapsed' => FALSE,
56+
);
57+
$form['simplesamlphp_auth_grp_debug']['simplesamlphp_auth_debug'] = array(
58+
'#type' => 'checkbox',
59+
'#title' => t('Turn on debugging messages'),
60+
'#default_value' => variable_get('simplesamlphp_auth_debug', FALSE),
61+
'#description' => t('Expand the level of watchdog messages logged to include debugging information'),
62+
);
5263
$form['simplesamlphp_auth_grp_reg'] = array(
5364
'#type' => 'fieldset',
5465
'#title' => t('User Provisioning'),

simplesamlphp_auth.inc

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ function _simplesaml_auth_login_register() {
2020
// Get unique identifier from saml attributes.
2121
$authname = _simplesamlphp_auth_get_authname();
2222

23-
watchdog('simplesamlphp_auth', 'Authname is [%authname] userid is [%uid]', array(
24-
'%authname' => $authname,
25-
'%uid' => $user->uid,
26-
), WATCHDOG_DEBUG);
27-
23+
if (variable_get('simplesamlphp_auth_debug', 0)) {
24+
watchdog('simplesamlphp_auth', 'Authname is [%authname] userid is [%uid]', array(
25+
'%authname' => $authname,
26+
'%uid' => $user->uid,
27+
), WATCHDOG_DEBUG);
28+
}
2829
if (!empty($authname)) {
2930
// User is logged in with SAML authentication and we got the unique
3031
// identifier, so try to log into Drupal.
31-
watchdog('simplesamlphp_auth', 'Loading Drupal user [%authname]', array('%authname' => $authname), WATCHDOG_DEBUG);
32+
if (variable_get('simplesamlphp_auth_debug', 0)) {
33+
watchdog('simplesamlphp_auth', 'Loading Drupal user [%authname]', array('%authname' => $authname), WATCHDOG_DEBUG);
34+
}
3235

3336
// Retrieve user mapping and attempt to log the user in.
3437
$ext_user = user_external_load($authname);
@@ -92,16 +95,20 @@ function _simplesaml_auth_user_register($authname) {
9295
if (variable_get('simplesamlphp_auth_registerusers', TRUE)) {
9396

9497
// We are allowed to register new users.
95-
watchdog('simplesamlphp_auth', 'Register [%authname]', array('%authname' => $authname), WATCHDOG_DEBUG);
98+
if (variable_get('simplesamlphp_auth_debug', 0)) {
99+
watchdog('simplesamlphp_auth', 'Register [%authname]', array('%authname' => $authname), WATCHDOG_DEBUG);
100+
}
96101

97102
// It's possible that a user with this name already exists, but is not
98103
// permitted to login to Drupal via SAML. If so, log out of SAML and
99104
// redirect to the front page.
100105
$account = user_load_by_name($authname);
101106
if ($account) {
102-
watchdog('simplesamlphp_auth', 'User [%authname] could not be registered because that username already exists and is not SAML enabled.', array(
103-
'%authname' => $authname,
104-
), WATCHDOG_DEBUG);
107+
if (variable_get('simplesamlphp_auth_debug', 0)) {
108+
watchdog('simplesamlphp_auth', 'User [%authname] could not be registered because that username already exists and is not SAML enabled.', array(
109+
'%authname' => $authname,
110+
), WATCHDOG_DEBUG);
111+
}
105112

106113
drupal_set_message(t('We are sorry, your user account is not SAML enabled.'));
107114
$_simplesamlphp_auth_as->logout(base_path());
@@ -112,10 +119,12 @@ function _simplesaml_auth_user_register($authname) {
112119
// Register the new user.
113120
user_external_login_register($authname, 'simplesamlphp_auth');
114121

115-
watchdog('simplesamlphp_auth', 'Registered [%authname] with uid @uid', array(
116-
'%authname' => $authname,
117-
'@uid' => $user->uid,
118-
), WATCHDOG_DEBUG);
122+
if (variable_get('simplesamlphp_auth_debug', 0)) {
123+
watchdog('simplesamlphp_auth', 'Registered [%authname] with uid @uid', array(
124+
'%authname' => $authname,
125+
'@uid' => $user->uid,
126+
), WATCHDOG_DEBUG);
127+
}
119128

120129
if (!empty($user->uid)) {
121130
// Populate roles based on configuration setting.
@@ -149,7 +158,9 @@ function _simplesaml_auth_user_register($authname) {
149158
* The user account object to update.
150159
*/
151160
function _simplesaml_auth_user_update($account) {
152-
watchdog('simplesamlphp_auth', 'Updating username [%acctname]', array('%acctname' => $account->name), WATCHDOG_DEBUG);
161+
if (variable_get('simplesamlphp_auth_debug', 0)) {
162+
watchdog('simplesamlphp_auth', 'Updating username [%acctname]', array('%acctname' => $account->name), WATCHDOG_DEBUG);
163+
}
153164

154165
db_update('users')
155166
->fields(array('name' => $account->name))
@@ -165,7 +176,9 @@ function _simplesaml_auth_user_update($account) {
165176
watchdog('simplesamlphp_auth', $e->getMessage(), NULL, WATCHDOG_CRITICAL);
166177
}
167178

168-
watchdog('simplesamlphp_auth', 'Updating mail [%mailaddr]', array('%mailaddr' => $mail_address), WATCHDOG_DEBUG);
179+
if (variable_get('simplesamlphp_auth_debug', 0)) {
180+
watchdog('simplesamlphp_auth', 'Updating mail [%mailaddr]', array('%mailaddr' => $mail_address), WATCHDOG_DEBUG);
181+
}
169182

170183
if (!empty($mail_address)) {
171184
db_update('users')
@@ -190,7 +203,9 @@ function _simplesaml_auth_user_login($ext_user) {
190203
// See if we're supposed to re-evaluate role assignments.
191204
if (variable_get('simplesamlphp_auth_roleevaleverytime', 0)) {
192205
// Populate roles based on configuration setting.
193-
watchdog('simplesamlphp_auth', 'User already registered [%authname] updating roles.', array('%authname' => $ext_user->name), WATCHDOG_DEBUG);
206+
if (variable_get('simplesamlphp_auth_debug', 0)) {
207+
watchdog('simplesamlphp_auth', 'User already registered [%authname] updating roles.', array('%authname' => $ext_user->name), WATCHDOG_DEBUG);
208+
}
194209
$roles = _simplesamlphp_auth_rolepopulation(variable_get('simplesamlphp_auth_rolepopulation', ''));
195210
$userinfo = array('roles' => $roles);
196211

simplesamlphp_auth.install

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function simplesamlphp_auth_uninstall() {
3838
variable_del('simplesamlphp_auth_authsource');
3939
variable_del('simplesamlphp_auth_rolepopulation');
4040
variable_del('simplesamlphp_auth_roleevaleverytime');
41+
variable_del('simplesamlphp_auth_debug');
4142
variable_del('simplesamlphp_auth_registerusers');
4243
variable_del('simplesamlphp_auth_allowsetdrupalpwd');
4344
variable_del('simplesamlphp_auth_allowdefaultlogin');

simplesamlphp_auth.module

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ function simplesamlphp_auth_user_insert(&$edit, $account, $category = NULL) {
199199
if ($_simplesamlphp_auth_as->isAuthenticated() && _simplesamlphp_auth_get_authname() == $account->init) {
200200
// Get name from default attributes.
201201
try {
202-
watchdog('simplesamlphp_auth', 'Registering user [%acctname]', array('%acctname' => $account->name), WATCHDOG_DEBUG);
202+
if (variable_get('simplesamlphp_auth_debug', 0)) {
203+
watchdog('simplesamlphp_auth', 'Registering user [%acctname]', array('%acctname' => $account->name), WATCHDOG_DEBUG);
204+
}
203205
$account->name = _simplesamlphp_auth_get_default_name($account->uid);
204206
}
205207
catch (Exception $e) {
@@ -438,7 +440,9 @@ function _simplesamlphp_auth_get_authname() {
438440

439441
// Check if valid local session exists.
440442
if (isset($_simplesamlphp_auth_saml_attributes)) {
441-
watchdog('simplesamlphp_auth', '_simplesamlphp_auth_get_authname: Valid local SAML session exists', NULL, WATCHDOG_DEBUG);
443+
if (variable_get('simplesamlphp_auth_debug', 0)) {
444+
watchdog('simplesamlphp_auth', '_simplesamlphp_auth_get_authname: Valid local SAML session exists', NULL, WATCHDOG_DEBUG);
445+
}
442446
if (isset($_simplesamlphp_auth_saml_attributes[variable_get('simplesamlphp_auth_unique_id', 'eduPersonPrincipalName')])) {
443447
$authname = $_simplesamlphp_auth_saml_attributes[variable_get('simplesamlphp_auth_unique_id', 'eduPersonPrincipalName')][0];
444448
}
@@ -551,11 +555,13 @@ function _simplesamlphp_auth_generate_block_text() {
551555
* An array containing role value and the attribute, or FALSE.
552556
*/
553557
function _simplesamlphp_auth_evaulaterolerule($roleruleevaluation, $attributes) {
554-
watchdog('simplesamlphp_auth', 'Evaluate rule (key=%key,operator=%op,value=%val)', array(
555-
'%key' => $roleruleevaluation[0],
556-
'%op' => $roleruleevaluation[1],
557-
'%val' => $roleruleevaluation[2],
558-
), WATCHDOG_DEBUG);
558+
if (variable_get('simplesamlphp_auth_debug', 0)) {
559+
watchdog('simplesamlphp_auth', 'Evaluate rule (key=%key,operator=%op,value=%val)', array(
560+
'%key' => $roleruleevaluation[0],
561+
'%op' => $roleruleevaluation[1],
562+
'%val' => $roleruleevaluation[2],
563+
), WATCHDOG_DEBUG);
564+
}
559565

560566
if (!array_key_exists($roleruleevaluation[0], $attributes)) {
561567
return FALSE;
@@ -601,19 +607,24 @@ function _simplesamlphp_auth_rolepopulation($rolemap) {
601607
global $_simplesamlphp_auth_saml_attributes;
602608
$roles = array();
603609

604-
watchdog('simplesamlphp_auth', 'Rolemap: %rolemap', array('%rolemap' => $rolemap), WATCHDOG_DEBUG);
610+
if (variable_get('simplesamlphp_auth_debug', 0)) {
611+
watchdog('simplesamlphp_auth', 'Rolemap: %rolemap', array('%rolemap' => $rolemap), WATCHDOG_DEBUG);
612+
}
605613

606614
// Check if valid local session exists..
607615
if (!empty($rolemap) && $_simplesamlphp_auth_as->isAuthenticated()) {
608616
$attributes = $_simplesamlphp_auth_saml_attributes;
609617

610-
watchdog('simplesamlphp_auth', 'Evaluate rolemap: %rolemap', array('%rolemap' => $rolemap), WATCHDOG_DEBUG);
618+
if (variable_get('simplesamlphp_auth_debug', 0)) {
619+
watchdog('simplesamlphp_auth', 'Evaluate rolemap: %rolemap', array('%rolemap' => $rolemap), WATCHDOG_DEBUG);
620+
}
611621

612622
$rolerules = explode('|', $rolemap);
613623

614624
foreach ($rolerules as $rolerule) {
615-
watchdog('simplesamlphp_auth', 'Evaluate role rule: %rolerule', array('%rolerule' => $rolerule), WATCHDOG_DEBUG);
616-
625+
if (variable_get('simplesamlphp_auth_debug', 0)) {
626+
watchdog('simplesamlphp_auth', 'Evaluate role rule: %rolerule', array('%rolerule' => $rolerule), WATCHDOG_DEBUG);
627+
}
617628
$roleruledecompose = explode(':', $rolerule, 2);
618629

619630
$roleid = $roleruledecompose[0];
@@ -622,7 +633,9 @@ function _simplesamlphp_auth_rolepopulation($rolemap) {
622633
$addnew = TRUE;
623634
foreach ($roleruleevaluations as $roleruleevaluation) {
624635

625-
watchdog('simplesamlphp_auth', 'Evaluate role evaulation: %roleruleeval', array('%roleruleeval' => $roleruleevaluation), WATCHDOG_DEBUG);
636+
if (variable_get('simplesamlphp_auth_debug', 0)) {
637+
watchdog('simplesamlphp_auth', 'Evaluate role evaulation: %roleruleeval', array('%roleruleeval' => $roleruleevaluation), WATCHDOG_DEBUG);
638+
}
626639

627640
$roleruleevaluationdc = str_getcsv($roleruleevaluation);
628641
if (!_simplesamlphp_auth_evaulaterolerule($roleruleevaluationdc, $attributes)) {
@@ -631,7 +644,9 @@ function _simplesamlphp_auth_rolepopulation($rolemap) {
631644
}
632645
if ($addnew) {
633646
$roles[$roleid] = $roleid;
634-
watchdog('simplesamlphp_auth', 'Add new role: %roleid', array('%roleid' => $roleid), WATCHDOG_DEBUG);
647+
if (variable_get('simplesamlphp_auth_debug', 0)) {
648+
watchdog('simplesamlphp_auth', 'Add new role: %roleid', array('%roleid' => $roleid), WATCHDOG_DEBUG);
649+
}
635650
}
636651

637652
}

0 commit comments

Comments
 (0)