Skip to content

Commit 00d4866

Browse files
authored
[7.x] Migrate authorization subsystem to the new platform. (#46145) (#50289)
1 parent be23dbb commit 00d4866

File tree

205 files changed

+7845
-7869
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

205 files changed

+7845
-7869
lines changed

src/core/server/http/http_server.mocks.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ interface RequestFixtureOptions {
3939
path?: string;
4040
method?: RouteMethod;
4141
socket?: Socket;
42+
routeTags?: string[];
4243
}
4344

4445
function createKibanaRequestMock({
@@ -49,6 +50,7 @@ function createKibanaRequestMock({
4950
query = {},
5051
method = 'get',
5152
socket = new Socket(),
53+
routeTags,
5254
}: RequestFixtureOptions = {}) {
5355
const queryString = querystring.stringify(query);
5456
return KibanaRequest.from(
@@ -61,10 +63,11 @@ function createKibanaRequestMock({
6163
method,
6264
url: {
6365
path,
66+
pathname: path,
6467
query: queryString,
6568
search: queryString ? `?${queryString}` : queryString,
6669
},
67-
route: { settings: {} },
70+
route: { settings: { tags: routeTags } },
6871
raw: {
6972
req: { socket },
7073
},

src/core/server/saved_objects/service/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface SavedObjectsLegacyService<Request = any> {
3434
addScopedSavedObjectsClientWrapperFactory: SavedObjectsClientProvider<
3535
Request
3636
>['addClientWrapperFactory'];
37+
setScopedSavedObjectsClientFactory: SavedObjectsClientProvider<Request>['setClientFactory'];
3738
getScopedSavedObjectsClient: SavedObjectsClientProvider<Request>['getClient'];
3839
SavedObjectsClient: typeof SavedObjectsClient;
3940
types: string[];

src/core/server/saved_objects/service/lib/scoped_client_provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class SavedObjectsClientProvider<Request = unknown> {
100100
this._wrapperFactories.add(priority, { id, factory });
101101
}
102102

103-
setClientFactory(customClientFactory: SavedObjectsClientFactory) {
103+
setClientFactory(customClientFactory: SavedObjectsClientFactory<Request>) {
104104
if (this._clientFactory !== this._originalClientFactory) {
105105
throw new Error(`custom client factory is already set, unable to replace the current one`);
106106
}

src/core/server/server.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,8 @@ export interface SavedObjectsLegacyService<Request = any> {
14921492
// (undocumented)
14931493
schema: SavedObjectsSchema;
14941494
// (undocumented)
1495+
setScopedSavedObjectsClientFactory: SavedObjectsClientProvider<Request>['setClientFactory'];
1496+
// (undocumented)
14951497
types: string[];
14961498
}
14971499

x-pack/legacy/plugins/actions/server/shim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface KibanaConfig {
4242
*/
4343
export type TaskManagerStartContract = Pick<TaskManager, 'schedule' | 'fetch' | 'remove'>;
4444
export type XPackMainPluginSetupContract = Pick<XPackMainPlugin, 'registerFeature'>;
45-
export type SecurityPluginSetupContract = Pick<SecurityPlugin, 'config' | 'registerLegacyAPI'>;
45+
export type SecurityPluginSetupContract = Pick<SecurityPlugin, '__legacyCompat'>;
4646
export type SecurityPluginStartContract = Pick<SecurityPlugin, 'authc'>;
4747
export type TaskManagerSetupContract = Pick<
4848
TaskManager,

x-pack/legacy/plugins/alerting/server/shim.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export interface Server extends Legacy.Server {
4141
* Shim what we're thinking setup and start contracts will look like
4242
*/
4343
export type TaskManagerStartContract = Pick<TaskManager, 'schedule' | 'fetch' | 'remove'>;
44-
export type SecurityPluginSetupContract = Pick<SecurityPlugin, 'config' | 'registerLegacyAPI'>;
44+
export type SecurityPluginSetupContract = Pick<SecurityPlugin, '__legacyCompat'>;
4545
export type SecurityPluginStartContract = Pick<SecurityPlugin, 'authc'>;
4646
export type XPackMainPluginSetupContract = Pick<XPackMainPlugin, 'registerFeature'>;
4747
export type TaskManagerSetupContract = Pick<

x-pack/legacy/plugins/reporting/export_types/common/execute_job/get_custom_logo.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ export const getCustomLogo = async ({
2525
// We use the basePath from the saved job, which we'll have post spaces being implemented;
2626
// or we use the server base path, which uses the default space
2727
getBasePath: () => job.basePath || serverBasePath,
28+
path: '/',
29+
route: { settings: {} },
30+
url: {
31+
href: '/',
32+
},
33+
raw: {
34+
req: {
35+
url: '/',
36+
},
37+
},
2838
};
2939

3040
const savedObjects = server.savedObjects;

x-pack/legacy/plugins/reporting/export_types/csv/server/execute_job.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ function executeJobFn(server) {
5353
// We use the basePath from the saved job, which we'll have post spaces being implemented;
5454
// or we use the server base path, which uses the default space
5555
getBasePath: () => basePath || serverBasePath,
56+
path: '/',
57+
route: { settings: {} },
58+
url: {
59+
href: '/',
60+
},
61+
raw: {
62+
req: {
63+
url: '/',
64+
},
65+
},
5666
};
5767

5868
const callEndpoint = (endpoint, clientParams = {}, options = {}) => {

x-pack/legacy/plugins/reporting/server/lib/get_user.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,19 @@
55
*/
66

77
import { oncePerServer } from './once_per_server';
8-
import { getClient as getShieldClient } from '../../../../server/lib/get_client_shield';
98

109
function getUserFn(server) {
11-
const callShieldWithRequest = getShieldClient(server).callWithRequest;
12-
13-
return async function getUser(request) {
14-
const xpackInfo = server.plugins.xpack_main.info;
15-
if (xpackInfo && xpackInfo.isAvailable() && xpackInfo.feature('security').isEnabled()) {
16-
try {
17-
return await callShieldWithRequest(request, 'shield.authenticate');
18-
} catch (err) {
19-
server.log(['reporting', 'getUser', 'debug'], err);
20-
return null;
21-
}
10+
return async request => {
11+
if (!server.plugins.security) {
12+
return null;
2213
}
2314

24-
return null;
15+
try {
16+
return await server.plugins.security.getUser(request);
17+
} catch (err) {
18+
server.log(['reporting', 'getUser', 'debug'], err);
19+
return null;
20+
}
2521
};
2622
}
2723

x-pack/legacy/plugins/reporting/server/routes/lib/__tests__/authorized_user_pre_routing.test.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('authorized_user_pre_routing', function () {
1515
// so createMockServer reuses the same 'instance' of the server and overwrites
1616
// the properties to contain different values
1717
const createMockServer = (function () {
18-
const callWithRequestStub = sinon.stub();
18+
const getUserStub = sinon.stub();
1919
let mockConfig;
2020

2121
const mockServer = {
@@ -30,13 +30,7 @@ describe('authorized_user_pre_routing', function () {
3030
log: function () {},
3131
plugins: {
3232
xpack_main: {},
33-
elasticsearch: {
34-
createCluster: function () {
35-
return {
36-
callWithRequest: callWithRequestStub
37-
};
38-
}
39-
}
33+
security: { getUser: getUserStub },
4034
}
4135
};
4236

@@ -57,8 +51,8 @@ describe('authorized_user_pre_routing', function () {
5751
}
5852
};
5953

60-
callWithRequestStub.resetHistory();
61-
callWithRequestStub.returns(Promise.resolve(user));
54+
getUserStub.resetHistory();
55+
getUserStub.resolves(user);
6256
return mockServer;
6357
};
6458
}());

0 commit comments

Comments
 (0)