#
# 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)
This comment has been removed by the author.
ReplyDeleteThis doesn't work with WLS 10.2
ReplyDeleteHi John, thanks for the article. Can you show a quick example of how to use the removeUser() operation in an AuthenticationProvider? I'm having problems trying to remove users (and groups) and can't find anyone that's doing this. Thank you.
ReplyDelete