Showing posts with label Weblogic. Show all posts
Showing posts with label Weblogic. Show all posts

Wednesday, June 19, 2013

Adding Test Users to Weblogics embedded LDAP

You may want to add Users in the DefaultAuthenticator that comes OOTB when Weblogic is installed for various reasons ( Providing access to Test teams or creating multiple users for performance testing etc)

Here is a simple method of creating those users

Navigate to the folder

E:\Oracle\Middleware\wlserver_10.3\server\bin

create a file with any name example addMyTestUsers.py

edit the file and add the following script to it and save ( note the script also adds the created users to a group someGroup )

****************************
connect ("admin","password","localhost:7001")
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")
users=['test1','test2','test3','test4','test5']
groups=['someGroup']
for user in users:
try:
atnr.createUser(user,'password','TestUser')
print user,': created'
except Exception, e:
print user,': exist'
for group in groups:
for user in users:
try:
atnr.addMemberToGroup(group,user)
print user,': add to group'
except Exception, e:
print user,': exist in group'

*******************************


Open a command prompt

Cd to E:\Oracle\Middleware\wlserver_10.3\server\bin
run the file setWLSEnv.cmd to set environment variables

then run the command

java weblogic.WLST addMyTestUsers.py

The script will add users that done already exist and associate them to a security group or multiple groups as per values provided

Add users to line: users=[‘ username here‘, …]
Add group names to line: groups =[‘group name here’,…]