コード例 #1
1
 /**
  * @Route("/edit/{user}",name="registration_admin_edit")
  */
 public function editAction(Request $request, $user)
 {
     $response = new Response();
     $em = $this->getDoctrine()->getManager();
     $form = $this->createForm(EditType::class);
     $form->handleRequest($request);
     $user = $em->getRepository(RegUser::class)->findOneByUsername($user);
     if ($form->isValid()) {
         $data = $form->getData();
         if ($data['action'] === true) {
             $password = new Password();
             $password->setHash($user->getPasswordHash());
             $password->setId('default');
             $password->setEncoder(CryptEncoder::class);
             $userLdap = $this->get('cloud.ldap.util.usermanipulator')->createUserObject($user->getUsername(), $password);
             $userLdap->setAltEmail($user->getAltEmail());
             $userLdap->setGpgPublicKey($user->getGpgPublicKey());
             $this->get('cloud.ldap.util.usermanipulator')->create($userLdap);
             $em->remove($user);
         } elseif ($data['action'] === false) {
             $em->remove($user);
         } else {
             $response->setStatusCode(400);
             return $response;
         }
         $em->flush();
     } else {
         $response->setContent(json_encode(['successfully' => false, 'error' => $form->getErrors(true)->__toString()]));
         return $response;
     }
     $response->setContent(json_encode(['successfully' => true]));
     return $response;
 }
コード例 #2
0
 public function testServiceInvalide()
 {
     $service = new Service("");
     $this->assertNotEmpty($this->validator->validate($service));
     $service = new Service("testService");
     $invalidPassword = new Password();
     $invalidPassword->setId("invalidö");
     $invalidPassword->setPasswordPlain("123456");
     $service->addPassword($invalidPassword);
     $this->assertNotEmpty($this->validator->validate($service));
 }
コード例 #3
0
 /**
  * (non-PHPdoc)
  * @see \Cloud\LdapBundle\Security\PasswordEncoderInterface::parsePassword()
  */
 public function parsePassword($password_hash)
 {
     $password = new Password();
     $password->setHash($password_hash);
     $matches = null;
     preg_match('#^{crypt}\\$\\d\\$(rounds=\\d+\\$)?([0-9a-zA-Z_-]+)?(=|\\+)?[0-9a-zA-Z_-]+\\$[^\\$]*$#', $password_hash, $matches);
     if ($matches != null) {
         $password->setId(substr($matches[2], 0, -1));
         $password->setMasterPassword($matches[3] === '+');
     }
     return $password;
 }
コード例 #4
0
 public function testPasswordEncoder()
 {
     $password = new Password("testId");
     $password->setPasswordPlain("123456");
     $this->encoder->encodePassword($password);
     $this->assertGreaterThan(10, strlen($password->getHash()));
     $password->setPasswordPlain("654321");
     $this->assertFalse($this->encoder->isPasswordValid($password));
     $password->setPasswordPlain("123456");
     $this->assertTrue($this->encoder->isPasswordValid($password));
     $password2 = $this->encoder->parsePassword($password->getHash());
     $this->assertEquals($password->getId(), $password2->getId());
     $this->assertEquals($password->getHash(), $password2->getHash());
 }
コード例 #5
0
 /**
  * (non-PHPdoc)
  * @see \Cloud\LdapBundle\Security\PasswordEncoderInterface::parsePassword()
  */
 public static function parsePassword(Attribute $password_hash)
 {
     $password = new Password();
     $password->setAttribute($password_hash);
     $matches = null;
     $found = preg_match('#^{crypt}\\$\\d\\$(rounds=\\d+\\$)?([0-9a-zA-Z_-]+)?(=|\\+)[0-9a-zA-Z_-]+\\$[^\\$]*$#', $password_hash->get(), $matches);
     if ($found === 1) {
         $password->setId($matches[2]);
         $password->setMasterPassword($matches[3] === '+');
     } else {
         return null;
     }
     $password->setEncoder(CryptEncoder::class);
     return $password;
 }
