Creating the Report on the KeyStore Certificates by Using API(Expired/Valid Certificates)
2023-12-6 21:52:50 Author: blogs.sap.com(查看原文) 阅读量:7 收藏

In this iflow, We are creating the Report on the KeyStore Certificates where we create attachment files of one is Valid Certificates and other is Expired Certificates one.

Step1: Create the iflow with the desired iflow name.

Step2: Connect the Sender and Integration process with the HTTP Adapter, give the desired endpoint in the address field like as below(/Keystore_Certificates_monitoring).

Step3:Now Add one Request reply and Receiver, then connect them with the OData V2 Adapter as shown below.

Do the following configurations in the Connection and Processing tab in OData Adapter.

Follow the below configuration to fetch the KeystoreEntries by using SAP CPI OData API in OData  Adapter.

In Connection tab:    Address: https://<<TenentURL>>/odata/api/v1

Authentication: Basic

Credential Name:  (Deploy the CPI login Credentials with a particular name in the security Material in monitoring section as User credentials type).Give that particular name in the Credential Name field.

In Processing Tab:

Resource Path: KeystoreEntries

Query Option: $select=Alias,ValidNotAfter.

Step4: Add Content Modifier to the iflow for set the Content-Type in the Header.

Name: Content-Type     Source-Type: Constant    Source Value: application/xml

Step5: Now add the message mapping element to the flow and create one Mapping.

After creating the Message Mapping add the Source and Target XSD’s.

Source XSD:

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com) -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="KeystoreEntries">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="KeystoreEntry">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Alias" type="xs:string" />
              <xs:element name="ValidNotAfter" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Target XSD:

<?xml version="1.0" encoding="utf-8"?>
<!-- Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com) -->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="KeystoreEntries">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="KeystoreEntry">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Name" type="xs:string" />
              <xs:element name="ExpiryDate" type="xs:string" />
	      <xs:element name="ExpiryStatus" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Do the following Mappings as shown below for KeyStore Entries.

Do the following Mappings as shown below for KeyStore Entry.

Create one script to find the difference between dates by clicking on the highlighted icon.

After creating the script add the below script.

import com.sap.it.api.mapping.*;

//import java.text.SimpleDateFormat // importing class SimpleDateFormat
import java.util.Date // import class Date
 
def String dayDiff(String date1, String date2){

    Date d1 = Date.parse("yyyy-MM-dd", date1)
    Date d2 = Date.parse("yyyy-MM-dd", date2)

    def timeDiffer = Math.abs(d1.time - d2.time) // gives time difference in milliseconds
    def dayDiffer = timeDiffer/(1000*60*60*24) // 1day = 1000*60*60*24 milliseconds

	if(d1.time<d2.time){
	    return "Certificate is already expired"
		}
	else if(dayDiffer<32){
	    return "Certificate is going to expire in " + dayDiffer + " Days"
	    }
    else{
        return "Valid till " +  date1
    }
}

Now take the dayDiff(Custom element) from left side panel and the join the substring to date1, current_date to date2.

After joining the dates do following mapping to the flow.

Now do the following mapping to Name by using Alias and ValidNotAfter.

Do the following mapping to Expiry Date by using ValidNotAfter.

Do the following mapping to ExpiryStatus by using ValidNotAfter.

Step6: After the Message Mapping add parallel Multicast to the iflow as shown below.

Step7: After adding the Multicast create two branches and add two filters one to each branch.

And give the below conditions in the filter1.

Xpath Expression field: /KeystoreEntries/KeystoreEntry[ExpiryStatus/text()=”Certificate is already expired”]

Give the below conditions in the filter2

Xpath Expression field: /KeystoreEntries/KeystoreEntry[ExpiryStatus/text()!=”Certificate is already expired”]

Step8: Now Add one content modifiers to each of the branches to the structure the body of the payload.

<KeyStoreEnteries>

${in.body}

</KeyStoreEnteries>

Step9: Add one XML to CSV convertor to each of the branches of the flow as shown below and give the below given string in the Xsd field

Path to source Element in XSD: /KeyStoreEnteries/KeystoreEntry

And the check the include the field name as Headers as shown below.

Step10: Add one content modifier to each branch of the iflow to save the payload of each branch in the property.

Name: PayLoad1     Source-Type: Expression    Source Value: ${in.body}  DateType: java.lang.String

Step11: After that use join element to join the both the branches of the flow.

Step12: After joining the both the branches of flow add the gather by given the below parameters as shown in the picture.

Step13: After the gather step save and deploy the iflow and fetch the iflow endpoint URL for testing the iflow

After fetching the endpoint use postman to the iflow as shown below.

Click on the send and observe the output.

Step14: To create the Attachments add one groovy script after the Gather step and write the below given script in it.

import com.sap.gateway.ip.core.customdev.util.Message
import org.apache.camel.impl.DefaultAttachment
import javax.mail.util.ByteArrayDataSource
 
def Message processData(Message message) {
    // 1: initailizing the variable to get the body from sent message
    def properties = message.getProperties()
    def payload1 = properties.get("PayLoad1");
    def payload2 = properties.get("PayLoad2");

    // 3: Construct a ByteArrayDataSource object with the byte array and the content's MIME type
    def dataSource1 = new ByteArrayDataSource(payload1, 'application/csv')
    def dataSource2 = new ByteArrayDataSource(payload2, 'application/csv')
 
    // 4: Construct a DefaultAttachment object
    def attachment1 = new DefaultAttachment(dataSource1)
    def attachment2 = new DefaultAttachment(dataSource2)
 
    // 5: Add the attachment to the message
    message.addAttachmentObject('Expired_Certificates', attachment1)
    message.addAttachmentObject('Valid_Certificates', attachment2)
    
    return message
 
}

By this groovy script two attachments will be created for the expired and valid Certificates separately.


文章来源: https://blogs.sap.com/2023/12/06/creating-the-report-on-the-keystore-certificates-by-using-apiexpired-valid-certificates/
如有侵权请联系:admin#unsafe.sh