OBIEE权限管理-WLST脚本-python

1.批量创建用户

#coding: utf-8

from weblogic.management.security.authentication import UserEditorMBean

from weblogic.management.security.authentication import UserAttributeEditorMBean

print '正在创建账户 ...'

atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')

userid = ['01','02']

username = [ur'张三',ur'李四']

department = [ur'集团A部',ur'b事业部']

count=0

numCreated=0

numIgnored=0

while count < len(userid):

if atnr.userExists(userid[count]):

print '用户 ' + userid[count] + ' 已经存在!'

count=count+1

numIgnored=numIgnored+1

continue

atnr.createUser(userid[count],userid[count]+'_biQA',username[count]+'-'+department[count])

atnr.setUserAttributeValue(userid[count],'c','CN')

atnr.setUserAttributeValue(userid[count],'departmentnumber',department[count])

atnr.setUserAttributeValue(userid[count],'displayname',username[count])

atnr.setUserAttributeValue(userid[count],'employeenumber',userid[count])

atnr.setUserAttributeValue(userid[count],'preferredlanguage','Chinese')

print userid[count]+' 已创建.'

count=count+1

numCreated=numCreated+1

print str(numCreated) + ' 个账户已创建:)'

print str(numIgnored) + ' 个操作已忽略:)'

2.移除用户

#coding: utf-8

from weblogic.management.security.authentication import UserEditorMBean

print "正在删除账户 ..."

atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")

userid = ['01','02']

username = [ur'张三',ur'李四']

department = [ur'集团A部',ur'b事业部']

count=0

numRemoved=0

numIgnored=0

while count < len(userid):

if atnr.userExists(userid[count])==false:

print '用户 ' + userid[count] + ' 不存在!'

count=count+1

numIgnored=numIgnored+1

continue

atnr.removeUser(userid[count])

print userid[count]+' 已删除.'

count=count+1

numRemoved=numRemoved+1

print str(numRemoved) + ' 个账户已删除:)'

print str(numIgnored) + ' 个操作已忽略:)'

3.添加到组

#!/usr/bin/python

#coding: utf-8

from weblogic.management.security.authentication import UserEditorMBean

from weblogic.management.security.authentication import GroupEditorMBean

print '正在进行目录组操作 ...'

atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')

atnr.createGroup('JT','集团')

atnr.createGroup('SYB','事业部')

userid = ['01','02']

username = [ur'张三',ur'李四']

department = [ur'集团A部',ur'b事业部']

count=0

numJT=0

numSYB=0

numIgnored=0

while count < len(userid):

if atnr.userExists(userid[count])==false:

print '账户 ' + userid[count] + ' 不存在!'

count=count+1

numIgnored=numIgnored+1

continue

if '集团' in department[count]:

atnr.addMemberToGroup('JT',userid[count])

atnr.addMemberToGroup('SYB',userid[count])

numJT=numJT+1

numSYB=numSYB+1

print userid[count]+' 已加入到目录组:JT,SYB。'

elif '事业部' in department[count]:

atnr.addMemberToGroup('SYB',userid[count])

numSYB=numSYB+1

print userid[count]+' 已加入到目录组:SYB。'

else:

continue

count=count+1

print str(numJT) + ' 个账户已加入到目录组:JT。:)'

print str(numSYB) + ' 个账户已加入到目录组:SYB。:)'

print str(numIgnored) + ' 个操作已忽略:)'

你可能感兴趣的:(OBIEE权限管理-WLST脚本-python)