How to integrate ?

How to integrate VG in PowerBuilder?

Estimated reading: 7 minutes 3370 views

Integrating Visual Guard with PowerBuilder allows developers to incorporate authentication and authorization capabilities into their PowerBuilder applications. This integration enables applications to leverage Visual Guard’s security framework to manage user access, roles, and permissions, ensuring that users can access application features and resources based on their assigned security rights.


Prerequisites.

You need to have the below requirements to integrate Power Builder in Visual Guard

  • Minimum PowerBuilder version PB 2019R3
  • VGIdentityServer 2024
  • VGWinConsole 2024

To Integrate Visual Guard in your PowerBuilder application, you have to:

Step 1: Add the library of Visual Guard in library list of your target.

Step 2: Add the Dll of Visual Guard runtime in your directory project

Step 3: Integrate Visual Guard in the code of your application.

Step 4: Create a Visual Guard repository and declare your application by using the Visual Guard console. This repository will contain all security items (users, roles, permissions …) of your application.

Step 5: Generate the Visual Guard configuration files by using the Visual Guard console. These configuration files will be needed to connect your application to the repository.

Step 6: Grant read/write permissions to the repository.


Add Visual Guard pbl files in your application.

Step 1: Open the workspace of your project in PowerBuilder.

Step 2: In the solution explorer, expand the workspace node.

Step 3: Right-click the Target node for the workspace and select Properties from the shortcut menu.

Step 4: In Library List tab, select the 2 libraries Novalys.visualguard.security.pbrt.pbl, Novalys.visualguard.security.pbrte.pbl . Below is how you can find the PBLs.

  • Navigate to the Visual Guard installation directory.
  • Open the VG PB Runtime folder.
  • Select the folder corresponding to the PowerBuilder version you are using.
  • The required PBL files will be available in that folder.
    • Example path: C:\Program Files (x86)\Novalys\Visual Guard 202x.x\VisualGuardConsole\VG PB Runtime (Please note that the exact folder path may vary depending on your Visual Guard installation version and PowerBuilder version.)

Step 5: Click the OK button

Note:

  • Novalys.VisualGuard.Security.pbrt.pbl contains the main Visual Guard classes. The content of this PBL should not be modified by developers.
  • Novalys.VisualGuard.Security.pbrte.pbl contains the classes needed to extend the functionality of Visual Guard.
  • Novalys.VisualGuard.Security.pbrt.dll contains the base classes and SSO manager.

Generate your configuration file for connection to Visual Guard Repository.

  • Using Visual Guard Identity Server

OR

  • Without Using Visual Guard Server (Using VGPBClient – Local system)

Using Visual Guard Identity Server.

File configuration of PowerBuilder application.
Variable NameDescriptionValue
VGServerUrl of VGServer or VGidentityServerUrl sample
http://127.0.0.1:29000|http://127.0.0.1:29001
VGPBClient to communicate with VGRuntime (.Net)
portPort of the service Default is 80 for http, you can set 443 for https
ClientidOnly for VGIdenityServer <GUID>
SecretOnly for VGIdentityServer, encoded to base64
mergeRolesNeed to merge the rolesY= for yes
N= for no
supportedAuthenticationModesWhat type of authentification is supportedVG equals VisualGuard
AD equals Active Directory
WC equals Windows by credentials
PL equals PasswordLess authentication
Db equals Database authentication
silentModeY= for yes
N= for no
traceY= for yes
N= for no

PowerBuilder file configuration for IdentityServer.

  • INI
[SECURITY] 
VGServer=http://127.0.0.1:29000|http://127.0.0.1:29001 
ClientId=<Guid>
secret=<Password encoded to base64>
mergeRoles=Y 
supportedAuthenticationModes=VG|AD|WC 
dynamicBrowser=Y 
silentMode=Y 
trace=Y

Without Using Visual Guard Server (Using VGPBClient – Local system).

  • INI
[SECURITY] 
VGServer=VGPBClient 
TraceServeur=Y (or N, to delete or no files exchange with VGPBClient for tracing execution).

Note:

  1. The program VGPBClient.exe and it’s dependencies must be copied in the current directory of the secured
    PowerBuilder application. (Or in a path accessible by it).  
  • Novalys.VisualGuard.Security.dll
  • Novalys.VisualGuard.Security.SQLServer.dll Or Novalys.VisualGuard.Security.Oracle.dll

2. The VisualGuardConfiguration.config file of this program (VGPBClient) should be made correctly:

Modify applicationId and connectionString with your values of application

  • applicationId=”7e6b1582-9229-451a-a615-22ec70933353″
  • connectionString=”server=YOURSERVERNAME\YOURSQLEXPRESS;initial catalog=visualguarddb;Trusted_Connection=True;”

