I would like to connect and use Google api of openconnector through CPI.
this is my Security Material
*The User value is the User value of OPENCONNECTOR.
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;
}

Request clarification before answering.
I solved the problem.
I changed it to a secure parameter and changed the Getusercrendental and getpassword strings, and it works well
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I tried the same, but as I want to have user and password secured, I did not want to switch to Secure Parameter.
With this script I am able to read out also User Credentials.
I like to add Debug infos....not necessary, but nice to have.
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 11 | |
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.