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.


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, 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 = ''
rlm = cmo.getSecurityConfiguration().getDefaultRealm()
credMapProv = rlm.lookupCredentialMapper("DefaultCredentialMapper")
credMapProv.setUserPasswordCredential(resourceId, remoteUsername, remotePassword)
credMapProv.setUserPasswordCredentialMapping(resourceId, wlsUsername, remoteUsername)
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
java weblogic.WLST
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.