Skip to content

Commit

Permalink
Added support for ltpa token
Browse files Browse the repository at this point in the history
Signed-off-by: enam-khan <[email protected]>
  • Loading branch information
enamkhan committed Jan 29, 2025
1 parent b51d5c2 commit 2604115
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
5 changes: 4 additions & 1 deletion packages/vsce/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ export async function activate(context: ExtensionContext) {
try {
plexExpansionHandler(node.element, treeDataProv);
} catch (error) {
const newSessionTree = new CICSSessionTree(node.element.getParent().profile, getIconFilePathFromName("profile-disconnected"));
const newSessionTree = new CICSSessionTree(
node.element.getParent().profile,
node.element.getParent().getSession(),
getIconFilePathFromName("profile-disconnected"));
treeDataProv.loadedProfiles.splice(treeDataProv.getLoadedProfiles().indexOf(node.element.getParent()), 1, newSessionTree);
treeDataProv._onDidChangeTreeData.fire(undefined);
}
Expand Down
28 changes: 19 additions & 9 deletions packages/vsce/src/trees/CICSSessionTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { CICSRegionTree } from "./CICSRegionTree";
import { CICSPlexTree } from "./CICSPlexTree";
import { imperative } from "@zowe/zowe-explorer-api";
import { getIconFilePathFromName } from "../utils/iconUtils";
import { Session, SessConstants } from "@zowe/imperative";

export class CICSSessionTree extends TreeItem {
children: (CICSPlexTree | CICSRegionTree)[];
Expand All @@ -23,20 +24,29 @@ export class CICSSessionTree extends TreeItem {

constructor(
profile: any,
session?: Session,
public readonly iconPath = getIconFilePathFromName("profile-unverified"),
) {
super(profile.name, TreeItemCollapsibleState.Collapsed);
this.children = [];
this.contextValue = `cicssession.${profile.name}`;
this.session = new imperative.Session({
type: "basic",
hostname: profile.profile!.host,
port: Number(profile.profile!.port),
user: profile.profile!.user || "",
password: profile.profile!.password || "",
rejectUnauthorized: profile.profile!.rejectUnauthorized,
protocol: profile.profile!.protocol,
});

if (session) {
this.session = session;
} else {
this.session = new imperative.Session({
type: profile.profile.useMFA ? SessConstants.AUTH_TYPE_TOKEN : SessConstants.AUTH_TYPE_BASIC,
storeCookie: profile.profile.useMFA,
tokenType: profile.profile.useMFA ? SessConstants.TOKEN_TYPE_LTPA : null,
hostname: profile.profile!.host,
port: Number(profile.profile!.port),
user: profile.profile!.user || "",
password: profile.profile!.password || "",
rejectUnauthorized: profile.profile!.rejectUnauthorized,
protocol: profile.profile!.protocol,
});
}

this.profile = profile;
this.isUnauthorized = undefined;
}
Expand Down
22 changes: 9 additions & 13 deletions packages/vsce/src/trees/CICSTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { openConfigFile } from "../utils/workspaceUtils";
import { CICSPlexTree } from "./CICSPlexTree";
import { CICSRegionTree } from "./CICSRegionTree";
import { CICSSessionTree } from "./CICSSessionTree";
import { SessConstants } from "@zowe/imperative";

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused import SessConstants.

export class CICSTree implements TreeDataProvider<CICSSessionTree> {
loadedProfiles: CICSSessionTree[] = [];
Expand Down Expand Up @@ -265,26 +266,21 @@ export class CICSTree implements TreeDataProvider<CICSSessionTree> {
profile = updatedProfile;
}
}
const plexInfo: InfoLoaded[] = await ProfileManagement.getPlexInfo(profile);

// Initialise session tree
newSessionTree = new CICSSessionTree(profile, getIconFilePathFromName("profile"));
newSessionTree = new CICSSessionTree(profile, undefined, getIconFilePathFromName("profile"));
const plexInfo: InfoLoaded[] = await ProfileManagement.getPlexInfo(profile, newSessionTree.getSession());

// For each InfoLoaded object - happens if there are multiple plexes
for (const item of plexInfo) {
// No plex
if (item.plexname === null) {
const session = new imperative.Session({
type: "basic",
hostname: profile.profile.host,
port: Number(profile.profile.port),
user: profile.profile.user,
password: profile.profile.password,
rejectUnauthorized: profile.profile.rejectUnauthorized,
protocol: profile.profile.protocol,
});
const regionsObtained = await getResource(session, {

const regionsObtained = await getResource(newSessionTree.getSession(), {
name: "CICSRegion",
regionName: item.regions[0].applid,
});

// 200 OK received
newSessionTree.setAuthorized();
const newRegionTree = new CICSRegionTree(
Expand Down Expand Up @@ -320,7 +316,7 @@ export class CICSTree implements TreeDataProvider<CICSSessionTree> {
this._onDidChangeTreeData.fire(undefined);
} catch (error) {
// Change session tree icon to disconnected upon error
newSessionTree = new CICSSessionTree(profile, getIconFilePathFromName("profile-disconnected"));
newSessionTree = new CICSSessionTree(profile, undefined, getIconFilePathFromName("profile-disconnected"));
// If method was called when expanding profile
if (sessionTree) {
this.loadedProfiles.splice(position, 1, newSessionTree);
Expand Down
11 changes: 11 additions & 0 deletions packages/vsce/src/utils/profileDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ const cicsProfileMeta: imperative.ICommandProfileTypeConfiguration[] = [
group: "Cics Connection Options",
},
},
useMFA: {
type: "boolean",
optionDefinition: {
name: "use-mfa",
aliases: ["ult"],
description: "Use MFA for authorization.",
type: "boolean",
defaultValue: false,
group: "Cics Connection Options",
},
},
},
required: [],
}
Expand Down
10 changes: 5 additions & 5 deletions packages/vsce/src/utils/profileManagement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

import { getCache, getResource } from "@zowe/cics-for-zowe-sdk";
import { Session } from "@zowe/imperative";
import { Session, SessConstants } from "@zowe/imperative";
import { imperative, Types, ZoweVsCodeExtension } from "@zowe/zowe-explorer-api";
import { window } from "vscode";
import { CICSPlexTree } from "../trees/CICSPlexTree";
Expand Down Expand Up @@ -58,7 +58,9 @@ export class ProfileManagement {
protocol: profile.protocol,
hostname: profile.host,
port: profile.port,
type: "basic",
type: profile.useMFA ? SessConstants.AUTH_TYPE_TOKEN : SessConstants.AUTH_TYPE_BASIC,
storeCookie: profile.useMFA,
tokenType: profile.useMFA ? SessConstants.TOKEN_TYPE_LTPA : null,
user: profile.user,
password: profile.password,
rejectUnauthorized: 'rejectUnauthorized' in profile ? profile.rejectUnauthorized : true,
Expand Down Expand Up @@ -264,9 +266,7 @@ export class ProfileManagement {
* @param profile
* @returns Array of type InfoLoaded
*/
public static async getPlexInfo(profile: imperative.IProfileLoaded): Promise<InfoLoaded[]> {

const session = this.getSessionFromProfile(profile.profile);
public static async getPlexInfo(profile: imperative.IProfileLoaded, session: Session): Promise<InfoLoaded[]> {

if (profile.profile.cicsPlex && profile.profile.regionName) {
return this.regionPlexProvided(session, profile.profile);
Expand Down

0 comments on commit 2604115

Please sign in to comment.