#
# 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)