Skip to content

Commit

Permalink
updated to add the tenant into the short URL once resolved
Browse files Browse the repository at this point in the history
Signed-off-by: leanneeliatra <[email protected]>
  • Loading branch information
leanneeliatra committed May 29, 2023
1 parent c4791f8 commit b872d31
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ import { setupMultitenantRoutes } from './multitenancy/routes';
import { defineAuthTypeRoutes } from './routes/auth_type_routes';
import { createMigrationOpenSearchClient } from '../../../src/core/server/saved_objects/migrations/core';
import { SecuritySavedObjectsClientWrapper } from './saved_objects/saved_objects_wrapper';
import { ensureRawRequest } from '../../../src/core/server/http/router';
import { ResponseObject } from '@hapi/hapi';
import { modifyUrl } from '../../../packages/osd-std/target';
import { GOTO_PREFIX } from '../../../src/plugins/share/common/short_url_routes';

export interface SecurityPluginRequestContext {
logger: Logger;
Expand Down Expand Up @@ -125,6 +129,22 @@ export class SecurityPlugin implements Plugin<SecurityPluginSetup, SecurityPlugi
);
core.http.registerAuth(auth.authHandler);

if (config.multitenancy?.enabled) {
core.http.registerOnPreResponse((request, preResponse, toolkit) => {
if (request.url.pathname.startsWith(`${GOTO_PREFIX}/`)) {
const rawRequest = ensureRawRequest(request);
const rawResponse = rawRequest.response as ResponseObject;
const modifiedUrl = modifyUrl(rawResponse.headers.location as string, (parts) => {
if (typeof parts.query.security_tenant === 'undefined') {
parts.query.security_tenant = request.headers.securitytenant as string;
} });
rawResponse.headers.location = modifiedUrl;
}

return toolkit.next();
});
}

// Register server side APIs
defineRoutes(router);
defineAuthTypeRoutes(router, config);
Expand Down

0 comments on commit b872d31

Please sign in to comment.