views:

358

answers:

2

I need to add Administrative users to the WebSphere Console using a Jython script. I tried to turn on the "Log command assistance commands" preference, but it did not log adding a user. It did log other stuff though.

We setup alot of servers and are trying to script the entire setup process.

Cheers, Konrad

+1  A: 

I haven't done the administrative user, however, I have done a JAAS user. Following the script, it might give you enough hints on how to do it.

def dbAuthenticationAlias():
   print 'Create JAAS - J2C Authentication Alias'

   #--------------------------------------------------------------
   # Check if JAAS - J2C Authentication Alias exists
   #--------------------------------------------------------------

   global dbuseralias

   # generate user alias
   dbuseralias = nodeName + '/' + dbuser

   # get context 
   sec = AdminConfig.getid('/Cell:%s/Security:/' % cellName)

   #Get all J2C Authentication Aliases (they are separated by \n
   j2c = AdminConfig.list('JAASAuthData',sec)

   found = 0
   if len(j2c) > 0 :
      for j2cUserId in j2c.splitlines():
         if AdminConfig.showAttribute(j2cUserId,"alias") == dbuseralias:
            found = 1

   #--------------------------------------------------------------
   # Create a JAAS - J2C Authentication Alias
   #--------------------------------------------------------------
   if found == 0 :
      print 'user not found, creating'

      # create structure for J2C Authentication Alias
      jaasAttrs = [['alias', dbuseralias],['userId', dbuser],['password',dbpassword]]  

      #create J2C Authentication Alias
      AdminConfig.create('JAASAuthData', sec, jaasAttrs)

      print 'user %s created' % dbuseralias

      #saving
      adminConfigSave()
   else:
      print 'user found'

I had problems so far, finding, where a specif setting is to be made. So I used following commands within wsadmin tool to retrieve the current configuration.

sec = AdminConfig.getid('/Cell:%s/Security:/' % cellName)
#shows all attributes for the config element given by an ID 
print AdminConfig.show(sec) 
#shows all attributes and expands the attributes where necessary 
print AdminConfig.showall(sec) 

Instead of retrieving the security settings you can also retrieve the server settings and subsequently moving deeper in the configuration tree.

srv = AdminConfig.getid('/Node:%s/Server:%s/' % (node,server)) 
#get the process definition from server config 
prcDef = AdminConfig.list('ProcessDef',srv) 
#get JVM config from process definition 
jvm= AdminConfig.list('JavaVirtualMachine',prcDef) 
Peter Schuetze
A: 

Hi, thanks for this response. just one mistake on my configuration (WID6.2) to save the configuration.

i have replace by the line below

#saving
adminConfig.save()
Malrin