Salesforce

How to create a CP usable by both ABL clients and browsers.

« Go Back

Information

 
TitleHow to create a CP usable by both ABL clients and browsers.
URL NameHow-to-create-a-CP-usable-by-both-ABL-clients-and-browsers
Article Number000116295
EnvironmentProduct: OpenEdge
Version: 11.7.x
OS: Windows
Other: clientprincipal
Question/Problem Description
Application has been around for a while and the current interface is an ABL client. The application is being enhanced to include a .NET control that creates Google Chrome browsers. How can a clientprincipal be created that can be used by both web browsers and ABL clients?
 
Steps to Reproduce
Clarifying Information
Error Message
Defect Number
Enhancement Number
Cause
Resolution
Basic steps:
1) Connect to the PAS instance using httpclient.
2) PAS instance creates a clientprincipal.
3) PAS returns the clientprincipal in the body of the httpclient response as a base64-encoded clientprincipal.
4) The base64-encoded clientprincipal is decoded and added to a clientprincipal handle.
5) The httpclient response includes a cookie names JSESSIONID. This JSESSIONID cookie can be used by browsers for accessing the PAS instance.

In this case form authentication is being used.
The default user of restuser in the users.properties file is used.
 
The following variables are used in the code below:
DEFINE VARIABLE oRequestBody AS String NO-UNDO.
DEF    VAR      oReq     AS IHttpRequest     NO-UNDO.
DEF    VAR      oResp    AS IHttpResponse    NO-UNDO.
DEFINE VARIABLE oJsonEntity AS JsonObject NO-UNDO.
DEFINE VARIABLE myLongchar AS LONGCHAR   NO-UNDO.
DEFINE VARIABLE myCPHandle  AS HANDLE NO-UNDO.
DEFINE VARIABLE myRaw       AS RAW NO-UNDO.
DEFINE VARIABLE myMemptr    AS MEMPTR NO-UNDO.
DEFINE VARIABLE hApplicationServer AS HANDLE    NO-UNDO.
DEFINE VARIABLE cConnectionString  AS CHARACTER NO-UNDO.



Use an httpclient to post to url "http://localhost:8810/static/auth/j_spring_security_check".

/* create a body to hold the username and password to go with the httpclient request */
oRequestBody = NEW String("j_username=restuser&j_password=password").

/*Authentication request*/
oReq = RequestBuilder:POST("http://localhost:8810/static/auth/j_spring_security_check", oRequestBody)
    :ContentType('application/x-www-form-urlencoded')
    :AcceptJson()    
    :Request.


/* make the request, and accept the response */
oResp =  ClientBuilder:Build():Client:Execute(oReq).

The JSON response contains a JSON object with the following attributes:
access_token : this is the clientprincipal token base64-encoded.
refresh_token: token to be used to refresh the CP before it expires.
token_type: "oecp"
expires_in: time after which CP expires (in seconds).

Extract the JSON object from the response.

oJsonEntity = CAST(oResp:Entity, JsonObject).
oJsonEntity:Write(JsonString, TRUE).


 Extract the base64-encoded clientprincipal from the JSON object.

/* extract the CP from the JSON object */
myLongChar = oJsonEntity:GetLongchar("access_token").

BASE64-DECODE the clientprincipal.

/* now decode the CP */
myMemptr = BASE64-DECODE(myLongChar).

Turn the MEMPTR that the clientprincipal is stored in, into a RaW variable as required by IMPORT-PRINCIPAL.

/* move the CP to a raw variable */
myRaw = myMemptr.


Create a clientprincipal handle and import the decoded clientprincipal into the handle.

/* create a clintprincipal to be used by ABL clients */
CREATE CLIENT-PRINCIPAL myCPHandle.

/* import the decoded CP into the CP handle, making it a usable CP */
myCPHandle:IMPORT-PRINCIPAL (myRaw).

At this point myCPHandle is a valid clientprincipal and is a copy of the clientprincipal created by the PAS instance by virtue of the httpclient API call.

Create a server handle and use the clientprincipal created above to set the clientprincipal for server connections to a PAS instance.
/* create an application server */
CREATE SERVER hApplicationServer.

MESSAGE "Attempting connect with PAS OE" VIEW-AS ALERT-BOX.
cConnectionString = "-URL http://localhost:8810/apsv".


// Set the client principal we got from httpclient as the request's client principal
hApplicationServer:REQUEST-INFO:SETCLIENTPRINCIPAL (myCPHandle).

 
Workaround
Notes

References to other Documentation:

https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/setclientprincipal(-)-method.html
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/create-server-statement.html
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/import-principal(-)-method.html
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/create-client-principal-statement.html
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/base64-decode-function.html
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/getlongchar(-)-method-(jsonobject).html
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvpin/openedge.net.http.httpclient.html
https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvpin/openedge.net.http.ihttprequest.html

The attached zip file test.zip contains four files, as follows:
test_connector.p - uses httpclient to connect to a PAS instance, have the PAS instance create a CP and get the CP back as a base-64 encoded CP. base64 decodes the CP and creates a CP handle with the decoded CP.

test_acceptor.p - procedure that runs on the PAS instance and access a sports 2000 database.
myConnectorProc.p - Connection procedure that runs when test_connector.p connects to the PAS instance.
oeablSecurity.properties - oeablSecurity.properties file used to test the other files.

Progress Article(s):
 Is there an HTTP client for OpenEdge?

 

Keyword Phrase
Last Modified Date11/20/2020 7:01 AM

Powered by