Many times we have been asked if there is any script which can change the password of all the data sources at one time. As lot of people in production have n-numbers of data sources and if they have to change each and every password it would take a lot of time and energy to do it.
Hence Jay and I sat to-gather to get you this script which would make your life easy. Using the below WLST script you can even change the Username and Password of all the data source in weblogic server in no time.
Hope this would help all the Webloigc administrators and make them your life easier…..
– You just have to create a file called ChangePassDs.py and copy the below code to it.
############################################################################# # # @author Copyright (c) 2010 - 2011 by Middleware Magic, All Rights Reserved. # ############################################################################# print("*** Trying to Connect.... *****") connect('weblogic','weblogic','t3://localhost:7001') print("*** Connected *****") cd('Servers/AdminServer') edit() startEdit() cd('JDBCSystemResources') allDS=cmo.getJDBCSystemResources() for tmpDS in allDS: dsName=tmpDS.getName(); print 'Changing Password & UserName for DataSource ', dsName cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName) print('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName) set('PasswordEncrypted','NEW_ENC_PASSWORDA') cd('/JDBCSystemResources/'+dsName+'/JDBCResource/'+dsName+'/JDBCDriverParams/'+dsName+'/Properties/'+dsName+'/Properties/user') set('Value','NEW_USERNAMEA') print("*** CONGRATES !!! Username & Password has been Changed for DataSource: ", dsName) print ('') print ('') save() activate()
Few things which has to be kept in mind:
- You might have to change Line 2, 4, 15 and 17 according to your environment.
- The alinement’s after the Line 10 to 20 should be copied as it is or else you would have syntax error.
- Make sure you follow the 5 Steps mentioned in the WLST page
Advantage of this Script:
- You work got automated.
- All the Username and Password of data sources can be changed
- Removing the set value for User name in Line 17 you can change only the passwords.
- You can enhance this script by changing other properties as well.
.
Do let us know if this WLST script helped you
Regards,
Ravish Mody
December 20th, 2010 on 4:21 pm
Hi Ravish,
I have small doubt on the above script. If we are using the above script to change the passwords of the datasources, it will be using the the same password(what we have defined in the script) across all the datasources. And also in any environment, datasources will be pointing to different databases with their own username & passwords. In this type of situation how is above script is useful/reduse the load to the administrator.
Regards,
Baji.
December 20th, 2010 on 4:27 pm
Hi BabuJasti,
above WLST script is extendable, It means u can write a Properties file mentioned in the following Link: http://middlewaremagic.com/weblogic/?p=4334 And then read the Values of different DataSource parameters like Username/Password/Url Etc from that file to change then.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
December 20th, 2010 on 4:53 pm
Hi Jay,
Yes i saw that and agree with you that we can use properties file to achive what i seek. But don’t you think it is going to be a lots of manual work. Is there any way to automate this??
Also i have another question about WLST scripting. Where can i raise a new question??? or you want me to ask here only?
Regards,
Baji.
December 20th, 2010 on 10:01 pm
Hi BabuJasti,
Plesae refer to the following Post : http://middlewaremagic.com/weblogic/?p=4956
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
December 20th, 2010 on 7:38 pm
Hi Jay/Ravish,
I had a query on the statement in line 15
set(‘PasswordEncrypted’,’NEW_ENC_PASSWORDA’)
On using the option “PasswordEncrypted” in the set(….) function, does the password “NEW_ENC_PASSWORDA” get encrypted and then stored or is it the encrypted value pulled from a properties file.
I had seen a similar post and reply from Jay but wanted to get my understanding clear – http://forums.oracle.com/forums/thread.jspa?threadID=1055551&tstart=100
I am particularly interested in the behaviour of Weblogic 10 MP1.
Thanks,
Souvik.
December 20th, 2010 on 8:53 pm
HI Souvik,
Yes …If you encrypt your Passwords like:
C:bea103user_projectsdomainsbase_domainbin>setDomainEnv.cmd
C:bea103user_projectsdomainsbase_domain>java weblogic.security.Encrypt PBPUBLIC
{3DES}IQHx+vYPxQI5k1W1Dbwubw==
And if you replace the Line in the WLST Script “set(‘PasswordEncrypted’,’NEW_ENC_PASSWORDA’)” with the following:
set(‘PasswordEncrypted’,'{3DES}IQHx+vYPxQI5k1W1Dbwubw==’)
then the DataSource password will be entered in the Encrypted form in the Data Source configuration file. But the Actual Password will be as it is “PBPUBLIC”.
So better if you use the WLST Script which is used in the Forums…Just try that once to see what happens. “CreateDS.py”
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
December 23rd, 2010 on 10:06 pm
Hi Souvik,
You can also refer to the following link: http://middlewaremagic.com/weblogic/?p=1400
To See how to insert Encrypted Password in the DataSource configuration using WLST.
.
.
Keep Posting 🙂
Thanks
Jay SenSharma
September 1st, 2011 on 10:19 pm
Hi,
This is Ravi.
I am getting error for this line when I am trying to set userid and password.
Syntax Error getting for line
for tmpDS in allDS:
dsName=tmpDS.getName()/*Error getting for this line*/
Below is the WLST script:-
connect(‘weblogic’,’weblogic’,’t3://localhost:7001′)
edit()
startEdit()
cd(‘JDBCSystemResources’)
allDS=cmo.getJDBCSystemResources()
for tmpDS in allDS:
dsName=tmpDS.getName();
print ‘Changing Password & UserName for DataSource ‘, dsName
cd(‘/JDBCSystemResources/’+dsName+’/JDBCResource/’+dsName+’/JDBCDriverParams/’+dsName)
print(‘/JDBCSystemResources/’+dsName+’/JDBCResource/’+dsName+’/JDBCDriverParams/’+dsName)
set(‘PasswordEncrypted’,’NEW_ENC_PASSWORDA’)
cd(‘/JDBCSystemResources/’+dsName+’/JDBCResource/’+dsName+’/JDBCDriverParams/’+dsName+’/Properties/’+dsName+’/Properties/user’)
set(‘Value’,’NEW_USERNAMEA’)
print(“*** CONGRATES !!! Username & Password has been Changed for DataSource: “, dsName)
print (”)
print (”)
activate()
save()
I am also trying to set the connection craetion retry frequency for all the datasources which is hosted on the same domain. but getting the error for the same line in that code also.
Please suggest what else I can use instead ….
Thanks in advance.
Ravi
September 1st, 2011 on 10:30 pm
Hi Ravi,
The WLST script given in the above article just runs fine for me on WLS 10.3 version, can you let us know on which WLS version are you trying to run the same script and also paste the error which is coming when you are running the script.
Regards,
Ravish Mody
September 1st, 2011 on 11:22 pm
Hi Ravish,
I am using 9.2 MP3 which is running on Solaris 10 (64 bit )with JDK update 31.
Getting the below error:-
Error at line no. 7.
dsName=tmpDS.getName();
syntax error.
Thanks,
Ravi
September 1st, 2011 on 11:35 pm
Hi Ravi,
WLST “for” Loops and control statements like if—else blocks boundaries are determined by the Indentations (Means the spaces left in front of the lines decides the Body of the Loops) So please be careful with the Indentations.
Example: Following is WRONG
for tmpDS in allDS:
dsName=tmpDS.getName();
print ‘Changing Password & UserName for DataSource ‘, dsName
Example Following is RIGHT
for tmpDS in allDS:
dsName=tmpDS.getName();
print ‘Changing Password & UserName for DataSource ‘, dsName
To get the Total Number of DataSources present inside a Domain you can do the following:
count=0
for tmpDS in allDS:
dsName=tmpDS.getName();
print ‘Changing Password & UserName for DataSource ‘, dsName
count = count + 1
print ‘Total DataSources = ‘, count
.
Keep Posting 🙂
Thanks
Jay SenSharma
September 1st, 2011 on 11:24 pm
Hi Ravish,
What is the command to get the count of datasource in the same domain.
Thanks,
Ravi Shankar Kumar.
September 2nd, 2011 on 11:42 am
Thanks Jay…its really helpful….
September 3rd, 2011 on 12:53 am
Hi Jay/Ravish,
I have to target/Untarget datasources on the same domain.
I am able to one by one using the following script:-
connect(‘weblogic’,’weblogic’,’t3://localhost:7001′)
edit()
startEdit()
dsName = “com.test.connector”
cd (‘/JDBCSystemResources/’+dsName)
set(‘Targets’,jarray.array([], ObjectName))
activate()
startEdit()
cd (‘/JDBCSystemResources/’+dsName)
set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=Testconnector,Type=Cluster’)], ObjectName))
activate()
exit()
I have 5 clusters on the same domain.I need to achieve the target/untarget all the datasources of the same domain using a single generic script.
Please help me out.
Warm Regards,
Ravi Shankar Kumar.
September 4th, 2011 on 9:18 pm
Hi Ravi,
We have just created an article which would target and untarget multiple datasources in the same domain using a single WLST script which would surely help you, hence check out the below article
Target and Untargeting of Multiple DataSources using WLST
Regards,
Ravish Mody
May 25th, 2012 on 10:05 pm
Is there a way just to update the password on certain Data Sources and not all
December 26th, 2013 on 1:18 pm
Hi Ravish,
Suppose If i want to change password for more then 2 Data source then how to do that.
Can you help me with the scripts.