diff --git a/src/ops/ApplicationOps.ts b/src/ops/ApplicationOps.ts index 6dd972207..5b4b6bb67 100644 --- a/src/ops/ApplicationOps.ts +++ b/src/ops/ApplicationOps.ts @@ -435,11 +435,18 @@ export function createApplicationExportTemplate({ } export function getRealmManagedApplication({ state }: { state: State }) { - let realmManagedOrg = 'application'; - if (state.getDeploymentType() === constants.CLOUD_DEPLOYMENT_TYPE_KEY) { - realmManagedOrg = `${getCurrentRealmName(state)}_application`; + let realmManagedApp = 'application'; + if ( + state.getDeploymentType() === constants.CLOUD_DEPLOYMENT_TYPE_KEY || + state.getUseRealmPrefixOnManagedObjects() === true + ) { + realmManagedApp = `${getCurrentRealmName(state)}_application`; + debugMessage({ + message: `DeploymentType === cloud or UseRealmPrefixOnManagedObjects is true, returning '${realmManagedApp}'`, + state: state, + }); } - return realmManagedOrg; + return realmManagedApp; } export async function createApplication({ diff --git a/src/ops/OrganizationOps.ts b/src/ops/OrganizationOps.ts index 6e4f56e05..7b71c4e99 100644 --- a/src/ops/OrganizationOps.ts +++ b/src/ops/OrganizationOps.ts @@ -2,6 +2,7 @@ import { IdObjectSkeletonInterface } from '../api/ApiTypes'; import { queryAllManagedObjectsByType } from '../api/ManagedObjectApi'; import Constants from '../shared/Constants'; import { State } from '../shared/State'; +import { debugMessage } from '../utils/Console'; import { FrodoError } from './FrodoError'; export type Organization = { @@ -53,8 +54,15 @@ export default (state: State): Organization => { */ export function getRealmManagedOrganization({ state }: { state: State }) { let realmManagedOrg = 'organization'; - if (state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY) { + if ( + state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY || + state.getUseRealmPrefixOnManagedObjects() === true + ) { realmManagedOrg = `${state.getRealm()}_organization`; + debugMessage({ + message: `DeploymentType === cloud or UseRealmPrefixOnManagedObjects is true, returning '${realmManagedOrg}'`, + state: state, + }); } return realmManagedOrg; } diff --git a/src/shared/State.ts b/src/shared/State.ts index 707ee6b77..121acc4d9 100644 --- a/src/shared/State.ts +++ b/src/shared/State.ts @@ -45,6 +45,8 @@ export type State = { getPassword(): string; setRealm(realm: string): void; getRealm(): string; + setUseRealmPrefixOnManagedObjects(useRealmPrefixOnManagedObjects: boolean): void; + getUseRealmPrefixOnManagedObjects(): boolean; setDeploymentType(type: string): void; getDeploymentType(): string; setAdminClientId(type: string): void; @@ -211,6 +213,13 @@ export default (initialState: StateInterface): State => { return state.realm || process.env.FRODO_REALM; }, + setUseRealmPrefixOnManagedObjects(useRealmPrefixOnManagedObjects: boolean) { + state.useRealmPrefixOnManagedObjects = useRealmPrefixOnManagedObjects; + }, + getUseRealmPrefixOnManagedObjects() { + return state.useRealmPrefixOnManagedObjects || false; + }, + setDeploymentType(type: string) { state.deploymentType = type; }, @@ -510,6 +519,7 @@ export interface StateInterface { username?: string; password?: string; realm?: string; + useRealmPrefixOnManagedObjects?: boolean; deploymentType?: string; adminClientId?: string; adminClientRedirectUri?: string; diff --git a/src/utils/ForgeRockUtils.ts b/src/utils/ForgeRockUtils.ts index c8e03cf80..f27da247d 100644 --- a/src/utils/ForgeRockUtils.ts +++ b/src/utils/ForgeRockUtils.ts @@ -1,6 +1,7 @@ import { getRealms } from '../ops/RealmOps'; import Constants from '../shared/Constants'; import { State } from '../shared/State'; +import { debugMessage } from '../utils/Console'; export type FRUtils = { applyNameCollisionPolicy(name: string): string; @@ -211,8 +212,15 @@ export function getCurrentRealmManagedUser({ state: State; }): string { let realmManagedUser = 'user'; - if (state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY) { + if ( + state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY || + state.getUseRealmPrefixOnManagedObjects() === true + ) { realmManagedUser = `${getCurrentRealmName(state)}_user`; + debugMessage({ + message: `DeploymentType === cloud or UseRealmPrefixOnManagedObjects is true, returning '${realmManagedUser}'`, + state: state, + }); } return realmManagedUser; }