[MediaWiki-commits] [Gerrit] mediawiki...GoogleLogin[master]: Move E-Mail host parsing to it's own class
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/358080 ) Change subject: Move E-Mail host parsing to it's own class .. Move E-Mail host parsing to it's own class This decouples the methods used for parsing an e-mail address to get the host part of it from the GoogleLogin class into it's own EmailDomain class. In the future, it will be easier to change e.g. how the caching is currently implemented. Change-Id: Ib0c7eea6b42773d0d0a154598b2ddb804ca2ffe4 --- M extension.json M includes/GoogleLogin.body.php A includes/alloweddomains/EmailDomain.php M includes/auth/GooglePrimaryAuthenticationProvider.php 4 files changed, 179 insertions(+), 136 deletions(-) Approvals: Florianschmidtwelzow: Looks good to me, approved jenkins-bot: Verified diff --git a/extension.json b/extension.json index 7cab228..4a835cd 100644 --- a/extension.json +++ b/extension.json @@ -54,6 +54,7 @@ "GoogleLogin\\Auth\\GoogleAuthenticationRequest": "includes/auth/GoogleAuthenticationRequest.php", "GoogleLogin\\Auth\\GoogleRemoveAuthenticationRequest": "includes/auth/GoogleRemoveAuthenticationRequest.php", "GoogleLogin\\Auth\\GoogleUserInfoAuthenticationRequest": "includes/auth/GoogleUserInfoAuthenticationRequest.php", + "GoogleLogin\\AllowedDomains\\EmailDomain": "includes/alloweddomains/EmailDomain.php", "ApiGoogleLoginInfo": "includes/api/ApiGoogleLoginInfo.php" }, "AuthManagerAutoConfig": { diff --git a/includes/GoogleLogin.body.php b/includes/GoogleLogin.body.php index 2e8e4e2..534e6f1 100755 --- a/includes/GoogleLogin.body.php +++ b/includes/GoogleLogin.body.php @@ -5,14 +5,13 @@ use ConfigFactory; use Google_Client; +use GoogleLogin\AllowedDomains\EmailDomain; class GoogleLogin { /** @var $mGoogleClient Stores an instance of GoogleClient */ private static $mGoogleClient; /** @var $mConfig Config object created for GoogleLogin extension */ private static $mConfig; - /** @var $mHost The Host of E-Mail provided by Google */ - private static $mHost; /** * Returns an prepared instance of Google client to do requests with to Google API @@ -53,9 +52,10 @@ public static function isValidDomain( $mailDomain ) { $glConfig = self::getGLConfig(); if ( is_array( $glConfig->get( 'GLAllowedDomains' ) ) ) { + $domain = new EmailDomain( $mailDomain, $glConfig->get( 'GLAllowedDomainsStrict' ) ); if ( in_array( - self::getHost( $mailDomain ), + $domain->getHost(), $glConfig->get( 'GLAllowedDomains' ) ) ) { @@ -64,132 +64,5 @@ return false; } return true; - } - - /** -* Returns the domain and tld (without subdomains) of the provided E-Mailadress -* @param string $domain The domain part of the email address to extract from. -* @return string The Tld and domain of $domain without subdomains -* @see http://www.programmierer-forum.de/domainnamen-ermitteln-t244185.htm -*/ - public static function getHost( $domain = '' ) { - $glConfig = self::getGLConfig(); - if ( !empty( self::$mHost ) ) { - return self::$mHost; - } - $dir = __DIR__ . "/.."; - if ( $glConfig->get( 'GLAllowedDomainsStrict' ) ) { - $domain = explode( '@', $domain ); - // we can trust google to give us only valid email address, so give the last element - self::$mHost = array_pop( $domain ); - return self::$mHost; - } - // for parse_url() - $domain = - !isset( $domain[5] ) || - ( - $domain[3] != ':' && - $domain[4] != ':' && - $domain[5] != ':' - ) ? 'http://' . $domain : $domain; - // remove "/path/file.html", "/:80", etc. - $domain = parse_url( $domain, PHP_URL_HOST ); - // separate domain level - $lvl = explode( '.', $domain ); // 0 => www, 1 => example, 2 => co, 3 => uk - // set levels - krsort( $lvl ); // 3 => uk, 2 => co, 1 => example, 0 => www - $lvl = array_values( $lvl ); // 0 => uk, 1 => co, 2 => example, 3 => www - $_1st = $lvl[0]; - $_2nd = isset( $lvl[1] ) ? $lvl[1] . '.' . $_1st : false; -
[MediaWiki-commits] [Gerrit] mediawiki...GoogleLogin[master]: Move E-Mail host parsing to it's own class
Florianschmidtwelzow has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/358080 ) Change subject: Move E-Mail host parsing to it's own class .. Move E-Mail host parsing to it's own class This decouples the methods used for parsing an e-mail address to get the host part of it from the GoogleLogin class into it's own EmailDomain class. In the future, it will be easier to change e.g. how the caching is currently implemented. Change-Id: Ib0c7eea6b42773d0d0a154598b2ddb804ca2ffe4 --- M extension.json M includes/GoogleLogin.body.php A includes/alloweddomains/EmailDomain.php M includes/auth/GooglePrimaryAuthenticationProvider.php 4 files changed, 180 insertions(+), 136 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GoogleLogin refs/changes/80/358080/1 diff --git a/extension.json b/extension.json index 7cab228..5a0349e 100644 --- a/extension.json +++ b/extension.json @@ -54,6 +54,8 @@ "GoogleLogin\\Auth\\GoogleAuthenticationRequest": "includes/auth/GoogleAuthenticationRequest.php", "GoogleLogin\\Auth\\GoogleRemoveAuthenticationRequest": "includes/auth/GoogleRemoveAuthenticationRequest.php", "GoogleLogin\\Auth\\GoogleUserInfoAuthenticationRequest": "includes/auth/GoogleUserInfoAuthenticationRequest.php", + "GoogleLogin\\AllowedDomains\\AllowedDomainsStore": "includes/alloweddomains/AllowedDomainsStore.php", + "GoogleLogin\\AllowedDomains\\EmailDomain": "includes/alloweddomains/EmailDomain.php", "ApiGoogleLoginInfo": "includes/api/ApiGoogleLoginInfo.php" }, "AuthManagerAutoConfig": { diff --git a/includes/GoogleLogin.body.php b/includes/GoogleLogin.body.php index 2e8e4e2..534e6f1 100755 --- a/includes/GoogleLogin.body.php +++ b/includes/GoogleLogin.body.php @@ -5,14 +5,13 @@ use ConfigFactory; use Google_Client; +use GoogleLogin\AllowedDomains\EmailDomain; class GoogleLogin { /** @var $mGoogleClient Stores an instance of GoogleClient */ private static $mGoogleClient; /** @var $mConfig Config object created for GoogleLogin extension */ private static $mConfig; - /** @var $mHost The Host of E-Mail provided by Google */ - private static $mHost; /** * Returns an prepared instance of Google client to do requests with to Google API @@ -53,9 +52,10 @@ public static function isValidDomain( $mailDomain ) { $glConfig = self::getGLConfig(); if ( is_array( $glConfig->get( 'GLAllowedDomains' ) ) ) { + $domain = new EmailDomain( $mailDomain, $glConfig->get( 'GLAllowedDomainsStrict' ) ); if ( in_array( - self::getHost( $mailDomain ), + $domain->getHost(), $glConfig->get( 'GLAllowedDomains' ) ) ) { @@ -64,132 +64,5 @@ return false; } return true; - } - - /** -* Returns the domain and tld (without subdomains) of the provided E-Mailadress -* @param string $domain The domain part of the email address to extract from. -* @return string The Tld and domain of $domain without subdomains -* @see http://www.programmierer-forum.de/domainnamen-ermitteln-t244185.htm -*/ - public static function getHost( $domain = '' ) { - $glConfig = self::getGLConfig(); - if ( !empty( self::$mHost ) ) { - return self::$mHost; - } - $dir = __DIR__ . "/.."; - if ( $glConfig->get( 'GLAllowedDomainsStrict' ) ) { - $domain = explode( '@', $domain ); - // we can trust google to give us only valid email address, so give the last element - self::$mHost = array_pop( $domain ); - return self::$mHost; - } - // for parse_url() - $domain = - !isset( $domain[5] ) || - ( - $domain[3] != ':' && - $domain[4] != ':' && - $domain[5] != ':' - ) ? 'http://' . $domain : $domain; - // remove "/path/file.html", "/:80", etc. - $domain = parse_url( $domain, PHP_URL_HOST ); - // separate domain level - $lvl = explode( '.', $domain ); // 0 => www, 1 => example, 2 => co, 3 => uk - // set levels - krsort( $lvl ); // 3 => uk, 2 => co, 1 => example, 0 => www - $lvl = array_values( $lvl ); // 0 => uk, 1 => co, 2 => exa