Cicalese has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/348986 )

Change subject: Added optional error message to authenticate().
......................................................................


Added optional error message to authenticate().

Bumped version number to synchronize with PluggaleAuth and OpenIDConnect
extensions.

Change-Id: Ib9539d177147b9cfbc7ee533dc3939d1f2e41298
---
M SimpleSAMLphp.class.php
M extension.json
2 files changed, 54 insertions(+), 24 deletions(-)

Approvals:
  Cicalese: Verified; Looks good to me, approved



diff --git a/SimpleSAMLphp.class.php b/SimpleSAMLphp.class.php
index 05664fd..2b87420 100644
--- a/SimpleSAMLphp.class.php
+++ b/SimpleSAMLphp.class.php
@@ -32,11 +32,18 @@
         * @param &$username
         * @param &$realname
         * @param &$email
+        * @param &$errorMessage
         */
-       public function authenticate( &$id, &$username, &$realname, &$email ) {
+       public function authenticate( &$id, &$username, &$realname, &$email,
+               &$errorMessage ) {
 
                $saml = $this->getSAMLClient();
-               $saml->requireAuth();
+               try {
+                       $saml->requireAuth();
+               } catch ( Exception $e ) {
+                       $errorMessage = $e->getMessage();
+                       return false;
+               }
                $attributes = $saml->getAttributes();
 
                if ( isset( $GLOBALS['wgSimpleSAMLphp_RealNameAttribute'] ) ) {
@@ -50,6 +57,8 @@
                                                }
                                                $realname .= 
$attributes[$attribute][0];
                                        } else {
+                                               wfDebug( 'SimpleSAMLphp: Could 
not find real name attribute ' .
+                                                       $attribute );
                                                return false;
                                        }
                                }
@@ -57,36 +66,52 @@
                                if ( array_key_exists( $realNameAttribute, 
$attributes ) ) {
                                        $realname = 
$attributes[$realNameAttribute][0];
                                } else {
+                                       wfDebug( 'SimpleSAMLphp: Could not find 
real name attribute ' .
+                                               $attributes );
                                        return false;
                                }
                        }
                } else {
+                       wfDebug( 'SimpleSAMLphp: 
$wgSimpleSAMLphp_RealNameAttribute is not set' );
                        return false;
                }
 
-               if ( isset( $GLOBALS['wgSimpleSAMLphp_EmailAttribute'] ) &&
-                       array_key_exists( 
$GLOBALS['wgSimpleSAMLphp_EmailAttribute'],
+               if ( isset( $GLOBALS['wgSimpleSAMLphp_EmailAttribute'] ) ) {
+                       if ( array_key_exists( 
$GLOBALS['wgSimpleSAMLphp_EmailAttribute'],
                                $attributes ) ) {
-                       $email = 
$attributes[$GLOBALS['wgSimpleSAMLphp_EmailAttribute']][0];
-               } else {
-                       return false;
-               }
-
-               if ( isset( $GLOBALS['wgSimpleSAMLphp_UsernameAttribute'] ) &&
-                       array_key_exists( 
$GLOBALS['wgSimpleSAMLphp_UsernameAttribute'],
-                       $attributes ) ) {
-                       $username = strtolower(
-                               
$attributes[$GLOBALS['wgSimpleSAMLphp_UsernameAttribute']][0] );
-                       $nt = Title::makeTitleSafe( NS_USER, $username );
-                       if ( is_null( $nt ) ) {
+                               $email = 
$attributes[$GLOBALS['wgSimpleSAMLphp_EmailAttribute']][0];
+                       } else {
+                               wfDebug( 'SimpleSAMLphp: Could not find email 
attribute ' .
+                                       $attributes );
                                return false;
                        }
-                       $username = $nt->getText();
-                       $id = User::idFromName( $username );
-                       return true;
+               } else {
+                       wfDebug( 'SimpleSAMLphp: 
$wgSimpleSAMLphp_EmailAttribute is not set' );
+                       return false;
                }
 
-               return false;
+               if ( isset( $GLOBALS['wgSimpleSAMLphp_UsernameAttribute'] ) ) {
+                       if ( array_key_exists( 
$GLOBALS['wgSimpleSAMLphp_UsernameAttribute'],
+                               $attributes ) ) {
+                               $username = strtolower(
+                                       
$attributes[$GLOBALS['wgSimpleSAMLphp_UsernameAttribute']][0] );
+                               $nt = Title::makeTitleSafe( NS_USER, $username 
);
+                               if ( is_null( $nt ) ) {
+                                       return false;
+                               }
+                               $username = $nt->getText();
+                               $id = User::idFromName( $username );
+                       } else {
+                               wfDebug( 'SimpleSAMLphp: Could not find 
username attribute ' .
+                                       $attributes );
+                               return false;
+                       }
+               } else {
+                       wfDebug( 'SimpleSAMLphp: 
$wgSimpleSAMLphp_UsernameAttribute is not set' );
+                       return false;
+               }
+
+               return true;
        }
 
        /**
@@ -121,7 +146,7 @@
 
        private function getSAMLClient() {
                require_once rtrim( $GLOBALS['wgSimpleSAMLphp_InstallDir'],
-                       DIRECTORY_SEPARATOR ) .  DIRECTORY_SEPARATOR . 'lib' .
+                       DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR . 'lib' .
                        DIRECTORY_SEPARATOR . '_autoload.php';
                return new SimpleSAML_Auth_Simple(
                        $GLOBALS['wgSimpleSAMLphp_AuthSourceId'] );
diff --git a/extension.json b/extension.json
index 6a9f601..e7b1923 100644
--- a/extension.json
+++ b/extension.json
@@ -1,12 +1,17 @@
 {
        "name": "SimpleSAMLphp",
-       "version": "2.1",
+       "version": "4.0",
        "author": [
                "[https://www.mediawiki.org/wiki/User:Cindy.cicalese Cindy 
Cicalese]"
        ],
        "url": "https://www.mediawiki.org/wiki/Extension:SimpleSAMLphp";,
        "descriptionmsg": "simplesamlphp-desc",
        "type": "other",
+       "requires": {
+               "extensions": {
+                       "PluggableAuth": ">= 4.0"
+               }
+       },
        "MessagesDirs": {
                "SimpleSAMLphp": [
                        "i18n"
@@ -15,8 +20,8 @@
        "AutoloadClasses": {
                "SimpleSAMLphp": "SimpleSAMLphp.class.php"
        },
-       "manifest_version": 1,
        "config": {
                "PluggableAuth_Class": "SimpleSAMLphp"
-       }
+       },
+       "manifest_version": 1
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/348986
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib9539d177147b9cfbc7ee533dc3939d1f2e41298
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/SimpleSAMLphp
Gerrit-Branch: master
Gerrit-Owner: Cicalese <cical...@mitre.org>
Gerrit-Reviewer: Cicalese <cical...@mitre.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to