Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@
"Save": "Enregistrer",
"More": "Plus",
"SaveFailed": "Impossible d’enregistrer le script",
"DeleteConfirm": "Supprimer « {name} » ?",
"DeleteFailed": "Impossible de supprimer le script",
"FillBatchCommand": "Insérer dans la commande par lot",
"GroupShell": "Shell",
"GroupPowerShell": "PowerShell",
Expand Down
8 changes: 8 additions & 0 deletions ui/composables/useApiRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,14 @@ export function getAccountDetail(accountId: string, orgId?: string): Promise<Per
});
}

export function getPersonalAssetCredential(credentialId: string, orgId?: string): Promise<PersonalAssetCredential> {
return apiRequest({
method: "GET",
path: `/api/v1/accounts/personal-asset-credentials/${encodeURIComponent(credentialId)}/`,
orgId
});
}

export async function getPersonalAssetCredentials(
assetId: string,
protocol: string,
Expand Down
57 changes: 56 additions & 1 deletion ui/composables/useSessionWindowConnect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import type { AssetDetail, AssetItem, PermedAccount, PermOrgItem, RdpGraphics } from "~/types";
import { getAccountDetail, getAssetDetailRequest, getConsoleAssetDetail } from "~/composables/useApiRequest";
import {
getAccountDetail,
getAssetDetailRequest,
getConsoleAssetDetail,
getPersonalAssetCredential
} from "~/composables/useApiRequest";
import { desktopInvoke } from "~/shared/desktop/bridge";
import { useUserInfoStore } from "~/store/modules/userInfo";
import { transformAssetDetail } from "~/utils";
Expand All @@ -11,6 +16,7 @@
account: string;
manualUsername: string;
manualPassword: string;
personalCredentialId?: string;
dynamicPassword: string;
rememberSecret: boolean;
rememberSelection?: boolean;
Expand Down Expand Up @@ -122,6 +128,9 @@
query.set("accountMode", connectionInfo.accountMode);
if (connectionInfo.accountId) query.set("accountId", connectionInfo.accountId);
if (connectionInfo.connectMethod) query.set("method", connectionInfo.connectMethod);
if (connectionInfo.accountMode === "manual" && connectionInfo.personalCredentialId) {
query.set("personalCredentialId", connectionInfo.personalCredentialId);
}

return `/session/${encodeURIComponent(asset.id)}?${query.toString()}`;
}
Expand Down Expand Up @@ -162,6 +171,7 @@

export function useSessionWindowConnect() {
const route = useRoute();
const { t } = useI18n();
const { activeTab, openSession, openSetupSession } = useWorkspaceTabs();
const { confirmConnection } = useAssetConnection();
const userInfoStore = useUserInfoStore();
Expand Down Expand Up @@ -214,6 +224,51 @@
asset.savedConnection = saved || undefined;
assetName.value = asset.name || "JumpServer";

// An explicit credential must never fall back to a remembered account.
if (route.query.personalCredentialId !== undefined) {
const credentialId = queryValue(route.query.personalCredentialId);
if (admin || !credentialId) throw new Error(t("ConnectError.PersonalCredentialNotFound"));

const credential = await getPersonalAssetCredential(credentialId, orgId);
if (credential.asset.id !== assetId || !credential.is_active || !credential.has_secret) {
throw new Error(t("ConnectError.PersonalCredentialNotFound"));
}
const protocol = typeof credential.protocol === "string" ? credential.protocol : credential.protocol.value;
if (
!asset.permedProtocols?.some(
(item) => item.name === protocol && (isDesktopRuntime() || item.public !== false)
)
) {
throw new Error(t("ConnectError.ProtocolUnavailable"));
}
if (!asset.permedAccounts?.some((account) => account.alias === "@INPUT")) {
throw new Error(t("ConnectError.ManualAccountDenied"));
}
const preferred =
preference?.protocol === protocol ? preference : saved?.protocol === protocol ? saved : undefined;

Check warning on line 248 in ui/composables/useSessionWindowConnect.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Extract this nested ternary operation into an independent statement.

See more on https://sonarcloud.io/project/issues?id=jumpserver_luna&issues=AaC-Fc57_s_fzfLygGMN&open=AaC-Fc57_s_fzfLygGMN&pullRequest=1710
const connectMethod = queryValue(route.query.method) || preferred?.connectMethod || "";
const pane = openSession(asset, { protocol, account: credential.username, connectMethod });
await confirmConnection(asset, {
protocol,
account: "@INPUT",
accountMode: "manual",
manualUsername: credential.username,
manualPassword: "",
personalCredentialId: credential.id,
personalCredentialVersion: credential.version,
personalCredentialSecretType:
typeof credential.secret_type === "string" ? credential.secret_type : credential.secret_type.value,
savePersonalCredential: false,
dynamicPassword: "",
rememberSecret: false,
preserveStoredSelection: true,
connectMethod,
connectOptions: preferred?.connectOptions || {},
tabId: pane.id
});
return;
}

const reusableSavedConnection = !admin && hasReusableSavedConnection(asset);
const connection = { ...(saved || {}), ...(preference || {}), ...(routeConnection || {}) };
const queryNeedsNoSecret = routeConnection && ["hosted", "anonymous"].includes(routeConnection.accountMode);
Expand Down
Loading