In one of my recent Event engagement, I was expected to provision 50+ users in Weblogic. Creating users in Weblogic is not cumbersome process, it's fairly easy. However, when you need to do in bulk it can take hours.
So, I just came up with simple WLST script which take an configuration file as input which contains all the server credentials required to make connectivity and list of users, description and group name etc and create and delete users in Weblogic.
Creating Users
createUserMultiGrp.properties
USER="weblogic" PASSWORD="XXXX1" ADMIN_URL="t3://XXX.XX.25.226:7001 userName10={ "name":"api-manager-user-10", "userPwd":"OracleiPa$$Us3r10", "description":"This user been created for PTF Event", "groupName1":"Administrators", "groupName2":"APIPlatformSysadmins", "groupName3":"APICSAdministrators" } userName11={ "name":"api-manager-user-11", "userPwd":"OracleiPa$$Us3r11", "description":"This user been created for PTF Event", "groupName1":"Administrators", "groupName2":"APIPlatformSysadmins", "groupName3":"APICSAdministrators" } userName12={ "name":"api-manager-user-12", "userPwd":"OracleiPa$$Us3r12", "description":"This user been created for PTF Event", "groupName1":"Administrators", "groupName2":"APIPlatformSysadmins", "groupName3":"APICSAdministrators" } userNameArray=(userName10,userName11,userName12)
createUserMultiGrp.py-
import sys #read properties file if len(sys.argv) != 2: print "Invalid Arguments :: Please provide input file" exit() try: print "Load properties file" properties=sys.argv[1] file=open(properties,'r') print "Read properties file" exec file print "Execute properties file" file.close except: exit() print 'userName Array Values are : ',userNameArray print 'Admin server user name : ',USER print 'ADMIN Server URL : ',ADMIN_URL connect(USER,PASSWORD,ADMIN_URL) edit() serverConfig() successCount=0 for userName in userNameArray: usrName=userName['name'] # print 'The Name of the user will be created : ',usrName pwd=userName['userPwd'] #print 'The password for this user : ',pwd desc=userName['description'] # print 'Description for this user : ',desc grpName1=userName['groupName1'] # print 'First Group Name for this user : ',grpName1 grpName2=userName['groupName2'] # print 'Second Group Name for this user : ',grpName2 grpName3=userName['groupName3'] # print 'Third Group Name for this user : ',grpName3 cd('/SecurityConfiguration/APICS01_domain/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator') cmo.createUser(usrName,pwd,desc) print usrName,'- been created' cmo.addMemberToGroup(grpName1,usrName) cmo.addMemberToGroup(grpName2,usrName) cmo.addMemberToGroup(grpName3,usrName) print grpName1, grpName2, grpName3,'- been assigend to ',usrName successCount=successCount+1 print str(successCount)+" users successfully created"
Run this python Script
Delete Users in Weblogic
This WLST script work in same way as above and will user same configuration file which been used to create users as input and will delete all users listed in that configuration file.
deleteUser.py
import sys #read properties file if len(sys.argv) != 2: print "Invalid Arguments :: Please provide input file" exit() try: print "Load properties file" properties=sys.argv[1] file=open(properties,'r') print "Read properties file" exec file print "Execute properties file" file.close except: exit() print 'userName Array Values are : ',userNameArray print 'Admin server user name : ',USER print 'ADMIN Server URL : ',ADMIN_URL connect(USER,PASSWORD,ADMIN_URL) edit() serverConfig() successCount=0 for userName in userNameArray: usrName=userName['name'] # print 'The Name of the user will be created : ',usrName cd('/SecurityConfiguration/APICS01_domain/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator') cmo.removeUser(usrName) print usrName,'- has been Deleted' successCount=successCount+1 print str(successCount)+" users successfully deleted"
Run this python Script
I hope this blog will help to someone who want to script the WLS users creation and deletion.
Happy Blogging :)
No comments:
Post a Comment