cancel
Showing results for 
Search instead for 
Did you mean: 

Fetching Credentials Dynamically

ganiganesh
Explorer
0 Kudos

Hi Everyone,

We need to fetch Credentials dynamically from Keystore based on dynamically passed alias name , in return it should send Username and Password as a result. Is there any groovy or any standard camel syntax ?. If their means please let me know.

Thanks & Regards,

Dhanush.

Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Gensha,

You can read the request and set the credential name as property( name it ARC_CRED ) using content modifier.Then in the script read the property value to get the response.

import com.sap.it.api.ITApi
import com.sap.it.api.ITApiFactory
import com.sap.it.api.securestore.*;
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;

def Message processData(Message message) {
       
      //Body 
       def body = message.getBody();
       String password;
       String _output="";
       def pMap = message.getProperties();
       String CREDENTIAL_NAME=pMap.get("ARC_CRED").toString();
       def service = ITApiFactory.getApi(SecureStoreService.class, null);
       def credential = service.getUserCredential(CREDENTIAL_NAME); 
       
	   if (credential == null)
       {
 		throw new IllegalStateException("No credential found for alias 'CREDENTIAL_NAME'");            
       }
       else
	   {
         password= new String(credential.getPassword());
       }
       message.setProperty("P_Password", password);
       return message;
}

Regards,

Sriprasad Shivaram Bhat

ganiganesh
Explorer

Thank you very much Sriprasad. I'm Dhanush ,recently joined to job as fresher but i'm using Ganesh A M's account. Anyway you peoples are helping me alot. Thanks to all for your precious responses.

Answers (2)

Answers (2)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Ganesha,

Below might help you and you can pass the property you have set for pass & user in connector.

import com.sap.it.api.ITApi
import com.sap.it.api.ITApiFactory
import com.sap.it.api.securestore.*;
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;


def Message processData(Message message) {
       
      //Body 
       def body = message.getBody();
       String password;
       String _output="";
       def service = ITApiFactory.getApi(SecureStoreService.class, null);
       def credential = service.getUserCredential("CREDENTIAL_NAME"); 
       
	   if (credential == null)
       {
 		throw new IllegalStateException("No credential found for alias 'CREDENTIAL_NAME'");            
       }
       else
	   {
         password= new String(credential.getPassword());
       }
       message.setProperty("P_Password", password);
       return message;
}

Regards,

Sriprasad Shivaram Bhat

ganiganesh
Explorer
0 Kudos

Thanks Sriprasad. But i'm looking for Dynamical fetching means if the Credentials alias name is triggered from ARC tool means it should give UserName and Password for that passed Credential alias.

cveto_ljubic
Explorer
0 Kudos

Hello, great POST. But I want to know if is it possible to save Credentials from Groovy, not just retrive it from Secure Material.

Thank you for answer.

Best Regards,

Cveto

manoj_khavatkopp
Active Contributor
0 Kudos

Hi Dhanush ,

You can use getUsername() and getPassword() of interface UserCredential.

Check this link for more details :

Thanks,

Manoj

ganiganesh
Explorer
0 Kudos

Thanks Manoj.

But i'm trying to groovy using those getPassword() and getUsername(), still not able write correct groovy. If don't mind please send complete groovy here.