Friday, July 15, 2011

WLST (un)deploying an application directory

#
# Deploy and start an application directory
# using WLST (online)
# John Minkjan Ciber Netherlands
#

print 'deploying....'
deploy('OBIEE_META2', 'D:/OBIEE_META2', targets='AdminServer,bi_server1')

print 'starting.....'
startApplication('OBIEE_META2')


#
# stop and undeploy an application directory
# using WLST (online)
# John Minkjan Ciber Netherlands
#

print 'stoping.....'
stopApplication('OBIEE_META2')

print 'undeploying....'
undeploy('OBIEE_META2')

Till Next Time

WLST List User, Groups and Users in Groups

#
# listing Users and Groups (online)
# John Minkjan Ciber Netherlands
#


from weblogic.management.security.authentication import UserReaderMBean
from weblogic.management.security.authentication import GroupReaderMBean

realm=cmo.getSecurityConfiguration().getDefaultRealm()
atns = realm.getAuthenticationProviders()

print 'All Users'
for i in atns:
  if isinstance(i,UserReaderMBean):
    userReader = i
    cursor = i.listUsers("*",0)
    print 'Users in realm '+realm.getName()+' are: '
    while userReader.haveCurrent(cursor):
      print userReader.getCurrentName(cursor)
      userReader.advance(cursor)
    userReader.close(cursor)

print 'All Groups'
for i in atns:
  if isinstance(i,GroupReaderMBean):
    groupReader = i
    cursor = i.listGroups("*",0)
    print 'Groups in realm are: '
    while groupReader.haveCurrent(cursor):
      print groupReader.getCurrentName(cursor)
      groupReader.advance(cursor)
    groupReader.close(cursor)

print 'users in group'   
for i in atns:
  if isinstance(i,GroupReaderMBean):
    groupReader = i
    cursor =  i.listGroups("*",0)
    while groupReader.haveCurrent(cursor):
        group = groupReader.getCurrentName(cursor)   
        usergroup = i.listAllUsersInGroup(group,"*",0)
        print realm.getName()
        print '-', group
        for user in usergroup:
            print '--',user       
        groupReader.advance(cursor)
    groupReader.close(cursor)
   
   
print ' unique users in group'   
for i in atns:
  if isinstance(i,GroupReaderMBean):
    groupReader = i
    cursor =  i.listGroups("*",0)
    while groupReader.haveCurrent(cursor):
        group = groupReader.getCurrentName(cursor)   
        usergroup = i.listAllUsersInGroup(group,"*",0)
        print realm.getName()
        print '-', group
        uniqueUser = []
        for user in usergroup:
            if user not in uniqueUser:
                uniqueUser.append(user)
        for user in uniqueUser:
            print '--',user       
        groupReader.advance(cursor)
    groupReader.close(cursor)

WLST Removing user from group.

#
# Removing Users to a Group using WLST (online)
# John Minkjan Ciber Netherlands
#
print 'lookup DefaultAuthenticator'
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')

groups = ['companya']
for group in groups:
    users = ['user1','user2']
    for user in users:       
        print 'removing user: ',user, ' from group:', group
        try:
            atnr.removeMemberFromGroup(group,user)
        except:
            print 'user: ', user , ' can not be removed from group: ', group

 

Till Next Time

WLST executing a script file

execfile( filePath .py)

execfile('D:\WLST_PY\DELETEUSERSFROMGROUP.py')

Till Next Time

Thursday, July 14, 2011

WLST Adding Users to a Group

#
# Adding Users to a Group using WLST (online)
# John Minkjan Ciber Netherlands
#
print 'lookup DefaultAuthenticator'
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')

groups = ['companya','BIConsumers','BIAuthors']
for group in groups:
    users = ['user1','user2']
    for user in users:       
        print 'working user: ',user, ' group:', group
        try:
            atnr.addMemberToGroup(group,user)
        except:
            print 'user: ', user , ' can not be placed in group: ', group

Till Next Time

WLST Removing and Adding Users

#
# Removing and Adding Users using WLST (online)
# John Minkjan Ciber Netherlands
#
print 'lookup DefaultAuthenticator'
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')

group = 'companya'
password = 'Welcome1'
users = ['user1','user2']
# delete the "old" users
for user in users:   
    try:
        print 'working user: ',user
        atnr.removeUser (user)
    except:
        pass

# Create the "new" users
users = ['user1','user2']
for user in users:           
    try:       
        print 'create user: ',user
        atnr.createUser(user,password,user)
    except:
        pass

Till Next Time

WLST Removing and Adding Groups

#
# Removing and Adding groups using WLST (online)
# John Minkjan Ciber Netherlands
#
print 'lookup DefaultAuthenticator'
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')

groups = ['companya', 'companyb']
groupcomment = 'If you work for this company you need this group'

for group in groups:
    print 'delete the old one if exists'
    try:
        atnr.removeGroup(group)
    except:
        print '*************** CANNOT DELETE !!! Check If The Group With the Name : ' , group ,' Exists or NOT...'

for group in groups:
    print 'create group:' , group
    atnr.createGroup(group,groupcomment)

 

Till Next Time

Monday, July 11, 2011

WLST Connect

connect('weblogic','Ciber2011','t3://localhost:7001',adminServerName='AdminServer')

Till Next Time

Welcome to wlst101

An other 101 blog John Minkjan dedicated to the Weblogic Scripting Tool.


Till Next Time