KEMBAR78
Changepwd Java | PDF | Areas Of Computer Science | Computing
0% found this document useful (0 votes)
94 views3 pages

Changepwd Java

This Java class provides a web service to change user passwords in WebLogic. It uses JMX to connect to the WebLogic server and invoke the changeUserPassword method on the security MBean, returning error messages for different failure cases.

Uploaded by

Prishan De Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views3 pages

Changepwd Java

This Java class provides a web service to change user passwords in WebLogic. It uses JMX to connect to the WebLogic server and invoke the changeUserPassword method on the security MBean, returning error messages for different failure cases.

Uploaded by

Prishan De Silva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

package Changepwd;

import java.io.IOException;
import java.net.MalformedURLException;
import javax.jws.WebMethod;
import javax.jws.WebService;
import
import
import
import
import

javax.management.MBeanServerConnection;
javax.management.ObjectName;
javax.management.remote.JMXConnector;
javax.management.remote.JMXConnectorFactory;
javax.management.remote.JMXServiceURL;

import java.util.HashMap;
import java.util.Hashtable;
import javax.naming.Context;
@WebService
public class Changepwd
{
private static JMXConnector jmxConnector = null;
private static MBeanServerConnection mBeanServerConnection = null;
private static String webLogicHostname = "localhost"; // Set to the weblogic
host
private static String webLogicPort = "7001"; // Set to the port of the admin
server on the weblogic instance
private static String webLogicUsername = "biadmin"; // Set to the weblogic a
dmin user
private static String webLogicPassword = "oracle01"; // Set to the password
of the weblogic admin user
private static final String validationFailed = "[Security:090237]";
private static final String mustBeEightChars = "[Security:090285]";
private static final String missingSpecialChars = "[Security:099116]";
public Changepwd() {} // for JAXB
@WebMethod(exclude = true)
public String changeUserPassword( String userId, String oldPassword, String
newPassword, String confirmPassword ) throws Exception
{
ObjectName securityMBeanName = new ObjectName("Security:Name=myrealmDefa
ultAuthenticator");
Object objUser[] = new Object[]{(userId), (oldPassword), (newPassword) }
;
String objStr[] = new String[]{("java.lang.String"), ("java.lang.String"
), ("java.lang.String") };
try
{
if ( confirmPassword.equals(newPassword) )
{
mBeanServerConnection.invoke(securityMBeanName, "changeUserPassw
ord", objUser, objStr);
return "Password successfully changed.";
}

else
{
return "New passwords do not match.";
}
}
catch (Exception e)
{
if( e.getCause().getMessage().contains( validationFailed ) )
return "Validation of old password failed.";
else if ( e.getCause().getMessage().contains( mustBeEightChars ) )
return "Password must be at least 8 characters long.";
else if ( e.getCause().getMessage().contains( missingSpecialChars )
)
return "Password must contain at least 1 number or special chara
cter.";
else
return "Can not reset password at this time. Please contact an A
dministrator.";
}
}
@WebMethod(exclude = true)
public static void initConnection(String hostname, String portString) throws
IOException, MalformedURLException
{
Integer portInteger = Integer.valueOf(portString);
int port = portInteger.intValue();
String mserver = "/weblogic.management.mbeanservers.runtime";
JMXServiceURL serviceURL = new JMXServiceURL("service:jmx:iiop:///jndi/i
iop://" + hostname + ":" + port + mserver);
Hashtable h = new Hashtable();
String[] credentials = new String[] {webLogicUsername, webLogicPassword
};
h.put("jmx.remote.credentials", credentials);
jmxConnector = JMXConnectorFactory.connect(serviceURL, h);
//jmxConnector = JMXConnectorFactory.connect(serviceURL);
mBeanServerConnection = jmxConnector.getMBeanServerConnection();
}
/*@WebMethod(exclude = true)
public static void main(String[] args) throws Exception
{
}*/
public String passwordChange( String userId, String oldPassword, String newP
assword, String confirmPassword ) throws Exception
{
Changepwd c = new Changepwd();
initConnection(webLogicHostname, webLogicPort);
String result = c.changeUserPassword( userId, oldPassword, newPassword,
confirmPassword );
jmxConnector.close();

return result;
}
}

You might also like