Skip to content

Commit

Permalink
Add constants and specify types (#1144)
Browse files Browse the repository at this point in the history
Signed-off-by: Chang Liu <[email protected]>
  • Loading branch information
cliu123 authored Oct 17, 2022
1 parent 6a823da commit 736a1d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
9 changes: 6 additions & 3 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ const APP_ID_DASHBOARDS = 'dashboards';
// OpenSearchDashboards app is for legacy url migration
const APP_ID_OPENSEARCH_DASHBOARDS = 'kibana';
const APP_LIST_FOR_READONLY_ROLE = [APP_ID_HOME, APP_ID_DASHBOARDS, APP_ID_OPENSEARCH_DASHBOARDS];
const GLOBAL_TENANT_RENDERING_TEXT = 'Global';
const PRIVATE_TENANT_RENDERING_TEXT = 'Private';
const GLOBAL_TENANT = '';

export class SecurityPlugin
implements
Expand Down Expand Up @@ -166,10 +169,10 @@ export class SecurityPlugin
dataType: 'string',
render: (value: any[][]) => {
let text = value[0][0];
if (text === null || text === '') {
text = 'Global';
if (text === null || text === GLOBAL_TENANT) {
text = GLOBAL_TENANT_RENDERING_TEXT;
} else if (text.startsWith('__user__')) {
text = 'Private';
text = PRIVATE_TENANT_RENDERING_TEXT;
}
text = i18n.translate('savedObjectsManagement.objectsTable.table.columnTenantName', {
defaultMessage: text,
Expand Down
7 changes: 4 additions & 3 deletions server/auth/types/authentication_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
IOpenSearchDashboardsResponse,
AuthResult,
} from 'opensearch-dashboards/server';
import { any } from 'joi';
import { SecurityPluginConfigType } from '../..';
import { SecuritySessionCookie } from '../../session/security_cookie';
import { SecurityClient } from '../../backend/opensearch_security_client';
Expand Down Expand Up @@ -101,6 +102,7 @@ export abstract class AuthenticationType implements IAuthenticationType {
}

const authState: OpenSearchDashboardsAuthState = {};
const globalTenant = '';

// if browser request, auth logic is:
// 1. check if request includes auth header or paramter(e.g. jwt in url params) is present, if so, authenticate with auth header.
Expand All @@ -126,7 +128,7 @@ export abstract class AuthenticationType implements IAuthenticationType {
}

this.sessionStorageFactory.asScoped(request).set(cookie);
} catch (error) {
} catch (error: any) {
return response.unauthorized({
body: error.message,
});
Expand All @@ -135,7 +137,7 @@ export abstract class AuthenticationType implements IAuthenticationType {
// no auth header in request, try cookie
try {
cookie = await this.sessionStorageFactory.asScoped(request).get();
} catch (error) {
} catch (error: any) {
this.logger.error(`Error parsing cookie: ${error.message}`);
cookie = undefined;
}
Expand Down Expand Up @@ -183,7 +185,6 @@ export abstract class AuthenticationType implements IAuthenticationType {

// set tenant in header
if (this.config.multitenancy.enable_aggregation_view) {
const globalTenant = '';
// Store all saved objects in a single kibana index.
Object.assign(authHeaders, { securitytenant: globalTenant });
} else {
Expand Down

0 comments on commit 736a1d9

Please sign in to comment.