Skip to content

Commit 0a73af3

Browse files
gitBalazs Dianiska
authored andcommitted
Issue #2514338 by malik.kotob: Prelogin hook to provide opportunity for custom authorization
1 parent 63f8709 commit 0a73af3

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

simplesamlphp_auth.api.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,23 @@ function hook_simplesamlphp_auth_allow_login($attributes) {
5050
return TRUE;
5151
}
5252
}
53+
54+
/**
55+
* Allows other modules to perform an additional authentication step prior
56+
* to logging in given the set of attributes and user object.
57+
*
58+
* Each implementation should take care of displaying errors or redirecting
59+
* to appropriate error pages, there is no message implementation at hook
60+
* invocation.
61+
*
62+
* @param $attributes
63+
* @param $ext_user
64+
* The user object for the current user
65+
*/
66+
function hook_simplesamlphp_auth_pre_login($attributes, $ext_user) {
67+
// Disallow students from logging in with a specific role.
68+
if ($ext_user['roles'] == '3' && (in_array('student', $attributes))) {
69+
drupal_goto('some-error-page-path');
70+
exit();
71+
}
72+
}

simplesamlphp_auth.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ function _simplesaml_auth_login_register() {
4646
}
4747
}
4848

49+
// Provides opportunity to perform additional prelogin authentication.
50+
$attributes = simplesamlphp_auth_get_attributes();
51+
foreach (module_implements('simplesamlphp_auth_pre_login') as $module) {
52+
module_invoke($module, 'simplesamlphp_auth_pre_login', $attributes, $ext_user);
53+
}
54+
4955
// Log the user in.
5056
_simplesaml_auth_user_login($ext_user);
5157

0 commit comments

Comments
 (0)