How to integrate VG in PowerBuilder?

How to use VG PB runtime API?

Estimated reading: 7 minutes 1458 views

The VG PB Runtime API is a specialized API designed to integrate Visual Guard (VG) functionalities into PowerBuilder (PB) applications at runtime. This API allows developers to interact programmatically with Visual Guard’s security features within a PowerBuilder environment, enabling dynamic management of user authentication, authorization, and permissions. This API is essential for developers looking to integrate advanced security features within their PowerBuilder applications, leveraging Visual Guard’s robust security framework.


Below are the codes you can use to retrieve specific information about Visual Guard entities


Repository information

If you want to get any repository related information then below are the functions you can use.

  • PB
guo_vgmanager.of_getinfo( 'repository' , 'version' )
guo_vgmanager.of_getinfo( 'repository' , 'name' )

User Information & User Attribute Information

Below are the functions you can use to get user related information.

  • PB
guo_vgmanager.of_getinfo( 'user' , 'name' )
guo_vgmanager.of_getinfo( 'userattr' , 'Firstname' )
guo_vgmanager.of_getinfo( 'userattr' , 'Lastname' )
guo_vgmanager.of_getinfo( 'userattr' , 'EmailAddress' )

Permissions of a User

If you want to know the permission of a user you can use the below functions.

  • PB
guo_vgmanager.of_getinfo( 'permission' , 'id' )
guo_vgmanager.of_getinfo( 'permission' , 'name' )
guo_vgmanager.of_getinfo( 'permission' , 'param' )
guo_vgmanager.of_getinfo( 'permission' , 'tag' )

Note: Blank means no permission assigned to user


Permission Set Assigned to a User

If you want to know what permission sets are assigned to your users then use the below methods to get the information.

  • PB
guo_vgmanager.of_getinfo( 'permissionset' , 'id' )
guo_vgmanager.of_getinfo( 'permissionset' , 'name' )

Note: Blank means no permission set assigned to user


Context Groups

You can use the below code to retrieve the context groups.

  • PB
Long nb, ii
String grpId[], grpName[], grpDesc[]
vg_n_group_ctx_list l_list_group_ctx

l_list_group_ctx = CREATE vg_n_group_ctx_list

guo_vgmanager.of_getAllContextGroups(l_list_group_ctx)

nb = l_list_group_ctx.of_rowCount()

FOR ii = 1 TO nb
	grpId[ii] = l_list_group_ctx.of_getgrpid(ii)
	grpName[ii] = l_list_group_ctx.of_getgrpname(ii)
	grpDesc[ii] = l_list_group_ctx.of_getgrpdisplayname(ii)
NEXT

Note: Blank means no context groups assigned to user


Groups

Use the below code to get the information about the groups in Visual guard.

  • PB
Long nb, ii
String grpId[], grpName[], grpDesc[]
vg_n_group_list l_list_group
l_list_group = CREATE vg_n_group_list
l_list_group = guo_vgmanager.of_getAllGroups()
nb = l_list_group.of_rowCount()

FOR ii = 1 TO nb
	grpId [ii] = l_list_group.of_getgrpid(ii)
	grpName[ii] = l_list_group.of_getgrpname(ii)
	grpDesc[ii] = l_list_group.of_getgrpdesc(ii)
	grpData1[ii] = l_list_group.of_getgrpdata1(ii)
	grpData2[ii] = l_list_group.of_getgrpdata2(ii)
	grpData3[ii] = l_list_group.of_getgrpdata3(ii)
NEXT

Note: Blank means no groups assigned to user 


Current Group

If you want the information of a specific current group then use the below code.

  • PB
Int ii, li_nb
String grpId, grpName, grpDesc
String grpData1, grpData2, grpData3
vg_n_group_ctx_list ListGroup
ListGroup = CREATE vg_n_group_ctx_list
guo_vgmanager.of_getAllContextGroups( ListGroup)
li_nb = ListGroup.of_rowcount( )

FOR ii = 1 TO li_nb
	IF NOT ListGroup.of_iscurrent( ) THEN CONTINUE

	grpId = ListGroup.of_getgrpid(ii )
	grpName = ListGroup.of_getgrpname(ii )
	grpDesc = ListGroup.of_getgrpdisplayname(ii)
	grpData1 = ListGroup.of_getgrpdata1(ii)
	grpData2 = ListGroup.of_getgrpdata2(ii)
	grpData3 = ListGroup.of_getgrpdata3(ii)
NEXT

Note: Blank means no groups assigned to user 

Roles

Below is the code to get the information about roles of a user.

  • PB
Boolean b_combinedRole
Long nb, ii
String roleId[], roleName[], roleTag[]
vg_n_role l_list_roles
l_list_roles = CREATE vg_n_role
b_combinedRole = guo_vgmanager.of_iscombineroles()
guo_vgmanager.of_getrole( l_list_roles)
nb = l_list_roles.of_rowcount( )

