accessing crendtials in sap cpi
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
import com.sap.it.api.ITApiFactory;
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) {
// Define the alias for the user credentials
def credentialAlias = "SAP_BTP_Team_test";
// Get the SecureStoreService instance
def secureStorageService = ITApiFactory.getService(SecureStoreService.class, null);
try {
// Retrieve the user credentials using the alias
def userCredential = secureStorageService.getUserCredential(credentialAlias);
// Get the username and password from the credentials
def username = userCredential.getUsername();
def password = new String(userCredential.getPassword());
// Set the username and password in the message headers
message.setHeader("client_id", username);
message.setHeader("client_secret", password);
// new String(credential.getPassword());
} catch (Exception e) {
// Handle the exception if the credentials cannot be retrieved
throw new SecureStoreException("User credentials not available: " + e.getMessage());
}
return message;
}