<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: BTP CPI. get Security Material in groovyscript problem in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/btp-cpi-get-security-material-in-groovyscript-problem/qaa-p/12670611#M4753695</link>
    <description>&lt;P&gt;I solved the problem.&lt;/P&gt;&lt;P&gt;I changed it to a secure parameter and changed the Getusercrendental and getpassword strings, and it works well&lt;/P&gt;</description>
    <pubDate>Sat, 18 Mar 2023 11:15:56 GMT</pubDate>
    <dc:creator>wkpk</dc:creator>
    <dc:date>2023-03-18T11:15:56Z</dc:date>
    <item>
      <title>BTP CPI. get Security Material in groovyscript problem</title>
      <link>https://community.sap.com/t5/technology-q-a/btp-cpi-get-security-material-in-groovyscript-problem/qaq-p/12670610</link>
      <description>&lt;P&gt;I would like to connect and use Google api of openconnector through CPI.&lt;/P&gt;
  &lt;BR /&gt;I used an http adapter on the sender, and I succeeded in hardcoding and deploying the authorization of header through groovyscript and calling it from POSTMAN.
  &lt;BR /&gt;
  &lt;BR /&gt;Next, hard coding seems to have a management problem, so i tried to change it to Security Material... But it's not working.
  &lt;BR /&gt;
  &lt;BR /&gt;To be exact, the API that gets security material information does not seem to work well.
  &lt;BR /&gt;
  &lt;P&gt;this is my Security Material&lt;/P&gt;*The User value is the User value of OPENCONNECTOR.
  &lt;BR /&gt;In Password, the organization and element of OPENCONNECTOR are concatenated as comma.
  &lt;BR /&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2156520-image.png" /&gt;&lt;/P&gt;
  &lt;BR /&gt;
  &lt;BR /&gt;this is my GroovyScript : 
  &lt;BR /&gt;
  &lt;PRE&gt;&lt;CODE&gt;import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import com.sap.it.api.ITApiFactory;
import com.sap.it.api.mapping.ValueMappingApi
import com.sap.it.api.securestore.SecureStoreService
import com.sap.it.api.securestore.UserCredential
import com.sap.it.api.securestore.exception.SecureStoreException

def Message processData(Message message) {
    def secureStorageService =  ITApiFactory.getService(SecureStoreService.class, null)
    def credentials  = secureStorageService.getUserCredential('GoogleDrive')
    
    def user = credentials.getUser()
    def password = credentials.getPassword()
    def (organization, element) = password.split(',')
    
    String authorization ="User ${user}, Organization ${organization}, Element ${element}"
    message.setHeader("Authorization", 'authorization ')
    return message;
}
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;BR /&gt;this is error :
  &lt;BR /&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2156521-image.png" /&gt;&lt;/P&gt;
  &lt;BR /&gt;How can solve this problem?</description>
      <pubDate>Sat, 18 Mar 2023 10:18:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/btp-cpi-get-security-material-in-groovyscript-problem/qaq-p/12670610</guid>
      <dc:creator>wkpk</dc:creator>
      <dc:date>2023-03-18T10:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: BTP CPI. get Security Material in groovyscript problem</title>
      <link>https://community.sap.com/t5/technology-q-a/btp-cpi-get-security-material-in-groovyscript-problem/qaa-p/12670611#M4753695</link>
      <description>&lt;P&gt;I solved the problem.&lt;/P&gt;&lt;P&gt;I changed it to a secure parameter and changed the Getusercrendental and getpassword strings, and it works well&lt;/P&gt;</description>
      <pubDate>Sat, 18 Mar 2023 11:15:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/btp-cpi-get-security-material-in-groovyscript-problem/qaa-p/12670611#M4753695</guid>
      <dc:creator>wkpk</dc:creator>
      <dc:date>2023-03-18T11:15:56Z</dc:date>
    </item>
    <item>
      <title>Re: BTP CPI. get Security Material in groovyscript problem</title>
      <link>https://community.sap.com/t5/technology-q-a/btp-cpi-get-security-material-in-groovyscript-problem/qaa-p/14028095#M4904971</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;BR /&gt;I tried the same, but as I want to have user and password secured, I did not want to switch to Secure Parameter.&amp;nbsp;&lt;BR /&gt;With this script I am able to read out also User Credentials.&lt;/P&gt;&lt;P&gt;I like to add Debug infos....not necessary, but nice to have.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;import com.sap.gateway.ip.core.customdev.util.Message
import com.sap.it.api.ITApiFactory
import com.sap.it.api.securestore.SecureStoreService

def Message processData(Message message) {
    def map = message.getProperties()
    def debugCounter = map.keySet().findAll { it.startsWith("Debug_") }.size() + 1

    try {
        // Retrieve SecureStoreService instance (with null as the second argument)
        SecureStoreService secureStoreService = ITApiFactory.getService(SecureStoreService.class, null)
        if (secureStoreService == null) {
            message.setProperty("Debug_${debugCounter++}", "Error: SecureStoreService could not be instantiated.")
            return message
        }

        // Access stored user credentials
        def credential = secureStoreService.getUserCredential("Name_of_Credential")
        if (credential == null) {
            message.setProperty("Debug_${debugCounter++}", "Error: No credentials found for Credentials.")
            return message
        }

        // Extract username and password
        String username = credential.getUsername()
        String password = new String(credential.getPassword()) // Convert char array to String

        // Store debugging information
        message.setProperty("Debug_${debugCounter++}", "Successfully retrieved credentials from Secure Store.")
        message.setProperty("Username", username)
        message.setProperty("Password", password) 

    } catch (Exception e) {
        message.setProperty("Debug_${debugCounter++}", "Exception while accessing Secure Store: " + e.getMessage())
    }

    return message
}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 26 Feb 2025 11:54:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/btp-cpi-get-security-material-in-groovyscript-problem/qaa-p/14028095#M4904971</guid>
      <dc:creator>Chris_XI</dc:creator>
      <dc:date>2025-02-26T11:54:30Z</dc:date>
    </item>
  </channel>
</rss>

