Skip to content

Commit

Permalink
[Files] Use server-side authc.getCurrentUser from core.security (#186922
Browse files Browse the repository at this point in the history
)

Part of #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
  • Loading branch information
tsullivan authored Jun 26, 2024
1 parent fdfcc52 commit 72090ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/plugins/files/server/routes/file_kind/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ export type Endpoint<M = unknown> = CreateRouteDefinition<
FilesClient['create']
>;

export const handler: CreateHandler<Endpoint> = async ({ fileKind, files }, req, res) => {
const { fileService, security } = await files;
export const handler: CreateHandler<Endpoint> = 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,
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/files/server/routes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 72090ee

Please sign in to comment.