コード例 #1
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));
 }
コード例 #2
0
 protected function serviceEnabled()
 {
     parent::serviceEnabled();
     $username = $this->getUser()->getUsername();
     $this->setUid(1000);
     //@TODO incremental id
     $this->setGid(1000);
     $this->setHomeDirector('/home/' . $username);
     $this->getObject(Schemas\PosixAccount::class)->setCn($username);
 }
コード例 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     try {
         $this->getContainer()->get('cloud.ldap.userprovider');
     } catch (\Exception $e) {
         $output->writeln("<error>Can't connect to database</error>");
         return 255;
     }
     // read username
     $username = null;
     if ($input->getArgument('username') !== null) {
         $username = $input->getArgument('username');
     } else {
         $question = new Question('Please enter the name of the User:'******'cloud.ldap.userprovider')->getUsernames());
         $username = $helper->ask($input, $output, $question);
     }
     // check username for existence
     try {
         $this->user = $this->getContainer()->get('cloud.ldap.userprovider')->loadUserByUsername($username);
     } catch (UsernameNotFoundException $e) {
         $output->writeln('<error>User not found</error>');
         return 1;
     }
     $action = null;
     if ($input->getArgument('action') !== null) {
         $action = $input->getArgument('action');
     } else {
         $question = new Question('Please enter a action (list|show|enable|disable|enableMasterPassword|disableMasterPassword):');
         $question->setAutocompleterValues(['list', 'show', 'enable', 'disable', 'enableMasterPassword', 'disableMasterPassword']);
         $action = $helper->ask($input, $output, $question);
     }
     if ($action === 'list') {
         $table = new Table($output);
         $table->setHeaders(array('Service Name', 'Enabled', 'MasterPasswordEnabled', 'passwords'));
         foreach ($this->user->getServices() as $service) {
             $table->addRow([$service->getName(), $service->isEnabled() ? 'X' : '', $service->isMasterPasswordEnabled() ? 'X' : '', implode(',', array_map(function ($password) {
                 return !$password->isMasterPassword() ? $password->getId() : '';
             }, $service->getPasswords()))]);
         }
         $table->render();
         return 0;
     }
     // read service
     $serviceName = null;
     if ($input->getArgument('service')) {
         $serviceName = $input->getArgument('service');
     } else {
         $question = new Question('Please enter service name:');
         $question->setAutocompleterValues(array_map(function ($service) {
             return $service->getName();
         }, $this->user->getServices()));
         $serviceName = $helper->ask($input, $output, $question);
     }
     $this->service = $this->user->getService($serviceName);
     switch ($action) {
         case 'show':
             //@TODO
             break;
         case 'enable':
             $this->service->setEnabled(true);
             $this->service->setMasterPasswordEnabled(true);
             $this->getContainer()->get('cloud.ldap.util.usermanipulator')->update($this->user);
             break;
         case 'disable':
             if (!$input->getOption('force')) {
                 $question = new ConfirmationQuestion('You really want to disable this service for the user \'' . $this->user->getUsername() . "?\n<error>all passwords get deleted</error> [y/N]:", false);
                 if (!$helper->ask($input, $output, $question)) {
                     $output->writeln('<error>canceled by user, if you use a script use \'-f\' to force delete</error>');
                     return 1;
                 }
             }
             $this->service->setEnabled(false);
             $this->getContainer()->get('cloud.ldap.util.usermanipulator')->update($this->user);
             break;
         case 'enableMasterPassword':
             $this->service->setMasterPasswordEnabled(true);
             $this->getContainer()->get('cloud.ldap.util.usermanipulator')->update($this->user);
             break;
         case 'disableMasterPassword':
             $this->service->setMasterPasswordEnabled(false);
             $this->getContainer()->get('cloud.ldap.util.usermanipulator')->update($this->user);
             break;
         default:
             $output->writeln('<error>action not found</error>');
             return 1;
     }
     return 0;
 }