/** * @inheritdoc */ protected function doExecute(InputInterface $input, OutputInterface $output) { $user = $this->getUser($input->getArgument('username')); $securityContext = $this->getContainer()->get('security.context'); $token = new CliToken($user->getRoles()); $token->setUser($user); $token->setAuthenticated(true); $securityContext->setToken($token); $shellHandler = $this->getContainer()->get('gitonomy_core.git.shell_handler'); $originalCommand = $shellHandler->getOriginalCommand(); if (null === $originalCommand) { $this->outputUserInformation($output, $user); return; } if (!preg_match('#^(.*) \'(/?' . Project::SLUG_PATTERN . ').git\'#', $originalCommand, $vars)) { throw new \RuntimeException('Command seems illegal: ' . $originalCommand); } $action = $vars[1]; $project = $this->getProject($vars[2]); switch ($action) { case 'git-receive-pack': case 'git-upload-pack': if (!$securityContext->isGranted('PROJECT_READ', $project)) { throw new \RuntimeException('You are not allowed to read on this repository'); } break; default: throw new \RuntimeException('Action seems illegal: ' . $action); } $this->getContainer()->get('gitonomy_core.git.shell_handler')->handle($project, $action, array('GITONOMY_PROJECT' => $project->getSlug(), 'GITONOMY_USER' => $user->getUsername())); }
/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $project = $this->getProject($input->getArgument('project')); $user = $this->getUser($input->getArgument('username')); $permission = $input->getArgument('permission'); $reference = $input->getArgument('reference'); $context = $this->getContainer()->get('security.context'); $token = new CliToken($user->getRoles()); $token->setUser($user); $token->setAuthenticated(true); $context->setToken($token); $test = $context->isGranted($permission, new PushTarget($project, $reference)); return $test ? 0 : 1; }
/** * @inheritdoc */ protected function execute(InputInterface $input, OutputInterface $output) { $permission = $input->getArgument('permission'); $em = $this->getContainer()->get('doctrine')->getManager(); $project = null; if (null !== $input->getOption('project')) { $projectSlug = $input->getOption('project'); $project = $this->getProject($projectSlug); } $username = $input->getArgument('username'); $user = $this->getUser($username); $context = $this->getContainer()->get('security.context'); $token = new CliToken($user->getRoles()); $token->setUser($user); $token->setAuthenticated(true); $context->setToken($token); $test = $context->isGranted($permission, $project); return $test ? 0 : 1; }