mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[APM Plugin - Browser] Migrate authc.getCurrentUser usage to coreStart.security (#187192)
Part of https://github.com/elastic/kibana/issues/186574 ## Summary This PR migrates the method to access an APM Plugin view model field, which consumes `authc.getCurrentUser`, to use `coreStart.security`. 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. ### 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
This commit is contained in:
parent
69c1533916
commit
78fa3c36c3
2 changed files with 8 additions and 5 deletions
|
@ -8,26 +8,26 @@
|
|||
import { useState, useEffect } from 'react';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import { AuthenticatedUser } from '@kbn/security-plugin/common';
|
||||
import { ApmPluginStartDeps } from '../plugin';
|
||||
import { ApmServices } from '../plugin';
|
||||
|
||||
export function useCurrentUser() {
|
||||
const {
|
||||
services: { security },
|
||||
} = useKibana<ApmPluginStartDeps>();
|
||||
services: { securityService },
|
||||
} = useKibana<ApmServices>();
|
||||
|
||||
const [user, setUser] = useState<AuthenticatedUser>();
|
||||
|
||||
useEffect(() => {
|
||||
const getCurrentUser = async () => {
|
||||
try {
|
||||
const authenticatedUser = await security?.authc.getCurrentUser();
|
||||
const authenticatedUser = await securityService.authc.getCurrentUser();
|
||||
setUser(authenticatedUser);
|
||||
} catch {
|
||||
setUser(undefined);
|
||||
}
|
||||
};
|
||||
getCurrentUser();
|
||||
}, [security?.authc]);
|
||||
}, [securityService.authc]);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
DEFAULT_APP_CATEGORIES,
|
||||
Plugin,
|
||||
PluginInitializerContext,
|
||||
SecurityServiceStart,
|
||||
} from '@kbn/core/public';
|
||||
import type { DataPublicPluginSetup, DataPublicPluginStart } from '@kbn/data-plugin/public';
|
||||
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
|
||||
|
@ -107,6 +108,7 @@ export interface ApmPluginSetupDeps {
|
|||
}
|
||||
|
||||
export interface ApmServices {
|
||||
securityService: SecurityServiceStart;
|
||||
telemetry: ITelemetryClient;
|
||||
}
|
||||
|
||||
|
@ -390,6 +392,7 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
|
|||
pluginsStart: pluginsStart as ApmPluginStartDeps,
|
||||
observabilityRuleTypeRegistry,
|
||||
apmServices: {
|
||||
securityService: coreStart.security,
|
||||
telemetry,
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue