Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(files_external): Replace security annotations with respective attributes #46809

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apps/files_external/lib/Controller/AjaxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use OCA\Files_External\Lib\Auth\Password\GlobalAuth;
use OCA\Files_External\Lib\Auth\PublicKey\RSA;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IGroupManager;
use OCP\IRequest;
Expand Down Expand Up @@ -60,9 +61,9 @@ private function generateSshKeys($keyLength) {
/**
* Generates an SSH public/private key pair.
*
* @NoAdminRequired
* @param int $keyLength
*/
#[NoAdminRequired]
public function getSshKeys($keyLength = 1024) {
$key = $this->generateSshKeys($keyLength);
return new JSONResponse(
Expand All @@ -75,13 +76,12 @@ public function getSshKeys($keyLength = 1024) {
}

/**
* @NoAdminRequired
*
* @param string $uid
* @param string $user
* @param string $password
* @return bool
*/
#[NoAdminRequired]
public function saveGlobalCredentials($uid, $user, $password) {
$currentUser = $this->userSession->getUser();
if ($currentUser === null) {
Expand Down
8 changes: 3 additions & 5 deletions apps/files_external/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
Expand Down Expand Up @@ -76,14 +77,13 @@ private function formatMount(string $mountPoint, StorageConfig $mountConfig): ar
}

/**
* @NoAdminRequired
*
* Get the mount points visible for this user
*
* @return DataResponse<Http::STATUS_OK, Files_ExternalMount[], array{}>
*
* 200: User mounts returned
*/
#[NoAdminRequired]
public function getUserMounts(): DataResponse {
$entries = [];
$mountPoints = [];
Expand All @@ -105,12 +105,10 @@ public function getUserMounts(): DataResponse {
}

/**
* @NoAdminRequired
* @NoCSRFRequired
*
* Ask for credentials using a browser's native basic auth prompt
* Then returns it if provided
*/
#[NoAdminRequired]
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
public function askNativeAuth(): DataResponse {
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\UserGlobalStoragesService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IGroupManager;
Expand Down Expand Up @@ -64,9 +65,8 @@ public function __construct(
* Get all storage entries
*
* @return DataResponse
*
* @NoAdminRequired
*/
#[NoAdminRequired]
public function index() {
/** @var UserGlobalStoragesService */
$service = $this->service;
Expand Down Expand Up @@ -97,9 +97,8 @@ protected function manipulateStorageConfig(StorageConfig $storage) {
* @param int $id storage id
* @param bool $testOnly whether to storage should only test the connection or do more things
* @return DataResponse
*
* @NoAdminRequired
*/
#[NoAdminRequired]
public function show($id, $testOnly = true) {
try {
$storage = $this->service->getStorage($id);
Expand Down Expand Up @@ -135,9 +134,8 @@ public function show($id, $testOnly = true) {
* @param bool $testOnly whether to storage should only test the connection or do more things
*
* @return DataResponse
*
* @NoAdminRequired
*/
#[NoAdminRequired]
public function update(
$id,
$backendOptions,
Expand Down
16 changes: 6 additions & 10 deletions apps/files_external/lib/Controller/UserStoragesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\Files_External\NotFoundException;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\IConfig;
use OCP\IGroupManager;
Expand Down Expand Up @@ -69,21 +70,19 @@ protected function manipulateStorageConfig(StorageConfig $storage) {
/**
* Get all storage entries
*
* @NoAdminRequired
*
* @return DataResponse
*/
#[NoAdminRequired]
public function index() {
return parent::index();
}

/**
* Return storage
*
* @NoAdminRequired
*
* {@inheritdoc}
*/
#[NoAdminRequired]
public function show($id, $testOnly = true) {
return parent::show($id, $testOnly);
}
Expand All @@ -98,9 +97,8 @@ public function show($id, $testOnly = true) {
* @param array $mountOptions backend-specific mount options
*
* @return DataResponse
*
* @NoAdminRequired
*/
#[NoAdminRequired]
public function create(
$mountPoint,
$backend,
Expand Down Expand Up @@ -154,9 +152,8 @@ public function create(
* @param bool $testOnly whether to storage should only test the connection or do more things
*
* @return DataResponse
*
* @NoAdminRequired
*/
#[NoAdminRequired]
public function update(
$id,
$mountPoint,
Expand Down Expand Up @@ -205,10 +202,9 @@ public function update(
/**
* Delete storage
*
* @NoAdminRequired
*
* {@inheritdoc}
*/
#[NoAdminRequired]
public function destroy($id) {
return parent::destroy($id);
}
Expand Down
Loading