3. The exchange files between PowerBuilder application and VGPBClient are generated, by default, in the directory: C:\ProgramData\Novalys\VisualGuard\FileTrsf


Integrate in your PowerBuilder Code.

Declare the Security Manager.

  • PB
// Declare the security manager as global variable 
vge_n_cst_vgmanager guo_vgmanager

Create the Security Manager.

  • PB
// Create the security manager 
guo_vgmanager = CREATE vge_n_cst_vgmanager

Destroy the Security Manager.

  • PB
// Destroy the security manager 
IF IsValid(guo_vgmanager) THEN
	DESTROY (guo_vgmanager)
END IF

Declare the Configuration file of the application (Optional).

  • PB
// Declare configuration file with your custom parameters to connect at Visual Guard Identity Server (Optional)
guo_vgmanager.of_setconfigfile ("myconfigfile.cfg")

Declare the Trace file of the application (Optional).

  • PB
// Declare the trace file if you use tracing action execution in your application (Optional)
guo_vgmanager.of_settracefile ("mytracefile.log")

Authenticate with Visual Guard.

Authenticating a user with Visual Guard login form.

  • PB
IF guo_vgmanager.of_openlogon() = 1 THEN
	RETURN 0
ELSE
	RETURN -1
END IF

Authenticating a user with Visual Guard in your own login form.

  • PB
// Authenticate a Visual Guard User and load the security data 
IF isvalid(guo_vgmanager) THEN
	IF guo_vgmanager.of_VerifyUser(VGlogin, VGpassword) > 0 THEN
		Open(w_Main)
	ELSE
		RETURN
	END IF
END IF

Authenticating a user using windows Single Sign-On (SSO).

  • PB
// Authenticate a Windows User and load the security data 
IF isvalid(guo_vgmanager) THEN
	IF guo_vgmanager.of_VerifyUser() > 0 THEN
		Open(w_Main)
	ELSE
		RETURN
	END IF
END IF

Authenticating a user with your own login form and window credential.

  • PB
// Authenticate a Windows By Credential User and load the security data 
IF isvalid(guo_vgmanager) THEN
	IF guo_vgmanager.of_VerifyUser(VGlogin, VGpassword, vg_n_authenticationmode.windowsbycredential) > 0 THEN
		Open(w_Main)
	ELSE
		RETURN
	END IF
END IF

How to get the bearer token?

To manually use the API provided by the VG Identity Server, you must use the bearer token provided by the VG Runtime after authentication.

  • PB
guo_vgmanager.of_getbearertoken()

This API allows you to:

  • Check that the Visual Guard account, the Windows account, and the Windows By Credential account exist.
  • Check that the user password is valid (Visual Guard account only)
  • Check that the user has a valid profile for this application
  • Load the application security related to the account profile

Secure Application Components.

  • CallingObject: The main object from which you apply the security, usually the window
  • CallingID: A string identifier to differentiate many calls from the same object
  • Parameters: A string containing one or more parameters to send to the security manager

In general, this function is called in the open event of the ancestor window:

  • PB
// Trigger the security in the open Event of the ancestor window 
IF isvalid(guo_vgmanager) THEN
	guo_vgmanager.of_SetSecurity( this, "open" , "" )
END IF

For the PFC, add the following code:

  • Open
  • Postinit
  • Constructor
// In the event ?w_master.pfc_preopen? in ?pfemain.pbl?: 
IF IsValid(guo_vgmanager) THEN
	guo_vgmanager.of_SetSecurity ( this, "open" , "" )
END IF
// In the event ?w_master.pfc_postopen? in ?pfemain.pbl?: 
if IsValid(guo_vgmanager) Then 
     guo_vgmanager.of_SetSecurity ( this, "postinit ", "") 
End if
// In the event ?u_dw.Constructor? in ?pfemain.pbl?: 
if IsValid(guo_vgmanager) Then 
    guo_vgmanager.of_SetSecurity ( this, "constructor ", "") 
End if

How to change the password?

To change the password in PB, we need to call the below method of VG Runtime by passing the old and new passwords once inside the application after initial authentication.

  • PB
// Call Change PassWord of Visual Guard Server
ret = guo_vgmanager.of_changepassword( ls_old, ls_new)
//IF ret = 1 Then Messagebox ("VGServer Change Password", "Password as being changed.")
IF ret <> 1 THEN
	guo_vgmanager.of_geterrvg( li_err, ls_err)
	Messagebox ( "Visual Guard Error" , "Error N° " + String (li_err) + "~rText :  " + ls_err)
END IF

These are the return values from the above method;

ValueStatus
1Success
2Failure
6OldPasswordDoesNotMatch
8LastBadLogin
16AccountIsLockedOut
32PasswordConfimrationDoesNotMatch
64UserNotFound
128NewPasswordDoesNotPassValidation
256PasswordAnswerDoesNotMatch