Jay SenSharma

Jay SenSharma

Here is a Simple example of changing the MinimumPasswordLength using JMX code. This sample uses New style of MBeans so u can use this JMX code for Any WerbLogic Version from WLS9.x onwards. Thanks to Mr. Alecomputacao for giving me an idea for write this very useful JMX code. http://middlewaremagic.com/weblogic/2010/08/28/changing-userlockoutduration-using-jmx-9-x-and-above/#comment-1897

This JMX code illustrates that if we want to make any configuration related changes then first of all we need to get the “EditServiceMBean” object reference first of all. This is must because from WLS9.x onwards we have Change Management Feature added as part of WebLogic Server .. It means until you dont press the “Lock & Edit” Button on the AdminConsole you cannot make any changes.

Step1). Create a directory somewhere in your file system like :  F:DELETE919

Step2). Write the following JMX Code inside the above directory “ChangeMinimumPasswordLength.java”

import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Hashtable;
import javax.management.Attribute;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import javax.naming.Context;
import weblogic.management.configuration.DomainMBean;
import weblogic.management.configuration.SecurityConfigurationMBean;
import weblogic.management.runtime.RealmRuntimeMBean;
import weblogic.management.security.RealmMBean;
import weblogic.management.security.authentication.AuthenticationProviderMBean;
import weblogic.management.security.authentication.UserLockoutManagerMBean;
import weblogic.management.security.authentication.UserPasswordEditorMBean;
import weblogic.security.UserLockoutManagerRuntime;
import weblogic.security.acl.internal.DefaultRealmImpl;
import weblogic.security.providers.authentication.DefaultAuthenticatorMBean;

public class ChangeMinimumPasswordLength {
private static MBeanServerConnection connection;
private static JMXConnector connector;
private static final ObjectName service;

try {
service = new ObjectName("com.bea:Name=EditService,Type=weblogic.management.mbeanservers.edit.EditServiceMBean");
catch (MalformedObjectNameException e)
throw new AssertionError(e.getMessage());

public static void initConnection(String hostname, String portString, String username, String password) throws IOException,MalformedURLException
String protocol = "t3";
Integer portInteger = Integer.valueOf(portString);
int port = portInteger.intValue();
String jndiroot = "/jndi/";
String mserver = "weblogic.management.mbeanservers.edit";
JMXServiceURL serviceURL = new JMXServiceURL(protocol, hostname, port,jndiroot + mserver);
Hashtable h = new Hashtable();
h.put(Context.SECURITY_PRINCIPAL, username);
h.put(Context.SECURITY_CREDENTIALS, password);
connector = JMXConnectorFactory.connect(serviceURL, h);
connection = connector.getMBeanServerConnection();

public ObjectName startEditSession() throws Exception
ObjectName cfgMgr = (ObjectName) connection.getAttribute(service,"ConfigurationManager");
ObjectName domainConfigRoot = (ObjectName)
connection.invoke(cfgMgr,"startEdit", new Object[] { new Integer(60000).  new Integer(120000) }, new String[] { "java.lang.Integer","java.lang.Integer" });
if (domainConfigRoot == null)
throw new Exception("Somebody else is editing already");
return domainConfigRoot;

public void editUserLockoutminPassLength(ObjectName cfgRoot,Integer minPassLength) throws Exception
Attribute newminPassLength = new Attribute("MinimumPasswordLength", minPassLength);
connection.setAttribute(cfgRoot, newminPassLength);
System.out.println("Changed the MinimumPasswordLength to " +minPassLength);

public ObjectName activate() throws Exception
ObjectName cfgMgr = (ObjectName) connection.getAttribute(service,"ConfigurationManager");
ObjectName task = (ObjectName) connection.invoke(cfgMgr, "activate",new Object[] { new Long(120000) }, new String[] { "java.lang.Long" });
return task;

public static void main(String[] args) throws Exception
String hostname = args[0];
String portString = args[1];
String username = args[2];
String password = args[3];
ChangeMinimumPasswordLength ewb = new ChangeMinimumPasswordLength();
initConnection(hostname, portString, username, password);
ObjectName cfgMgr = (ObjectName) connection.getAttribute(service,"ConfigurationManager");
ObjectName cfgRoot = ewb.startEditSession();
Integer minPassLength=new Integer("3");
ewb.editUserLockoutminPassLength(new ObjectName("Security:Name=myrealmDefaultAuthenticator").  minPassLength);
connection.invoke(cfgMgr, "save", null, null);
Step3). Now open a command prompt and then run the “setWLSEnv.cmd” script to set the Environment like “CLASSPATH” and “PATH” in your command prtompt.
Step4). run the Above program like following:

Running the ChangeMinPassword_Jmx Code

Running the ChangeMinPassword_Jmx Code

Step5). Verify from the Server STDOUT that the changes gets reflected on Server or not….(NOTE: You will have to restart your Server sothat the changes can take effect)
Server_Stdout_AfterMinPassChange JMX

Server_Stdout_AfterMinPassChange JMX

Jay SenSharma
If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.