예제 #1
0
 /**
  * Create redmine user
  * @param User $user
  * @return mixed
  */
 public function createUser(User $user)
 {
     // Fast Return in case of server stopped
     if (!$this->serverAvailable) {
         return null;
     }
     $params['login'] = $user->getUsername();
     $params['firstname'] = $user->getFirstName();
     $params['lastname'] = $user->getLastName();
     $params['mail'] = $user->getEmail();
     $params['auth_source_id'] = $this->authSourceId;
     return $this->redmineClient->api($this::API_USER)->create($params);
 }
예제 #2
0
 /**
  * Delete User
  * @param User $user
  * @return mixed
  * @deprecated
  */
 public function deleteUser(User $user)
 {
     // Fast Return in case of server stopped
     if (!$this->isServerAvailable()) {
         return null;
     }
     // Initialize values
     $userPath = $this->userBasePath . $user->getUsername();
     $fs = new Filesystem();
     // Delete user path
     $fs->remove($userPath);
     $retval['userPath'] = $userPath;
     $retval['userPathRemoved'] = !$fs->exists($userPath);
     // Remove global var
     if (file_exists($this->configFile)) {
         // Config file backup
         $retval['confFileBackuped'] = $this->backupConfigFile();
         // Opening config file
         $xmlFile = simplexml_load_file($this->configFile);
         //            // Removing some values
         $permissions = $xmlFile->xpath("//authorizationStrategy/permission");
         foreach ($permissions as $result) {
             if ($result == "hudson.model.Hudson.Read:" . $user->getUsername()) {
                 unset($result[0]);
             }
         }
         // Overriding config file
         $dom = dom_import_simplexml($xmlFile)->ownerDocument;
         $dom->formatOutput = true;
         $fileToWrite = fopen($this->configFile, "w");
         fwrite($fileToWrite, $dom->saveXML());
         fclose($fileToWrite);
         // Updating return values
         $retval['confFileUpdated'] = $fs->exists($this->configFile);
     } else {
         $retval['confFileBackuped'] = false;
         $retval['confFileUpdated'] = false;
     }
     // Restart jenkins
     $retval['hostRestarted'] = $this->reloadHost();
     // Return values
     if ($retval['userPathRemoved'] && $retval['confFileUpdated']) {
         return true;
     } else {
         return false;
     }
     //        return $retval;
 }
예제 #3
0
 /**
  * Removes a permission from a project
  * @param User $user
  * @param Project $project
  * @return mixed
  */
 public function removePermission(User $user, Project $project)
 {
     // Fast Return in case of server stopped
     if (!$this->serverAvailable) {
         return null;
     }
     try {
         return $this->sonarClient->api('permissions')->remove(array("component" => $project->getSonarProjectKey(), "user" => $user->getUsername(), "permission" => 'user'));
     } catch (\Exception $e) {
         return null;
     }
 }
예제 #4
0
 /**
  * @param User $user
  * @return mixed
  */
 public function createUser(User $user)
 {
     // Fast Return in case of server stopped
     if (!$this->isServerAvailable()) {
         return null;
     }
     // Create user
     $newUser = $this->gitLabClient->api($this::API_USERS)->create($user->getEmail(), '1234567890', array('username' => $user->getUsername(), 'name' => $user->getCommonName(), 'provider' => $this->ldapProvider, 'extern_uid' => $user->getDn(), 'confirm' => false, 'projects_limit' => 0));
     // Return created user
     return $newUser;
 }
예제 #5
0
 /**
  * Unlock user LDAP Account
  * @param User $user
  * @return mixed
  */
 public function ldapUnlockAccount(User $user)
 {
     $ldapInitialization = $this->ldapInit();
     $issue = null;
     if ($ldapInitialization) {
         $ldapSearch = ldap_search($this->ldapLinkIdentifier, $this->baseDn, 'uid=' . $user->getUsername());
         $ldapUser = ldap_get_entries($this->ldapLinkIdentifier, $ldapSearch);
         $ldapUserPassword = $ldapUser[0]['userpassword'][0];
         $ldapUserNewPassword = substr($ldapUserPassword, 0, 6) . substr($ldapUserPassword, 7, strlen($ldapUserPassword));
         $modifiedInfos = ['userPassword' => $ldapUserNewPassword];
         $issue = ldap_modify($this->ldapLinkIdentifier, $user->getDn(), $modifiedInfos);
     }
     ldap_close($this->ldapLinkIdentifier);
     return $issue;
 }