Skip to content

Commit

Permalink
Don't attempt to open the SMP in a Simple Browser for IRIS 2024.1+ (#223
Browse files Browse the repository at this point in the history
)
  • Loading branch information
isc-bsaviano authored May 29, 2024
1 parent 0fe86bf commit 123c23d
Showing 1 changed file with 39 additions and 26 deletions.
65 changes: 39 additions & 26 deletions src/api/getPortalUriWithToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,50 +27,63 @@ export async function getPortalUriWithToken(
const spec: IServerSpec | undefined = await myApi.getServerSpec(name, scope);
if (typeof spec !== "undefined") {

// Retrieve previously cached token
let token = allTokens[target].get(name) || "";

// Revalidate and extend existing token, or obtain a new one
const response = await makeRESTRequest(
"POST",
spec,
{ apiVersion: 1, namespace, path: "/action/query" },
{ query: "select %Atelier_v1_Utils.General_GetCSPToken(?, ?) token", parameters: [page, token] },
);

if (!response) {
// User will have to enter credentials
token = "";
allTokens[target].delete(name);
} else {
token = response.data?.result?.content[0]?.token || "";
allTokens[target].set(name, token);
}

if (target === BrowserTarget.SIMPLE && !simpleBrowserCompatible.has(name)) {
// Check that the portal webapps have all been altered so they don't require session cookie support, which Simple Browser cannot provide
const response = await makeRESTRequest(
"POST",
spec,
{ apiVersion: 1, namespace: "%SYS", path: "/action/query" },
{ query: "SELECT Name FROM Security.Applications WHERE {fn CONCAT(Name, '/')} %STARTSWITH '/csp/sys/' AND UseCookies = 2" },
{
query:
"SELECT Name FROM Security.Applications WHERE {fn CONCAT(Name, '/')} %STARTSWITH '/csp/sys/' AND UseCookies = 2 " +
"UNION SELECT $PIECE($PIECE($PIECE($ZVERSION,') ',2),' '),'.') AS Name"
},
);
if (response) {
const appsRequiringCookie = (response.data?.result?.content as any[]).map((row) => {
return row.Name as string;
});
if (appsRequiringCookie.length > 0) {
await vscode.window.showWarningMessage(`Portal web apps cannot be used in the Simple Browser tab if their 'UseCookies' property is set to 'Always' (the default). To resolve this, use Portal's security section to change it to 'Autodetect' in these apps: ${appsRequiringCookie.join(", ")}`, { modal: true });
return;
if (appsRequiringCookie.length && parseInt(appsRequiringCookie[appsRequiringCookie.length - 1], 10) >= 2024) {
// SMP in 2024.1+ can't be embedded in a cross-origin iframe
vscode.window.showWarningMessage(`The Portal cannot be opened in the Simple Browser for IRIS versions 2024.1+.`, "Dismiss");
simpleBrowserCompatible.set(name, false);
}
else if (appsRequiringCookie.length > 1) {
vscode.window.showWarningMessage(`Portal web apps cannot be used in the Simple Browser tab if their 'UseCookies' property is set to 'Always' (the default). To resolve this, use Portal's security section to change it to 'Autodetect' in these apps: ${appsRequiringCookie.slice(0, -1).join(", ")}`, { modal: true });
}
else {
simpleBrowserCompatible.set(name, true);
}
}
else {
vscode.window.showWarningMessage(`Unable to check the Portal web apps for compatibility with Simple Browser.`);
simpleBrowserCompatible.set(name, true);
vscode.window.showWarningMessage(`Unable to check the Portal web apps for compatibility with Simple Browser.`, "Dismiss");
}
if (!simpleBrowserCompatible.get(name)) return;
}

if (target === BrowserTarget.SIMPLE && simpleBrowserCompatible.has(name) && !simpleBrowserCompatible.get(name)) {
vscode.window.showWarningMessage(`The Portal cannot be opened in the Simple Browser for IRIS versions 2024.1+.`, "Dismiss");
return;
}

// Retrieve previously cached token
let token = allTokens[target].get(name) || "";

// Revalidate and extend existing token, or obtain a new one
const response = await makeRESTRequest(
"POST",
spec,
{ apiVersion: 1, namespace, path: "/action/query" },
{ query: "select %Atelier_v1_Utils.General_GetCSPToken(?, ?) token", parameters: [page, token] },
);

if (!response) {
// User will have to enter credentials
token = "";
allTokens[target].delete(name);
} else {
token = response.data?.result?.content[0]?.token || "";
allTokens[target].set(name, token);
}

const webServer = spec.webServer;
Expand Down

0 comments on commit 123c23d

Please sign in to comment.