From 72090ee7c37f11bad728e4b0d7ab89aecd06dafa Mon Sep 17 00:00:00 2001 From: Tim Sullivan Date: Wed, 26 Jun 2024 10:00:49 -0700 Subject: [PATCH] [Files] Use server-side authc.getCurrentUser from core.security (#186922) Part of https://github.com/elastic/kibana/issues/186574 Background: This PR serves as an example of a plugin migrating away from depending on the Security plugin, which is a high priority effort for the last release before 9.0. The Files plugin uses the `authc.getCurrentUser` method to attribute the current user to files that are created in the system. ### Checklist Delete any items that are not applicable to this PR. - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --- src/plugins/files/server/routes/file_kind/create.ts | 6 +++--- src/plugins/files/server/routes/types.ts | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/plugins/files/server/routes/file_kind/create.ts b/src/plugins/files/server/routes/file_kind/create.ts index 9121e27df0ac1..b15cb96a2ce93 100644 --- a/src/plugins/files/server/routes/file_kind/create.ts +++ b/src/plugins/files/server/routes/file_kind/create.ts @@ -31,12 +31,12 @@ export type Endpoint = CreateRouteDefinition< FilesClient['create'] >; -export const handler: CreateHandler = async ({ fileKind, files }, req, res) => { - const { fileService, security } = await files; +export const handler: CreateHandler = async ({ core, fileKind, files }, req, res) => { + const [{ security }, { fileService }] = await Promise.all([core, files]); const { body: { name, alt, meta, mimeType }, } = req; - const user = security?.authc.getCurrentUser(req); + const user = security.authc.getCurrentUser(); const file = await fileService.asCurrentUser().create({ fileKind, name, diff --git a/src/plugins/files/server/routes/types.ts b/src/plugins/files/server/routes/types.ts index 9a1332137c811..5095ae8ab51a2 100644 --- a/src/plugins/files/server/routes/types.ts +++ b/src/plugins/files/server/routes/types.ts @@ -17,14 +17,12 @@ import type { ResponseError, RouteMethod, } from '@kbn/core/server'; -import type { SecurityPluginStart } from '@kbn/security-plugin/server'; import type { FileServiceStart } from '../file_service'; import { Counters } from '../usage'; import { AnyEndpoint } from './api_routes'; export interface FilesRequestHandlerContext extends RequestHandlerContext { files: Promise<{ - security?: SecurityPluginStart; fileService: { asCurrentUser: () => FileServiceStart; asInternalUser: () => FileServiceStart;