1. Yuri Denshchik
  2. PowerBuilder
  3. Friday, 8 November 2019 18:40 PM UTC

Hello, 

Does anybody tried to authenticate a user with Windows credentials in PowerBuilder? 

We are looking for an option when user can login to PB App without entering a password with Windows credentials 

Thank you,

Yuri

 

John Raghanti Accepted Answer Pending Moderation
  1. Friday, 8 November 2019 19:39 PM UTC
  2. PowerBuilder
  3. # 1

We have a local application for logging client information. Not all of our employees need to access all parts of the application.

We don't do windows authentication, per-se, but we use their login name to determine if they have access.

Global external function:

Function long GetUserNameA(ref String lbBuffer, ref Long nSize) library "advapi32.dll" alias for "GetUserNameA;Ansi"

 

Code to access name:

long lb_retval
long ll_buffer
string ls_buffer

ls_buffer = space(200)
ll_buffer = len(ls_buffer) - 1

lb_retval = GetUserNameA(ls_buffer, ll_buffer)

if lb_retval = 0 then
      ls_buffer = left(ls_buffer, ll_buffer)
end if

return ls_buffer

Comment
There are no comments made yet.
Ashutosh Varshney Accepted Answer Pending Moderation
  1. Friday, 8 November 2019 19:58 PM UTC
  2. PowerBuilder
  3. # 2

Yuri,

You can use the winapi function LogonUser.

Also check out Chris's LDAP service:

https://answers.sap.com/questions/11825718/powerbuilder-115--ldap-authentication-active-direc.html

HTH

 

Comment
There are no comments made yet.
Michael Kramer Accepted Answer Pending Moderation
  1. Friday, 8 November 2019 22:15 PM UTC
  2. PowerBuilder
  3. # 3

Another but similar approach: single sign-on to MSSQL and obtain identities from DB server. Example below uses ADO.NET and the AdventureWorks database. This sample also does impersonation (albeit you have to create the user = DEMO yourself)

Enjoy /Michael

string dbServer = "(localdb)\ProjectsV13"
string dbName = "AdventureWorks"

// Login credentials: Single sign-on or Login/password
boolean singleSignOn = true
string loginID, loginPWD
string roleUser = "Demo" // To impersonate
// - - - - - - - - - - - - - - - - - - - - - - - - - -
string OS_Login, DB_Login, DB_User

// Setup DB connection
SQLCA.DBMS = "ADO"
SQLCA.DBParm  = "Namespace='System.Data.SqlClient'"
SQLCA.DBParm += ",DataSource='" + dbServer + "'"
SQLCA.DBParm += ",Database='" + dbName + "'"
SQLCA.DBParm += ",DisableBind=0"    // Avoid SQL injection

if singleSignOn then
   SQLCA.DBParm += ",TrustedConnection=1"
else
   SQLCA.LogID = loginID
   SQLCA.LogPass = loginPWD
end if

// DB Logon - - - - - - - - - - - - - - -
CONNECT USING SQLCA;
EXECUTE IMMEDIATE "EXECUTE AS USER='" + roleUser + "';" USING SQLCA;

// Query Identities - - - - - - - - - - -
SELECT   OS_Login,  DB_Login,  DB_User
   INTO :OS_Login, :DB_Login, :DB_User
   FROM (SELECT ORIGINAL_LOGIN() [OS_Login]
              , SUSER_NAME()     [DB_Login]
              , USER_NAME()      [DB_User]
        ) data
   USING SQLCA;

// DB Logoff  - - - - - - - - - - - - - -
EXECUTE IMMEDIATE "REVERT;" USING SQLCA; // Stop impersonation
ROLLBACK USING SQLCA;
DISCONNECT USING SQLCA;

 

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.