Ravish Mody

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:

  1. You might have to change Line 2, 4, 15 and 17 according to your environment.
  2. The alinement’s after the Line 10 to 20 should be copied as it is or else you would have syntax error.
  3. Make sure you follow the 5 Steps mentioned in the WLST page

Advantage of this Script:

  1. You work got automated.
  2. All the Username and Password of data sources can be changed
  3. Removing the set value for User name in Line 17 you can change only the passwords.
  4. You can enhance this script by changing other properties as well.

.

Do let us know if this WLST script helped you

Regards,

Ravish Mody