Support Article
Unable to use Custom Authentication in Service package
Summary
Unable use custom authentication for Service package with the following requirements:
- Basic Authentication
- AccessGroup used should be determined by content in service payload
Error Messages
Not Applicable.
Steps to Reproduce
Unknown.
Root Cause
A defect in Pegasystems’ code or rules.
Resolution
Perform the following local-change:When using a custom authentication for a service that is also using Basic Authentication, perform the following steps:
- Set the Authentication Service on the Custom tab to use 'Basic Authentication'
- Use the following java code to access the authorization header in the Authentication activity:
javax.servlet.http.HttpServletRequest request =
(javax.servlet.http.HttpServletRequest)tools.getRequestor().getRequestorPage().getObject("pxHTTPServletRequest");
String authHeader = request.getHeader("authorization");
if (authHeader != null){
String base64UandP = authHeader.substring(6);
sUserAndPass = Base64Util.decode(base64UandP);
oLog.infoForced("UserAndPass: "+ sUserAndPass);
}
else {
//Direct processing to error handling in step named ERR
nextBlock = "ERR";
}
To read the payload of the data in a SOAP or REST HTTP POST request, use the following Java code in the Authentication activity to get access to the data:
javax.servlet.http.HttpServletRequest request =
(javax.servlet.http.HttpServletRequest)tools.getRequestor().getRequestorPage().getObject("pxHTTPServletRequest");
StringBuffer inData = new StringBuffer();
String line = null;
try{
java.io.InputStream is = request.getInputStream();
java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(is, "UTF-8"));
while ((line = br.readLine()) != null){
inData.append(line);
}
}catch (Exception e){
//Direct processing to error handling in step named ERR
nextBlock = "ERR";
}
After these steps, the content is in the StringBuffer inData and can be used further to access the content.
For example, for a JSON type data, include the data to the clipboard and use standard processing to get the data contents.
Example for JSON:
ClipboardPage inDataPage = tools.createPage("","inData");
try {
inDataPage.adoptJSONObject(inData.toString());
String someData=inDataPage.getString("SomeDataElement");
}
Published February 20, 2019 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.