Skip to content

Commit

Permalink
specialize security parameter for get user factory
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Jan 28, 2020
1 parent 8886b9a commit 9427d77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions x-pack/legacy/plugins/reporting/server/lib/get_user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ import { KibanaRequest } from '../../../../../../src/core/server';
import { Logger, ServerFacade } from '../../types';
import { ReportingSetupDeps } from '../plugin';

export function getUserFactory(server: ServerFacade, plugins: ReportingSetupDeps, logger: Logger) {
export function getUserFactory(
server: ServerFacade,
security: ReportingSetupDeps['security'],
logger: Logger
) {
/*
* Legacy.Request because this is called from routing middleware
*/
return async (request: Legacy.Request) => {
if (!plugins.security) {
if (!security) {
return null;
}

try {
return await plugins.security.authc.getCurrentUser(KibanaRequest.from(request));
return await security.authc.getCurrentUser(KibanaRequest.from(request));
} catch (err) {
logger.error(err, ['getUser']);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const authorizedUserPreRoutingFactory = function authorizedUserPreRouting
plugins: ReportingSetupDeps,
logger: Logger
) {
const getUser = getUserFactory(server, plugins, logger);
const getUser = getUserFactory(server, plugins.security, logger);
const config = server.config();

return async function authorizedUserPreRouting(request: Legacy.Request) {
Expand Down

0 comments on commit 9427d77

Please sign in to comment.