@@ -649,7 +649,9 @@ function simplesamlphp_auth_block_info() {
649
649
return $block;
650
650
}
651
651
652
- // Helper functions --------------------------------------
652
+ /****************************************************************************
653
+ * Private functions ********************************************************
654
+ ****************************************************************************/
653
655
654
656
/**
655
657
* Checks to see if authentication via SimpleSAMLphp should be activated
@@ -944,3 +946,73 @@ function _simplesamlphp_auth_destroy_drupal_session() {
944
946
945
947
drupal_goto();
946
948
}
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