コード例 #6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     // read password
     $password = "";
     if ($input->getArgument('password')) {
         $password = $input->getArgument('password');
     } else {
         $question = new Question('Please enter password:');
         $question->setHidden(true);
         $password = $helper->ask($input, $output, $question);
     }
     $encoder = new CryptEncoder();
     $pw = new Password();
     $pw->setPasswordPlain($password);
     $encoder->encodePassword($pw);
     $output->writeln($pw->getHash());
     return 0;
 }
コード例 #7
0
 public function testPasswordInvalide()
 {
     $password = new Password();
     // no plain password and no hash
     $password->setId("valid");
     //$this->assertNotEmpty($this->validator->validate($password));
     $password->setPasswordPlain("123456");
     $password->setId("0");
     $this->assertNotEmpty($this->validator->validate($password));
     $password->setId(null);
     $this->assertNotEmpty($this->validator->validate($password));
     $password->setId("");
     // empty id
     $this->assertNotEmpty($this->validator->validate($password));
     $password->setId("df.");
     // invalide char
     $this->assertNotEmpty($this->validator->validate($password));
     $password->setId("0101sfdgfda");
     // to long
     $this->assertNotEmpty($this->validator->validate($password));
 }
コード例 #8
0
 /**
  * @param   Request $request
  * @return  Response
  * @Route("/do",name="registraion_do")
  */
 public function registrationAction(Request $request)
 {
     $response = new Response();
     $form = $this->createForm(RegistrationType::class, new User());
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $user = $form->getData();
         if (in_array(strtolower($user->getUsername()), $this->get('cloud.ldap.userprovider')->getUsernames()) || $em->getRepository('CloudRegistrationBundle:User')->findOneByUsername($user->getUsername())) {
             return $response->setContent(json_encode(['successfully' => false, 'errors' => ['message' => 'user exiests']]));
         }
         $password = new Password();
         $password->setPasswordPlain($user->getPassword());
         $encoder = new CryptEncoder();
         $encoder->encodePassword($password);
         $user->setPasswordHash($password->getHash());
         $em->persist($user);
         $em->flush();
     } else {
         return $response->setContent(json_encode(['successfully' => false, 'errors' => ['message' => $form->getErrors(true)->__toString()]]));
     }
     return $response->setContent(json_encode(['successfully' => true, 'message' => 'Your account need to get activated by a admin']));
 }
コード例 #9
0
 /**
  * (non-PHPdoc)
  * @see \Cloud\LdapBundle\Security\PasswordEncoderInterface::parsePassword()
  */
 public static function parsePassword(Attribute $password_hash)
 {
     $password = new Password();
     $password->setAttribute($password_hash);
     $password->setHash($password_hash->get());
     $password->setId('default');
     /*if(preg_match('#^[0-9A-F]$#',$password_hash->get())===1) {
           $password->setMasterPassword(true);
       }elseif(preg_match('#^[0-9a-f]$#',$password_hash->get())===1) {
           $password->setMasterPassword(false);
       }*/
     $password->setEncoder(NtEncoder::class);
     return $password;
 }
コード例 #10
0
 /**
  *
  * @param Password $password
  * @return \Cloud\LdapBundle\Entity\Service
  */
 public function addPassword(Password $password)
 {
     //@TODO update to new schema
     if ($password->getEncoder() === $this->getEncoder()) {
         $attr = $this->getAttributes()->get('sambalmpassword');
         $attr->set($password->getAttribute()->get());
         $password->setAttribute($attr);
         $this->password = $password;
         return $this;
     }
     if ($password->getPasswordPlain() === null) {
         throw new \InvalidArgumentException("can't store false encoded password");
     }
     $password->setAttribute($this->getAttributes()->get('sambalmpassword'));
     call_user_func($this->getEncoder() . '::encodePassword', $password);
     return $this;
 }
コード例 #11
0
 /**
  *
  * @param Password $password
  * @return Service
  */
 public function removePassword(Password $password)
 {
     if (!isset($this->passwords[$password->getId()])) {
         return $this;
     }
     $this->getAttributes()->get('userpassword')->removeElement($this->passwords[$password->getId()]->getAttribute());
     unset($this->passwords[$password->getId()]);
     return $this;
 }