Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7866491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:24:59+00:00 2026-06-03T00:24:59+00:00

I’m trying to create users in WebLogic (10.3.4) programmatically from a simple standalone Java

  • 0

I’m trying to create users in WebLogic (10.3.4) programmatically from a simple standalone Java client (one class –> two methods: createWeblogicUser() & main()).

public void createWeblogicUser() {
try {
    Hashtable<String, String> env = new Hashtable<String, String>();
    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://myserver:7001");

    InitialContext ctx = new InitialContext(env);
    MBeanServer wls = (MBeanServer) ctx.lookup("java:comp/env/jmx/runtime");

    ObjectName userEditor = null;
    ObjectName mBeanTypeService = new ObjectName( "com.bea:Name=MBeanTypeService, Type=weblogic.management.mbeanservers.MBeanTypeService");
    ObjectName rs = new ObjectName("com.bea:Name=RuntimeService, Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean");
    ObjectName domainMBean = (ObjectName) wls.getAttribute(rs, "DomainConfiguration");
    ObjectName securityConfig = (ObjectName) wls.getAttribute(domainMBean, "SecurityConfiguration");
    ObjectName defaultRealm = (ObjectName) wls.getAttribute(securityConfig, "DefaultRealm");
    ObjectName[] authProviders = (ObjectName[]) wls.getAttribute(defaultRealm, "AuthenticationProviders");

    for(ObjectName providerName : authProviders) {
        if(userEditor == null) {
            ModelMBeanInfo info = (ModelMBeanInfo) wls.getMBeanInfo(providerName);
            String className = (String) info.getMBeanDescriptor().getFieldValue("interfaceClassName");
            if(className != null) {
                String[] mba = (String[]) wls.invoke(mBeanTypeService
                                                    , "getSubtypes"
                                                    , new Object[] {"weblogic.management.security.authentication.UserEditorMBean"}
                                                    , 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");

        try {
            wls.invoke(userEditor
                        , "createUser"
                        , new Object[] {"wls_user", "password123","User created programmatically."}
                        , new String[] {"java.lang.String", "java.lang.String","java.lang.String"}
            );
        }
        catch(Exception e){
            e.printStackTrace();
        }

        ctx.close();
    }
}
catch(Exception ex) {
    ex.printStackTrace();
}

}

Any ideas on what the context lookup I should be making? “java:comp” throws a javax.naming.NameNotFoundException; looks like I can use that only from w/in a container.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T00:25:01+00:00Added an answer on June 3, 2026 at 12:25 am

    Got it to work.

    private void createWeblogicUser(String username) {
    try {
        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(Context.SECURITY_PRINCIPAL, "weblogic");
        env.put(Context.SECURITY_CREDENTIALS, "weblogic");
    
        String hostname = "myserver";
        int port = 7001;
        String protocol = "rmi";
        String url= new String("/jndi/iiop://myserver:7001/weblogic.management.mbeanservers.domainruntime");
    
        JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port, url);
        JMXConnector connector = JMXConnectorFactory.connect(serviceURL, env);
        MBeanServerConnection connection = connector.getMBeanServerConnection();
    
        ObjectName userEditor = null;
        ObjectName mBeanTypeService = new ObjectName( "com.bea:Name=MBeanTypeService,Type=weblogic.management.mbeanservers.MBeanTypeService");
        ObjectName rs = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
        ObjectName domainMBean = (ObjectName) connection.getAttribute(rs, "DomainConfiguration");
        ObjectName securityConfig = (ObjectName) connection.getAttribute(domainMBean, "SecurityConfiguration");
        ObjectName defaultRealm = (ObjectName) connection.getAttribute(securityConfig, "DefaultRealm");
        ObjectName[] authProviders = (ObjectName[]) connection.getAttribute(defaultRealm, "AuthenticationProviders");
    
        for(ObjectName providerName : authProviders) {
            System.out.println("Auth provider is: " + providerName) ;
    
            if(userEditor == null) {
                ModelMBeanInfo info = (ModelMBeanInfo) connection.getMBeanInfo(providerName);
                String className = (String) info.getMBeanDescriptor().getFieldValue("interfaceClassName");
                System.out.println("className is: " + className) ;
    
                if(className != null) {
                    String[] mba = (String[]) connection.invoke(mBeanTypeService
                                            , "getSubtypes"
                                            , new Object[] {"weblogic.management.security.authentication.UserEditorMBean"}
                                            , new String[] {"java.lang.String"}
                                        );
                    for(String mb : mba) {
                        System.out.println("Model Bean is: " + mb) ;
                        if(className.equals(mb)) {
                            System.out.println("Found a macth for the model bean and class name!") ;
                            userEditor = providerName;
                        }
                    }
                }
            }
        }
    
        if(userEditor == null)
            throw new RuntimeException("Could not retrieve user editor");
    
        try {
            connection.invoke(userEditor
                        , "createUser"
                        , new Object[] {username, "password123","User created programmatically."}
                        , new String[] {"java.lang.String", "java.lang.String","java.lang.String"}
            );
    
            System.out.println("User created successfully") ;
        }
        catch(Exception e){
            e.printStackTrace();
        }
    
        connector.close();
    
    }
    catch(Exception ex) {
        ex.printStacktrace();
    }
    

    }

    You need only weblogic.jar and wljmxclient.jar in classpath. I ran this against JDK 1.6.0_29. I have to add that I ran this on a machine on which WebLogic was installed as well. So the classpath entries were fully qualified path names to the jar files.

    One “gotcha” I came across:
    While providing the “com.bea:Name=XXXX,Type=XXXX”, DONOT give a space between anything – not the colon; not the comma; nothing – I spent sometime debugging this, before it finally hit it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.