Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate authc dependency from security plugin to core security service #187124

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions x-pack/plugins/cases/server/client/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('CasesClientFactory', () => {
});

expect(args.securityPluginStart.userProfiles.getCurrent).toHaveBeenCalled();
expect(args.securityPluginStart.authc.getCurrentUser).not.toHaveBeenCalled();
expect(args.securityServiceStart.authc.getCurrentUser).not.toHaveBeenCalled();
expect(createCasesClientMocked.mock.calls[0][0].user).toEqual({
username: 'my_user',
full_name: 'My user',
Expand All @@ -63,7 +63,7 @@ describe('CasesClientFactory', () => {
it('constructs the user info from the authc service if the user profile is not available', async () => {
const scopedClusterClient = coreStart.elasticsearch.client.asScoped(request).asCurrentUser;
// @ts-expect-error: not all fields are needed
args.securityPluginStart.authc.getCurrentUser.mockReturnValueOnce({
args.securityServiceStart.authc.getCurrentUser.mockReturnValueOnce({
username: 'my_user_2',
full_name: 'My user 2',
email: 'elastic2@elastic.co',
Expand All @@ -76,7 +76,7 @@ describe('CasesClientFactory', () => {
});

expect(args.securityPluginStart.userProfiles.getCurrent).toHaveBeenCalled();
expect(args.securityPluginStart.authc.getCurrentUser).toHaveBeenCalled();
expect(args.securityServiceStart.authc.getCurrentUser).toHaveBeenCalled();
expect(createCasesClientMocked.mock.calls[0][0].user).toEqual({
username: 'my_user_2',
full_name: 'My user 2',
Expand All @@ -95,7 +95,7 @@ describe('CasesClientFactory', () => {
});

expect(args.securityPluginStart.userProfiles.getCurrent).toHaveBeenCalled();
expect(args.securityPluginStart.authc.getCurrentUser).toHaveBeenCalled();
expect(args.securityServiceStart.authc.getCurrentUser).toHaveBeenCalled();
expect(createCasesClientMocked.mock.calls[0][0].user).toEqual({
username: 'elastic/kibana',
full_name: null,
Expand All @@ -113,7 +113,7 @@ describe('CasesClientFactory', () => {
});

expect(args.securityPluginStart.userProfiles.getCurrent).toHaveBeenCalled();
expect(args.securityPluginStart.authc.getCurrentUser).toHaveBeenCalled();
expect(args.securityServiceStart.authc.getCurrentUser).toHaveBeenCalled();
expect(createCasesClientMocked.mock.calls[0][0].user).toEqual({
username: null,
full_name: null,
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/cases/server/client/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
ElasticsearchClient,
SavedObjectsClientContract,
IBasePath,
SecurityServiceStart,
} from '@kbn/core/server';
import type { ISavedObjectsSerializer } from '@kbn/core-saved-objects-server';
import { SECURITY_EXTENSION_ID } from '@kbn/core-saved-objects-server';
Expand Down Expand Up @@ -57,6 +58,7 @@ import { EmailNotificationService } from '../services/notifications/email_notifi
interface CasesClientFactoryArgs {
securityPluginSetup: SecurityPluginSetup;
securityPluginStart: SecurityPluginStart;
securityServiceStart: SecurityServiceStart;
spacesPluginStart?: SpacesPluginStart;
featuresPluginStart: FeaturesPluginStart;
actionsPluginStart: ActionsPluginStart;
Expand Down Expand Up @@ -257,6 +259,7 @@ export class CasesClientFactory {

try {
const userProfile = await this.options.securityPluginStart.userProfiles.getCurrent({
// todo: Access userProfiles from core's UserProfileService contract
request,
});

Expand All @@ -273,7 +276,7 @@ export class CasesClientFactory {
}

try {
const user = this.options.securityPluginStart.authc.getCurrentUser(request);
const user = this.options.securityServiceStart.authc.getCurrentUser(request);

if (user != null) {
return {
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/cases/server/client/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
*/

import type { PublicContract, PublicMethodsOf } from '@kbn/utility-types';
import { loggingSystemMock, savedObjectsClientMock } from '@kbn/core/server/mocks';
import {
loggingSystemMock,
savedObjectsClientMock,
securityServiceMock,
} from '@kbn/core/server/mocks';
import type { ISavedObjectsSerializer } from '@kbn/core-saved-objects-server';

import {
Expand Down Expand Up @@ -226,6 +230,7 @@ export const createCasesClientFactoryMockArgs = () => {
return {
securityPluginSetup: securityMock.createSetup(),
securityPluginStart: securityMock.createStart(),
securityServiceStart: securityServiceMock.createStart(),
spacesPluginStart: spacesMock.createStart(),
featuresPluginStart: featuresPluginMock.createSetup(),
actionsPluginStart: actionsMock.createStart(),
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cases/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export class CasePlugin
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
securityPluginSetup: this.securityPluginSetup!,
securityPluginStart: plugins.security,
securityServiceStart: core.security,
spacesPluginStart: plugins.spaces,
featuresPluginStart: plugins.features,
actionsPluginStart: plugins.actions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class EmailNotificationService implements NotificationService {
);

const uids = new Set(assignees.map((assignee) => assignee.uid));
const userProfiles = await this.security.userProfiles.bulkGet({ uids });
const userProfiles = await this.security.userProfiles.bulkGet({ uids }); // todo: access userProfiles from core security service start contract
const users = userProfiles.map((profile) => profile.user);

const to = users
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const MIN_PROFILES_SIZE = 0;

interface UserProfileOptions {
securityPluginSetup: SecurityPluginSetup;
securityPluginStart: SecurityPluginStart;
securityPluginStart: SecurityPluginStart; // TODO: Use core's UserProfileService
spaces?: SpacesPluginStart;
licensingPluginStart: LicensingPluginStart;
}
Expand Down Expand Up @@ -58,6 +58,7 @@ export class UserProfileService {
size?: number;
owners: string[];
}) {
// TODO: Use core's UserProfileService
return securityPluginStart.userProfiles.suggest({
name: searchTerm,
size,
Expand Down