Skip to content

Commit c9fb0c1

Browse files
committed
Issue #1912426 by colan: Started adding public functions.
1 parent 0c76785 commit c9fb0c1

File tree

1 file changed

+73
-1
lines changed

1 file changed

+73
-1
lines changed

simplesamlphp_auth.module

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,9 @@ function simplesamlphp_auth_block_info() {
649649
return $block;
650650
}
651651

652-
// Helper functions --------------------------------------
652+
/****************************************************************************
653+
* Private functions ********************************************************
654+
****************************************************************************/
653655

654656
/**
655657
* Checks to see if authentication via SimpleSAMLphp should be activated
@@ -944,3 +946,73 @@ function _simplesamlphp_auth_destroy_drupal_session() {
944946

945947
drupal_goto();
946948
}
949+
950+
/****************************************************************************
951+
* Public functions *********************************************************
952+
****************************************************************************/
953+
954+
/**
955+
* Determine if the current user is authenticated through SAML.
956+
*
957+
* @return
958+
* TRUE if the current user is authenticated through SAML. FALSE otherwise.
959+
*/
960+
function simplesamlphp_auth_is_authenticated() {
961+
global $_simplesamlphp_auth_as;
962+
963+
// Assume that the user isn't authenticated until proven otherwise.
964+
$authenticated = FALSE;
965+
966+
// If the associated global variable exists, and the auth flag is set, note it.
967+
if (isset($_simplesamlphp_auth_as) && $_simplesamlphp_auth_as->isAuthenticated()) {
968+
$authenticated = TRUE;
969+
}
970+
971+
// Return the result.
972+
return $authenticated;
973+
}
974+
975+
/**
976+
* Return any attributes provided by the SAML IDP.
977+
*
978+
* @param $attribute
979+
* The attribute whose value to return. Can be skipped if all attribute
980+
* values are requested.
981+
*
982+
* @return
983+
* If an attribute was provided, the value of the attribute is returned.
984+
* Otherwise, an array of all attribute values is returned, keyed by
985+
* attribute.
986+
*/
987+
function simplesamlphp_auth_get_attributes($attribute = NULL) {
988+
global $_simplesamlphp_auth_saml_attributes;
989+
990+
if (isset($attribute)) {
991+
992+
// Initially, assume that there's nothing to return.
993+
$result = NULL;
994+
995+
// If the specified attribute is set, grab it.
996+
if (isset($_simplesamlphp_auth_saml_attributes)) {
997+
if (isset($_simplesamlphp_auth_saml_attributes[$attribute])) {
998+
$result = $_simplesamlphp_auth_saml_attributes[$attribute];
999+
}
1000+
}
1001+
}
1002+
1003+
// No specific attribute was requested; return all of them.
1004+
else {
1005+
1006+
// Initially, assume that there's nothing to return.
1007+
$result = array();
1008+
1009+
// If the global array exists, return it.
1010+
if (isset($_simplesamlphp_auth_saml_attributes)) {
1011+
$result = $_simplesamlphp_auth_saml_attributes;
1012+
}
1013+
}
1014+
1015+
// Return whatever we've got.`
1016+
return $result;
1017+
}
1018+

0 commit comments

Comments
 (0)