FOR ii = 1 TO nb
	roleId [ii] = l_list_roles.of_getRoleId(ii)
	roleName[ii] = l_list_roles.of_getRoleName(ii)
	roleTag[ii] = l_list_roles.of_getRoleTag(ii)
NEXT

Message in Event Viewer (Winconsole)

Use the below code to write a message in the event viewer in Winconsole.

  • PB
guo_vgmanager.of_writelog(String1, String2, EventID, TypeOfEvent) 

Here  the strings mean
String1 – title of the event message 
String2 – text of the event message 
EventID – A unique integer ID for the Event 
TypeOfEvent – 1: Critical, 2: Error, 4: Warning, 8: Information


Token Refresh of VG Server

You can use the below code to refresh the token of VG Server.

  • PB
guo_vgmanager.of_refresh_token( )

If User connected have more Group, show list of your group and select a new 

  • PB
Int ret

IF guo_vgmanager.of_getmodegroupselect( ) = vgValue.grp_mode_combi THEN
	Messagebox ( "Visual Guard information" , "Mode combined groups, no change group possible." )
	RETURN
END IF

IF NOT guo_vgmanager.of_hasgroup( ) THEN
	Messagebox ( "Visual Guard information" , "User has no group." )
	RETURN
END IF

// Show Selected Window Groups
ret = guo_vgmanager.of_show_window_group( )

IF ret < 0 THEN
	Messagebox ( "Visual Guard information" , "Error code: " + String (ret))
END IF

Verification of the connected User belonging to a Group

If you want to verify if a connected user belonging to a group then use the below code.

  • PB
IF sle_grp.text = "" THEN
	Messagebox ( "Error" , "Please write a Group Id or Group Name." )
	RETURN
END IF

IF guo_vgmanager.of_isingroup(sle_grp.text) THEN
	Messagebox ( "Information" , "User: " + guo_vgmanager.of_getinfo( "user" , "name" ) + "~r~n" + &
	" is connected with this Group: " + sle_grp.text + "." )
ELSE
	Messagebox ( "Error" , "User: " + guo_vgmanager.of_getinfo( "user" , "name" ) + "~r~n" + &
	" is not connected in this Group: " + sle_grp.text + "." )
END IF

Verification of the connected User having a Role

If you want to verify if a connected user has roles then use the below code.

  • PB
IF sle_role.text = "" THEN
	Messagebox ( "Error" , "Please write a Role Id or Role Name." )
	RETURN
END IF

IF guo_vgmanager.of_isinrole(sle_role.text) THEN
	Messagebox ( "Information" , "User : " + guo_vgmanager.of_getinfo( "user" , "name" ) + "~r~n" + &
	" is connected with this Role : " + sle_role.text + "." )
ELSE
	Messagebox ( "Error" , "User : " + guo_vgmanager.of_getinfo( "user" , "name" ) + "~r~n" + &
	" is not connected in this Role : " + sle_role.text + "." )
END IF

Verification of the connected User having a Permission

If you want to verify if a connected user has permission then use the below code.

  • PB
IF sle_permission.text = "" THEN
	Messagebox ( "Error" , "Please write a permission Id or permission Name." )
	RETURN
END IF

IF guo_vgmanager.of_haspermission(sle_permission.text) THEN
	Messagebox ( "Information" , "User : " + guo_vgmanager.of_getinfo( "user" , "name" ) + "~r~n" + &
	" is connected with this permission: " + sle_permission.text + "." )
ELSE
	Messagebox ( "Error" , "User : " + guo_vgmanager.of_getinfo( "user" , "name" ) + "~r~n" + &
	" is not connected in this permission : " + sle_permission.text + "." )
END IF

Verification of the connected User having a Group

If you want to verify if a connected user has a Group then use the below code.

  • PB
IF guo_vgmanager.of_hasgroup () THEN
	Messagebox ( "Information" , "User have group." )
ELSE
	Messagebox ( "Information" , "User have no group." )
END IF

Current AD User & User SID

Below is the code to get the current AD user and user SID information.

  • PB
Boolean lb_with_domain
Int li_ret
String ls_user, ls_user_sid

lb_with_domain = TRUE
li_ret = guo_vgmanager.of_getcurrentaduser( lb_with_domain, ls_user)
li_ret = guo_vgmanager.of_getcurrentsid( ls_user_sid)
Messagebox ( "User info" , "AD User: " + ls_user + "~r~nUser SID: " + ls_user_sid)

Current VG Token

If you want to know the current VG token then use the below code.

  • PB
guo_vgmanager.of_getvgtoken() 

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

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