Creating Users in Weblogic Server Embedded LDAP Programatically.

I have received many requests from Clients for code snippet to create users programmatically.Below is a sample code by which we can create users in the Embedded LDAP of Weblogic Server.Put simple, this program creates an MBean Server connection, traverses to the relevant Mbean and invokes the right method to create the user.

Details can be found at this link.

Use the following code is a JSP and do the necessary import and acess the jsp page.

User testuser will be created in the embedded ldap with the password as password.

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,”weblogic.jndi.WLInitialContextFactory”); env.put(Context.SECURITY_PRINCIPAL, “weblogic”);
env.put(Context.SECURITY_CREDENTIALS, “weblogic”);
env.put(Context.PROVIDER_URL, “t3://″);
InitialContext ctx = new InitialContext(env);
MBeanServer wls = (MBeanServer) ctx.lookup(“java:comp/env/jmx/runtime”);
ObjectName userEditor = null;
ObjectName MBTservice = new ObjectName( “com.bea:Name=MBeanTypeService,” + “”);
ObjectName rs = new ObjectName(“com.bea:Name=RuntimeService,”+””);
ObjectName domainMBean = (ObjectName) wls.getAttribute(rs,”DomainConfiguration”); ObjectName securityConfig = (ObjectName) wls.getAttribute(domainMBean,”SecurityConfiguration”);
ObjectName defaultRealm = (ObjectName) wls.getAttribute(securityConfig,”DefaultRealm”);
ObjectName[] atnProviders = (ObjectName[]) wls.getAttribute(defaultRealm,”AuthenticationProviders”);

for (ObjectName providerName : atnProviders) {
if (userEditor == null) {
ModelMBeanInfo info = (ModelMBeanInfo) wls.getMBeanInfo(providerName);
String className = (String) info.getMBeanDescriptor().getFieldValue(“interfaceClassName”);
if (className != null) {
String[] mba = (String[]) wls.invoke( MBTservice, “getSubtypes”, new Object[] { “” }, new String[] { “java.lang.String” });

for (String mb : mba)
if (className.equals(mb)) userEditor = providerName;

if (userEditor == null) throw new RuntimeException(“Could not retrieve user editor”);


out.println(“Creating User : testuser”);
wls.invoke(userEditor,”createUser”,new Object[] {“testuser”,”password”,”test user”},new String[] {“java.lang.String”, “java.lang.String”,”java.lang.String”});
out.println(“Created User : testuser”);

catch(Exception e){

Latest Comments

  1. partha July 1, 2010
    • admin July 1, 2010
  2. Pranxas January 7, 2011
    • Administrator January 11, 2011
  3. Corneliu February 9, 2011
  4. André Simões June 16, 2011
  5. Assaf August 19, 2013

Leave a Reply