How to Create Credential Mappings for a WebLogic Server Datasource Using WLST

This article describes how to create Credential Mappings for an existing WebLogic Server Datasource using WLST.

Fix

You can use a WLST Python script to create Credential Mappings for an existing WebLogic Server Datasource. Create the filename with a .py extention with the following content: for example, JDBCCredentialMapping.py. In the script make modifications according to your environment and requirement specifying the DataSource Name (), Domain Name (), remoteUsername (), remotePassword
(<remotePassword>) and WLST domain connect parameters specifying domain username, password and listen address.

resourceId = 'type=<jdbc>, application=, module=, resourceType=ConnectionPool, resource=<DataSource Name>, action=reserve'
wlsUsername = '<wlsUsername>'
remoteUsername = '<remoteUsername>'
remotePassword = '<remotePassword>'
domainName = ''
connect('<username>','<password>','t3://<listenaddress>:<PortNo>')
serverConfig()
cd("//")
rlm = cmo.getSecurityConfiguration().getDefaultRealm()
credMapProv = rlm.lookupCredentialMapper("DefaultCredentialMapper")
credMapProv.setUserPasswordCredential(resourceId, remoteUsername, remotePassword)
credMapProv.setUserPasswordCredentialMapping(resourceId, wlsUsername, remoteUsername)
disconnect()
exit()
Set the WebLogic Server environment variables by running setDomainEnv.cmd/sh script inside the ${DOMAIN_HOME}/bin folder and run the WLST python script as below. In this example. we assume the python script name JDBCCredentialMapping.py.
java weblogic.WLST JDBCCredentialMapping.py
Once the python script is executed in WLST, log in to the WLS console, navigate to Datasource -> Security -> Credential Mappings. You can see the specified WLS User and Remote User credentials created.