Hi,

Jay SenSharma

Jay SenSharma

NOTE: Updated version of this Script is available in  http://middlewaremagic.com/weblogic/?p=4751

Many times in production Environments we dont want to provide the Actual Clear text Passwords for safety reasons while creating the DataSources. So here is a Simple Example which demonstrates up that how we can Create a DataSource using WLST without using Clear Text passwords.

Step1). run the “setDomainEnv.sh” in the command Shell.

Step2).Run the following command to encrypt the DataBase Password of the DataSource.

java weblogic.security.Encrypt ${Clear_Text_Password}

Example: $ encrypt_password.ksh PBPUBLIC
{3DES}0HYiEySifDiz0IcqDhelGA==

(NOTE: the above command you need to run from inside the <DOMAIN_HOME> directory  or u need to use -Dbea.home option to specify the Domain Directory path)

Step3). Now we need to write the WLSt script to Create the DataSource with the Above Encrypted password: “CreateDS.py”

import sys
from java.lang import System
print "@@@ Starting the script ..."
url = 't3://localhost:7001'
usr = 'weblogic'
password = 'weblogic'
connect(usr,password, url)

edit()
startEdit()

print("----------------------------1")
print("*** Creating JDBC DataSource ")
myResourceName = "TestDSA"
print("Here is the Resource Name: " + myResourceName)

print("----------------------------2")
jdbcSystemResource = create(myResourceName,"JDBCSystemResource")
myFile = "TestDSA.xml"
print ("HERE IS THE JDBC FILE NAME: " + myFile)
jdbcResource = jdbcSystemResource.getJDBCResource()
jdbcResource.setName("MyJdbcResource")

print("----------------------------3")
# Create the DataSource Params
dpBean = jdbcResource.getJDBCDataSourceParams()
myName="MyJNDINameA"
dpBean.setJNDINames([myName])

print("----------------------------4")
# Create the Driver Params
drBean = jdbcResource.getJDBCDriverParams()
drBean.setPassword("{3DES}IQHx+vYPxQI5k1W1Dbwubw==")
drBean.setUrl("jdbc:pointbase:server://localhost/demo")
drBean.setDriverName("com.pointbase.jdbc.jdbcUniversalDriver")

print("----------------------------5")
propBean = drBean.getProperties()
driverProps = Properties()
driverProps.setProperty("user","PBPUBLIC")

print("----------------------------6")
e = driverProps.propertyNames()
while e.hasMoreElements() :
propName = e.nextElement()
myBean = propBean.createProperty(propName)
myBean.setValue(driverProps.getProperty(propName))

print("----------------------------7")
save()
activate()
--------------------------------------------------

Step4). Make Sure that the dataBase is running and reachable then Please run the above WLST scrpt to create the daatSource:

java weblogic.WLST CreateDS.py

Step5). Now after running the CreateDB.py script when i checked the DataSource XML File “<DOMAIN_HOME>/config/jdbc”

<?xml version='1.0' encoding='UTF-8'?>
<jdbc-data-source xmlns="http://www.bea.com/ns/weblogic/jdbc-data-source" xmlns:sec="http://www.bea.com/ns/weblogic/90/security" xmlns:wls="http://www.bea.com/ns/weblogic/90/security/wls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/jdbc-data-source http://www.bea.com/ns/weblogic/jdbc-data-source/1.0/jdbc-data-source.xsd">
<name>MyJdbcResource</name>
<jdbc-driver-params>
<url>jdbc:pointbase:server://localhost/demo</url>
<driver-name>com.pointbase.jdbc.jdbcUniversalDriver</driver-name>
<properties>
<property>
<name>user</name>
<value>PBPUBLIC</value>
</property>
</properties>
<password-encrypted>{3DES}IQHx+vYPxQI5k1W1Dbwubw==</password-encrypted>
</jdbc-driver-params>
<jdbc-data-source-params>
<jndi-name>MyJNDINameA</jndi-name>
</jdbc-data-source-params>
</jdbc-data-source>

NOTE: If you enter a Wrong Encrypted Password in the WLST script …then It will not be visible in the AdminConsole…You will see an EMPTY Password TextField there.

.
.
Thanks
Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.