Question

Reading Header Attribute information - get CN works in non-Pega app, but doesn't work in Pega app

I have loaded Pega Personal Edition (tomcat installation) and we have deployed two apps. The first app is able to read the header to get the user CN. The pega app is not able to obtain the user CN.

First application (java code)

  1. X509Certificate[] certs = null;
  2. try {
  3.  
  4. Object objCertificates = request.getAttribute("javax.servlet.request.X509Certificate");
  5. certs = (X509Certificate[])objCertificates;
  6.  
  7. } catch (Exception e) {
  8. System.out.println("ERROR: Calling x509 certificate ... " + e.getMessage());
  9. }
  10.  
  11. if (certs != null) {
  12.  
  13. X509Certificate cert = certs[0];
  14. Principal p = cert.getSubjectDN();
  15.  
  16. // display user cn from cac, set session attributes
  17. String CN = p.getName().substring(3, p.getName().indexOf(",", 0));
  18.  
  19. System.out.println("~~ CN = " + CN);
  20. System.out.println("~~ caCertO = " + cert.getIssuerDN().toString());
  21.  
  22. }

… and when we access the java web application, the java console show:

  1. ~~ CN = BL*****.M*****.A.129012345
  2. ~~ cacCertO = CN=DOD ID CA-24, OU=PKI, OU=DoD, O=U.S. Government, C=US

In the second (Pega) application, we modified the Web-Login page to include similar java code:

  1. <pega:choose>
  2. <pega:when test="pyUnsupportedBrowsers" >
  3. <pega:include name='pyUnsupportedBrowserLoginMessage' type='Rule-HTML-Fragment'/>
  4. </pega:when>
  5. <pega:otherwise>
  6.  
  7. <%
  8. System.out.println("---------------------------------------------------------");
  9. System.out.println("-- Checking for Certificates!");
  10. System.out.println("---------------------------------------------------------");
  11. java.security.cert.X509Certificate[] certs = null;
  12. try {
  13. if (request != null) {
  14. System.out.println("-- 3");
  15. }
  16. String requestUrl = (request.getRequestURL()).toString();
  17. System.out.println("-- Checking for Certificates 00 - requestURL = " + requestUrl);
  18. System.out.println("-- Checking for Certificates 01");
  19. Object objCertificates = request.getAttribute("javax.servlet.request.X509Certificate");
  20. if (objCertificates != null) {
  21. System.out.println("-- Checking for Certificates 02 - objCertificates is not null");
  22. }
  23. certs = (java.security.cert.X509Certificate[])objCertificates;
  24. System.out.println("-- Checking for Certificates 03");
  25. } catch (Exception e) {
  26. System.out.println("ERROR: Calling x509 certificate ... " + e.getMessage());
  27. }
  28.  
  29. if (certs != null) {
  30. System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  31. System.out.println("~~ WE FOUND CERTS");
  32. System.out.println("~~");
  33.  
  34. java.security.cert.X509Certificate cert = certs[0];
  35. java.security.Principal p = cert.getSubjectDN();
  36.  
  37. // display user cn from cac, set session attributes
  38. String CN = p.getName().substring(3, p.getName().indexOf(",", 0));
  39.  
  40. System.out.println("~~ CN = " + CN);
  41. System.out.println("~~ caCertO = " + cert.getIssuerDN().toString());
  42. System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
  43. } else {
  44. System.out.println("-- We did not find any certificates ...");
  45. }
  46.  
  47. ///////////////////////////////////////
  48. // Start of original Web-Login code
  49. ///////////////////////////////////////
  50. ...

When we access the Pega login screen, the tomcat console shows:

  1. ---------------------------------------------------------
  2. -- Checking for Certificates!
  3. ---------------------------------------------------------
  4. -- Checking for Certificates 00 - requestURL = /Non_Interactive_Session_No_Context/NonInteractive
  5. -- Checking for Certificates 01
  6. -- Checking for Certificates 03
  7. -- We did not find any certificates ...

Comments

Keep up to date on this post and subscribe to comments

September 10, 2019 - 10:02am

I apologize for the above post - i realize it is very hard to read.  I am looking for examples of reading HttpServletRequest object from the Pega "Web-Login" HTML page.

I also found a similar post where the solution was found by using javascript code (but they didn't post a sample of the javascript code) - https://community1.pega.com/community/product-support/question/not-able-read-http-header-information

 

Does anyone have sample code to read header information?  If so, please post the sample.  Thanks!