Skip to content

Commit

Permalink
Uses enum instead of magic constant
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Apr 9, 2024
1 parent 7b68f1c commit 2a1289d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions server/auth/types/authentication_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { SecuritySessionCookie } from '../../session/security_cookie';
import { SecurityClient } from '../../backend/opensearch_security_client';
import { resolveTenant, isValidTenant } from '../../multitenancy/tenant_resolver';
import { UnauthenticatedError } from '../../errors';
import { GLOBAL_TENANT_SYMBOL } from '../../../common';
import { AuthType, GLOBAL_TENANT_SYMBOL } from '../../../common';

export interface IAuthenticationType {
type: string;
Expand Down Expand Up @@ -210,7 +210,7 @@ export abstract class AuthenticationType implements IAuthenticationType {
}
}
if (!authInfo) {
const authRequestType = cookie.isAnonymousAuth ? 'anonymous' : cookie.authType;
const authRequestType = cookie.isAnonymousAuth ? AuthType.ANONYMOUS : cookie.authType;
authInfo = await this.securityClient.authinfo(request, authRequestType, authHeaders);
}
authState.authInfo = authInfo;
Expand Down Expand Up @@ -244,7 +244,7 @@ export abstract class AuthenticationType implements IAuthenticationType {
authHeader: any,
authInfo: any
): Promise<string | undefined> {
const authType = cookie.isAnonymousAuth ? 'anonymous' : cookie.authType;
const authType = cookie.isAnonymousAuth ? AuthType.ANONYMOUS : cookie.authType;
if (!authInfo) {
try {
authInfo = await this.securityClient.authinfo(request, authType, authHeader);
Expand Down
6 changes: 5 additions & 1 deletion server/auth/types/basic/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ export class BasicAuthRoutes {
}
context.security_plugin.logger.info('The Redirect Path is ' + redirectUrl);
try {
user = await this.securityClient.authenticateWithHeaders(request, 'anonymous', {});
user = await this.securityClient.authenticateWithHeaders(
request,
AuthType.ANONYMOUS,
{}
);
} catch (error) {
context.security_plugin.logger.error(
`Failed authentication: ${error}. Redirecting to Login Page`
Expand Down
7 changes: 6 additions & 1 deletion server/readonly/readonly_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
isPrivateTenant,
LOGIN_PAGE_URI,
CUSTOM_ERROR_PAGE_URI,
AuthType,
} from '../../common';
import { SecurityClient } from '../backend/opensearch_security_client';
import { IAuthenticationType, OpenSearchAuthInfo } from '../auth/types/authentication_type';
Expand Down Expand Up @@ -104,7 +105,11 @@ export class ReadonlyService extends BaseReadonlyService {
return false;
}

const authType = cookie ? (cookie.isAnonymousAuth ? 'anonymous' : cookie.authType) : '';
const authType = cookie
? cookie.isAnonymousAuth
? AuthType.ANONYMOUS
: cookie.authType
: '';
const authInfo = await this.securityClient.authinfo(request, authType, headers);

if (!authInfo.user_requested_tenant && cookie) {
Expand Down

0 comments on commit 2a1289d

Please sign in to comment.