Exemplo n.º 1
0
 /**
  * Loading User datas
  * @param ObjectManager $manager
  */
 public function load(ObjectManager $manager)
 {
     // Creating Super Admin User
     $userSuper = new User();
     $userSuper->setUsername('sys');
     $password = $this->encoder->encodePassword($userSuper, 'sys');
     $userSuper->setPassword($password);
     $userSuper->setEmail('sys@ecosystem.v2');
     $userSuper->setDn('uid=sys,dc=ldap,dc=test');
     $userSuper->setLastName('sys');
     $userSuper->setFirstName('sys');
     $userSuper->setLanguage('en');
     $userSuper->setEnabled(true);
     $userSuper->setRoles(['ROLE_SUPER_ADMIN']);
     $manager->persist($userSuper);
     // Creating Admin user
     $userAdmin = new User();
     $userAdmin->setUsername('admin');
     $password = $this->encoder->encodePassword($userAdmin, 'admin');
     $userAdmin->setPassword($password);
     $userAdmin->setEmail('admin@ecosystem.v2');
     $userAdmin->setDn('uid=admin,dc=ldap,dc=test');
     $userAdmin->setLastName('admin');
     $userAdmin->setFirstName('admin');
     $userAdmin->setLanguage('en');
     $userAdmin->setEnabled(true);
     $userAdmin->setRoles(['ROLE_ADMIN']);
     $manager->persist($userAdmin);
     // Flushing datas
     $manager->flush();
 }
Exemplo n.º 2
0
 /**
  * Adding new LDAP User to database
  * @param $userArray
  * @return User
  */
 protected function processDBUserRegister($userArray)
 {
     // Creating DB User object
     $dbUser = new User();
     $dbUser->setUsername($userArray['uid']);
     // Setting empty password
     $dbUser->setPassword('');
     $dbUser->setEmail($userArray['mail']);
     $dbUser->setDn($userArray['userDn']);
     $dbUser->setLastName($userArray['sn']);
     $dbUser->setFirstName($userArray['givenName']);
     $dbUser->setLanguage($userArray['preferredLanguage']);
     $dbUser->setEnabled(true);
     $dbUser->setRoles(['ROLE_USER']);
     // Adding it to database
     $this->em->persist($dbUser);
     $this->em->flush();
     return $dbUser;
 }
Exemplo n.º 3
0
 /**
  * Send mail for account de/activation, deletion
  * @param User $user
  * @param String $status deletion|deactivation|activation
  * @return mixed
  */
 public function accountUpdate(User $user, $status)
 {
     // Define necessary vars
     $template = "SpiritDevDBoxPortalBundle:Mailer/Profile:accountManagment.html.twig";
     //template
     $subject = $this->getSubject('Account ' . $status);
     // Subject
     $appUrl = $this->router->generate('spirit_dev_dbox_portal_bundle_homepage');
     $rendered = $this->templating->render($template, array('status' => $status, 'user' => $user, 'app_url' => $appUrl, 'admin_mail' => $this->adminMail));
     // Template rendering
     // Send mail effectively
     $this->sendEmailMessage($rendered, $subject, $user->getEmail());
 }
Exemplo n.º 4
0
 /**
  * Processor to remove user from system
  * @param User $user
  * @return mixed
  */
 public function deleteUser(User $user)
 {
     // Preparing variables
     $returnValues['processor'] = 'delete_user';
     $returnValues['username'] = $user->getCommonName() . ' (' . $user->getId() . ')';
     // If user
     if ($user) {
         // Removing LDAP User
         try {
             $returnValues['ldapIssue'] = $this->ldapDriver->ldapRemoveUser($user);
         } catch (\Exception $e) {
             $returnValues['ldapIssue'] = false;
         }
         // Remove VCS user
         try {
             $returnValues['vcsIssue'] = $this->gitlabApi->deleteUser($user);
         } catch (\Exception $e) {
             $returnValues['vcsIssue'] = false;
         }
         // Remove PM user
         try {
             $returnValues['pmIssue'] = $this->redmineApi->deleteUser($user);
         } catch (\Exception $e) {
             $returnValues['pmIssue'] = false;
         }
         // Remove CI User
         //            try {
         //                $returnValues['ciIssue'] = $this->container->get('spirit_dev_dbox_portal_bundle.api.jenkins')->deleteUser($user);
         //            } catch (\Exception $e) {
         $returnValues['ciIssue'] = 'Deprecated !';
         //            }
         // Remove QA User
         $returnValues['qaIssue'] = $this->sonarApi->deleteUser($user);
         // Remove demands
         $demands = $this->em->getRepository('SpiritDevDBoxPortalBundle:Demand')->findBy(array('applicant' => $user));
         $status = $this->em->getRepository('SpiritDevDBoxPortalBundle:Status')->findOneBy(array('canonicalName' => 'new'));
         foreach ($demands as $demand) {
             $demand->setApplicant(null);
             $demand->setStatus($status);
         }
         // Remove projects
         $projectsOwned = $this->em->getRepository('SpiritDevDBoxPortalBundle:Project')->findBy(array('owner' => $user));
         foreach ($projectsOwned as $project) {
             $project->setOwner(null);
         }
         //            $projectMembers = $em->getRepository('SpiritDevDBoxPortalBundle:Project')->findBy(array('teamMembers'=>$user));
         //            foreach ($projectMembers as $project) {
         //                $project->removeTeamMember($user);
         //            }
         // Remove DB User
         $this->em->remove($user);
         // Save changes
         $this->em->flush();
         $returnValues['dbIssue'] = true;
         // Send mail
         $this->mailer->accountUpdate($user, "deletion");
         $returnValues['mailIssue'] = true;
     } else {
         $returnValues['ldapIssue'] = false;
         $returnValues['vcsIssue'] = false;
         $returnValues['pmIssue'] = false;
         $returnValues['ciIssue'] = false;
         $returnValues['qaIssue'] = false;
         $returnValues['dbIssue'] = false;
         $returnValues['mailIssue'] = false;
     }
     // Return values
     return $returnValues;
 }
Exemplo n.º 5
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;
 }
Exemplo n.º 6
0
 /**
  * Remove member from project
  * @param Project $project
  * @param User $user
  * @return mixed
  */
 public function removeProjectMemberships(Project $project, User $user)
 {
     // Fast Return in case of server stopped
     if (!$this->serverAvailable) {
         return null;
     }
     try {
         // Get first the membership ID
         $membershipId = null;
         $membershipArray = $this->getProjectMemberships($project);
         $membershipArray = $membershipArray['memberships'];
         foreach ($membershipArray as $membership) {
             if ($membership['user']['id'] == $user->getRedmineId()) {
                 $membershipId = $membership['id'];
             }
         }
         // Remove it
         return $this->redmineClient->api($this::API_MEMBERSHIP)->remove($membershipId);
     } catch (\Exception $e) {
         return null;
     }
 }
Exemplo n.º 7
0
 /**
  * Unlock user account
  * @param User $user
  * @return mixed
  */
 public function unlockUser(User $user)
 {
     // Fast Return in case of server stopped
     if (!$this->isServerAvailable()) {
         return null;
     }
     return $this->gitLabClient->api($this::API_USERS)->unblock($user->getGitLabId());
 }
Exemplo n.º 8
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;
     }
 }
Exemplo n.º 9
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;
 }