diff --git a/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts b/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts index 1efbec8e5b4a7..e7df04ab24ac9 100644 --- a/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts +++ b/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts @@ -88,32 +88,17 @@ export const useCurrentUser = (): AuthenticatedElasticUser | null => { const [, dispatchToaster] = useStateToaster(); - const { security } = useKibana().services; + const { securityService: security } = useKibana().services; const fetchUser = useCallback( () => { let didCancel = false; const fetchData = async () => { try { - if (security != null) { - const response = await security.authc.getCurrentUser(); - if (!isMounted.current) return; - if (!didCancel) { - setUser(convertToCamelCase(response)); - } - } else { - setUser({ - username: i18n.translate('xpack.securitySolution.getCurrentUser.unknownUser', { - defaultMessage: 'Unknown', - }), - email: '', - fullName: '', - roles: [], - enabled: false, - authenticationRealm: { name: '', type: '' }, - lookupRealm: { name: '', type: '' }, - authenticationProvider: '', - }); + const response = await security.authc.getCurrentUser(); + if (!isMounted.current) return; + if (!didCancel) { + setUser(convertToCamelCase(response)); } } catch (error) { if (!didCancel) { diff --git a/x-pack/plugins/security_solution/public/management/links.test.ts b/x-pack/plugins/security_solution/public/management/links.test.ts index 6a8c5525b8d58..9623fbbcac503 100644 --- a/x-pack/plugins/security_solution/public/management/links.test.ts +++ b/x-pack/plugins/security_solution/public/management/links.test.ts @@ -45,21 +45,22 @@ describe('links', () => { links: links.links?.filter((link) => !excludedLinks.includes(link.id)), }); - const getPlugins = (noUserAuthz: boolean = false): StartPlugins => { + const getPlugins = (): StartPlugins => { return { - security: { - authc: { - getCurrentUser: noUserAuthz - ? jest.fn().mockReturnValue(undefined) - : jest.fn().mockReturnValue([]), - }, - }, fleet: { authz: createFleetAuthzMock(), }, } as unknown as StartPlugins; }; + const getCoreStart = (noUserAuthz: boolean = false) => { + const coreStart = coreMock.createStart(); + coreStart.security.authc.getCurrentUser = noUserAuthz + ? jest.fn().mockReturnValue(undefined) + : jest.fn().mockReturnValue([]); + return coreStart; + }; + beforeAll(() => { ExperimentalFeaturesService.init({ experimentalFeatures: { ...allowedExperimentalValues }, @@ -67,7 +68,7 @@ describe('links', () => { }); beforeEach(() => { - coreMockStarted = coreMock.createStart(); + coreMockStarted = getCoreStart(); fakeHttpServices = coreMockStarted.http as jest.Mocked; }); @@ -84,7 +85,7 @@ describe('links', () => { }); it('should not return any endpoint management link for user with all sub-feature privileges when no user authz', async () => { - const filteredLinks = await getManagementFilteredLinks(coreMockStarted, getPlugins(true)); + const filteredLinks = await getManagementFilteredLinks(getCoreStart(true), getPlugins()); expect(filteredLinks).toEqual( getLinksWithout( SecurityPageName.blocklist, diff --git a/x-pack/plugins/security_solution/public/management/links.ts b/x-pack/plugins/security_solution/public/management/links.ts index 06d47e2936115..fbf30d4091cc2 100644 --- a/x-pack/plugins/security_solution/public/management/links.ts +++ b/x-pack/plugins/security_solution/public/management/links.ts @@ -248,7 +248,7 @@ export const getManagementFilteredLinks = async ( plugins: StartPlugins ): Promise => { const fleetAuthz = plugins.fleet?.authz; - const currentUser = await plugins.security.authc.getCurrentUser(); + const currentUser = await core.security.authc.getCurrentUser(); const { canReadActionsLogManagement, canAccessHostIsolationExceptions, diff --git a/x-pack/plugins/security_solution/public/plugin_services.ts b/x-pack/plugins/security_solution/public/plugin_services.ts index 38ac65c08c8be..335f77a137af9 100644 --- a/x-pack/plugins/security_solution/public/plugin_services.ts +++ b/x-pack/plugins/security_solution/public/plugin_services.ts @@ -140,8 +140,8 @@ export class PluginServices { savedObjectsTagging: savedObjectsTaggingOss.getTaggingApi(), storage: this.storage, sessionStorage: this.sessionStorage, - security: startPlugins.security, securityLayout: { getPluginWrapper: () => SecuritySolutionTemplateWrapper }, + securityService: coreStart.security, contentManagement: startPlugins.contentManagement, telemetry: this.telemetry.start(), customDataService, diff --git a/x-pack/plugins/security_solution/public/types.ts b/x-pack/plugins/security_solution/public/types.ts index 1eb944143c0fe..e09b3ea877dd2 100644 --- a/x-pack/plugins/security_solution/public/types.ts +++ b/x-pack/plugins/security_solution/public/types.ts @@ -60,6 +60,7 @@ import type { ChartsPluginStart } from '@kbn/charts-plugin/public'; import type { SavedSearchPublicPluginStart } from '@kbn/saved-search-plugin/public'; import type { PluginStartContract } from '@kbn/alerting-plugin/public/plugin'; import type { MapsStartApi } from '@kbn/maps-plugin/public'; +import type { SecurityServiceStart } from '@kbn/core-security-browser'; import type { ResolverPluginSetup } from './resolver/types'; import type { Inspect } from '../common/search_strategy'; import type { Detections } from './detections'; @@ -188,6 +189,11 @@ export type StartServices = CoreStart & customDataService: DataPublicPluginStart; topValuesPopover: TopValuesPopoverService; timelineDataService: DataPublicPluginStart; + /** + * The "security" field name is used for both CoreStart['security'] and StartPlugins['security'] (deprecated). + * Use this field to ensure you are using the non-deprecated Security-In-Core APIs. + */ + securityService: SecurityServiceStart; }; export type StartRenderServices = Pick< diff --git a/x-pack/plugins/security_solution/tsconfig.json b/x-pack/plugins/security_solution/tsconfig.json index f1320dc3205be..820a9bee23173 100644 --- a/x-pack/plugins/security_solution/tsconfig.json +++ b/x-pack/plugins/security_solution/tsconfig.json @@ -209,5 +209,6 @@ "@kbn/core-analytics-browser", "@kbn/core-i18n-browser", "@kbn/core-theme-browser", + "@kbn/core-security-browser", ] } diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index 606be2f72914c..bdfd2daadabe7 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -36327,7 +36327,6 @@ "xpack.securitySolution.formattedNumber.compactThousands": "k", "xpack.securitySolution.formattedNumber.compactTrillions": "T", "xpack.securitySolution.getCurrentUser.Error": "Erreur lors de l'obtention de l'utilisateur", - "xpack.securitySolution.getCurrentUser.unknownUser": "Inconnu", "xpack.securitySolution.getFileAction.pendingMessage": "Récupération du fichier à partir de l'hôte.", "xpack.securitySolution.getStarted.landingCards.box.cloudCard.desc": "Évaluez votre niveau de cloud et protégez vos charges de travail contre les attaques.", "xpack.securitySolution.getStarted.landingCards.box.cloudCard.title": "Protection cloud de bout en bout", diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index fe26b29ebc559..2ce72dd5bc491 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -36302,7 +36302,6 @@ "xpack.securitySolution.formattedNumber.compactThousands": "k", "xpack.securitySolution.formattedNumber.compactTrillions": "T", "xpack.securitySolution.getCurrentUser.Error": "ユーザーの取得エラー", - "xpack.securitySolution.getCurrentUser.unknownUser": "不明", "xpack.securitySolution.getFileAction.pendingMessage": "ホストからファイルを取得しています。", "xpack.securitySolution.getStarted.landingCards.box.cloudCard.desc": "クラウド態勢を評価し、ワークロードを攻撃から保護します。", "xpack.securitySolution.getStarted.landingCards.box.cloudCard.title": "エンドツーエンドのクラウド保護", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 7dc4eaa5adcb2..a7183d615df40 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -36345,7 +36345,6 @@ "xpack.securitySolution.formattedNumber.compactThousands": "k", "xpack.securitySolution.formattedNumber.compactTrillions": "T", "xpack.securitySolution.getCurrentUser.Error": "获取用户时出错", - "xpack.securitySolution.getCurrentUser.unknownUser": "未知", "xpack.securitySolution.getFileAction.pendingMessage": "正在从主机检索文件。", "xpack.securitySolution.getStarted.landingCards.box.cloudCard.desc": "评估您的云态势并防止工作负载受到攻击。", "xpack.securitySolution.getStarted.landingCards.box.cloudCard.title": "端到端云防护",