Posted by: michaelverzijl | 23/08/2012

Weblogic – WLST get users and groups

Sometimes it can be handy to retrieve all users and groups from the internal weblogic security provider.
To do this follow these steps:

  1. Create defaults.properties
  2. Set Weblogic environment
  3. Execute script

defaults.properties:

Don’t forget to change the URL, username and Password:

admin.url=t3://localhost:7001
admin.userName=weblogic
admin.password=<PWD>

# User Name which wants to get listed (where, * = all users name) #
user.name.wildcard=*

# Maximum Numbers of List you want to see (where, 0 = all the number of users) #
maximum.to.return=0

Set weblogic environment

Execure the file:
FMW_HOME\wlserver_10.3\server\bin\setWLSEnv.cmd/sh

Execute script
The following script will result in the users and the groups (separated by a “;”):

from java.io import FileInputStream</pre>
from weblogic.management.security.authentication import UserReaderMBean
from weblogic.management.security.authentication import GroupReaderMBean
from weblogic.management.security.authentication import MemberGroupListerMBean

propInputStream = FileInputStream("details.properties")
configProps = Properties()
configProps.load(propInputStream)

adminURL=configProps.get("admin.url")
adminUserName=configProps.get("admin.userName")
adminPassword=configProps.get("admin.password")
userNameWildcard=configProps.get("user.name.wildcard")
maximumToReturn=configProps.get("maximum.to.return")
showAllAuthenticatorUserList=configProps.get("show.all.authenticator.userlist")

connect(adminUserName, adminPassword, adminURL)

realmName=cmo.getSecurityConfiguration().getDefaultRealm()
authProvider = realmName.getAuthenticationProviders()

for i in authProvider:
if isinstance(i,UserReaderMBean):
userName = i
userReader1 = i
authName= i.getName()
userList = i.listUsers(str(userNameWildcard),int(maximumToReturn))
print '======================================================================'
print 'Below are the List of USERS which are in the: "'+authName+'"'
print '======================================================================'
num=1
while userName.haveCurrent(userList):
cursor1=i.listMemberGroups(userName.getCurrentName(userList))
while userReader1.haveCurrent(cursor1):
print userName.getCurrentName(userList) + ';'+userReader1.getCurrentName(cursor1)
userReader1.advance(cursor1)
#userReader1.close(cursor1)
userName.advance(userList)
num=num+1
print '======================================================================'
userName.close(userList)

The script can be executed by: java weblogic.WLST userlist.py > logging.txt

My thanks go out to: http://middlewaremagic.com/weblogic/

Advertisements

Responses

  1. What is this weblogic.WLST ?

  2. Dear, I am having an issue that We are using Oracle 11g DB & Weblogic server … when ever end user is connect with the Applications, v$session show the Weblogic Server Name and does not show the actual connecting Terminal as well as Operating System Name… There is any way to get the User Terminal as well as OS Name ???

  3. I tried to run your script and get a syntax error
    File “/u01/WLS/userlist.py”, line 23
    if isinstance(i,UserReaderMBean):
    ^
    SyntaxError: invalid syntax

    I am new to WLST . can you help me out . Thanks

  4. I tried but got an error

    Problem invoking WLST – Traceback (innermost last):
    (no code object) at line 0
    File “/p03/oracle/mwhome/userlist.py”, line 23
    if isinstance(i,UserReaderMBean):
    ^
    SyntaxError: invalid syntax

    Any help on this.

    Thanks
    Kiran


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Categories

%d bloggers like this: