[MediaWiki-commits] [Gerrit] mediawiki...OpenStackManager[master]: Add maintenance script for attaching existing LDAP accounts

2017-12-14 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/394510 )

Change subject: Add maintenance script for attaching existing LDAP accounts
..


Add maintenance script for attaching existing LDAP accounts

The attachLdapUser.php maintenance script can be used to attach an
existing LDAP account to the local wiki. In addition to creating the
user table entries, it will also add the expected user creation log
events.

Bug: T174469
Bug: T180813
Change-Id: Id7aa131c64fc0a7df934ebcbc56d367e996b8355
---
A maintenance/attachLdapUser.php
1 file changed, 64 insertions(+), 0 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/attachLdapUser.php b/maintenance/attachLdapUser.php
new file mode 100644
index 000..d4cd49a
--- /dev/null
+++ b/maintenance/attachLdapUser.php
@@ -0,0 +1,64 @@
+http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+if ( getenv( 'MW_INSTALL_PATH' ) ) {
+   $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+   $IP = __DIR__ . '/../../..';
+}
+require_once "$IP/maintenance/Maintenance.php";
+
+use MediaWiki\Auth\AuthManager;
+
+/**
+ * Attach an existing LDAP account to the local wiki with all expected log
+ * events created as well.
+ *
+ * @copyright © 2017 Wikimedia Foundation and contributors
+ */
+class AttachLdapUser extends Maintenance {
+   public function __construct() {
+   parent::__construct();
+   $this->mDescription = "Attach an existing LDAP user to the 
local wiki";
+   $this->addOption( 'user', 'Username', true, true );
+   $this->addOption( 'email', 'Email address', true, true );
+   $this->addOption( 'domain', 'LDAP domain', false, true );
+   }
+
+   public function execute() {
+   // Setup the internal state of LdapAuthenticationPlugin as 
though the
+   // login form was used. Ugly but this is what LdapAuthentication
+   // forces us to do.
+   $ldap = LdapAuthenticationPlugin::getInstance();
+   $ldap->LDAPUsername = $this->getOption( 'user' );
+   $ldap->email = $this->getOption( 'email' );
+   $domain = $this->getOption( 'domain', $ldap->getDomain() );
+   $ldap->setDomain( $domain );
+   $_SESSION['wsDomain'] = $domain;
+
+   $user = User::newFromName( $ldap->LDAPUsername, 'creatable' );
+   AuthManager::singleton()->autoCreateUser(
+   $user, LdapPrimaryAuthenticationProvider::class, false 
);
+   }
+}
+
+$maintClass = "AttachLdapUser";
+require_once RUN_MAINTENANCE_IF_MAIN;

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id7aa131c64fc0a7df934ebcbc56d367e996b8355
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: master
Gerrit-Owner: BryanDavis 
Gerrit-Reviewer: Andrew Bogott 
Gerrit-Reviewer: BryanDavis 
Gerrit-Reviewer: Gergő Tisza 
Gerrit-Reviewer: Reedy 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] mediawiki...OpenStackManager[master]: Add maintenance script for attaching existing LDAP accounts

2017-11-30 Thread BryanDavis (Code Review)
BryanDavis has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/394510 )

Change subject: Add maintenance script for attaching existing LDAP accounts
..

Add maintenance script for attaching existing LDAP accounts

The attachLdapUser.php maintenance script can be used to attach an
existing LDAP account to the local wiki. In addition to creating the
user table entries, it will also add the expected user creation log
events.

Bug: T180813
Change-Id: Id7aa131c64fc0a7df934ebcbc56d367e996b8355
---
A maintenance/attachLdapUser.php
1 file changed, 64 insertions(+), 0 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OpenStackManager 
refs/changes/10/394510/1

diff --git a/maintenance/attachLdapUser.php b/maintenance/attachLdapUser.php
new file mode 100644
index 000..d4cd49a
--- /dev/null
+++ b/maintenance/attachLdapUser.php
@@ -0,0 +1,64 @@
+http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
+
+if ( getenv( 'MW_INSTALL_PATH' ) ) {
+   $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+   $IP = __DIR__ . '/../../..';
+}
+require_once "$IP/maintenance/Maintenance.php";
+
+use MediaWiki\Auth\AuthManager;
+
+/**
+ * Attach an existing LDAP account to the local wiki with all expected log
+ * events created as well.
+ *
+ * @copyright © 2017 Wikimedia Foundation and contributors
+ */
+class AttachLdapUser extends Maintenance {
+   public function __construct() {
+   parent::__construct();
+   $this->mDescription = "Attach an existing LDAP user to the 
local wiki";
+   $this->addOption( 'user', 'Username', true, true );
+   $this->addOption( 'email', 'Email address', true, true );
+   $this->addOption( 'domain', 'LDAP domain', false, true );
+   }
+
+   public function execute() {
+   // Setup the internal state of LdapAuthenticationPlugin as 
though the
+   // login form was used. Ugly but this is what LdapAuthentication
+   // forces us to do.
+   $ldap = LdapAuthenticationPlugin::getInstance();
+   $ldap->LDAPUsername = $this->getOption( 'user' );
+   $ldap->email = $this->getOption( 'email' );
+   $domain = $this->getOption( 'domain', $ldap->getDomain() );
+   $ldap->setDomain( $domain );
+   $_SESSION['wsDomain'] = $domain;
+
+   $user = User::newFromName( $ldap->LDAPUsername, 'creatable' );
+   AuthManager::singleton()->autoCreateUser(
+   $user, LdapPrimaryAuthenticationProvider::class, false 
);
+   }
+}
+
+$maintClass = "AttachLdapUser";
+require_once RUN_MAINTENANCE_IF_MAIN;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id7aa131c64fc0a7df934ebcbc56d367e996b8355
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: master
Gerrit-Owner: BryanDavis 

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