How to use VG PB runtime API?

Estimated reading: 7 minutes 63 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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

guo_vgmanager.of_refresh_token( )

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

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.

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.

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 Group

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

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.

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.

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.

// 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