Tuesday, July 3, 2012

Changing user password in OBIEE 11G


Hi,


Just use the below java code (Changepwd.java) and compile and run using java tool(JDEV,Netbeans etc)  and get the jar/war file and deploy the war file via Weblogic console then call the link (jmx bean url) in your analysis by using Action link method.
-------------------------------------------------------------------------------
package obiee.chngpwd;


import java.io.IOException;
import java.util.Set;


import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanParameterInfo;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;


public class Changepwd {
private JMXConnector jmxConnector = null;
private MBeanServerConnection mBeanServerConnection = null;


public Changepwd() throws IOException, MalformedObjectNameException, NullPointerException, InstanceNotFoundException, IntrospectionException, ReflectionException {
JMXServiceURL serviceURL = new JMXServiceURL("service:jmx:rmi://IP/jndi/rmi://IPaddress:1090/jmxconnector");
System.out.println("Connecting to: " + serviceURL);


jmxConnector = JMXConnectorFactory.connect(serviceURL);
mBeanServerConnection = jmxConnector.getMBeanServerConnection();
Set<ObjectName> mbeans = mBeanServerConnection.queryNames(null, null);
for (ObjectName mbeanName : mbeans) {
System.out.println(mbeanName);
System.out.println("Service:" + mbeanName.getKeyPropertyListString() + "Domain:" + mbeanName.getDomain());

}
//ObjectName securityMBeanName = new ObjectName("jboss:service=JNDIView");
//ObjectName securityMBeanName = new ObjectName("jboss:service=JNDIView");
ObjectName securityMBeanName = new ObjectName("Security:Name:myrealmDefaultAuthenticator");
MBeanInfo mbeanInfo = mBeanServerConnection.getMBeanInfo(securityMBeanName);
MBeanOperationInfo[] opInfo = mbeanInfo.getOperations();
        System.out.println("Security Operations: ");
        for(int o = 0; o < opInfo.length; o ++) {
            MBeanOperationInfo op = opInfo[o];


            String returnType = op.getReturnType();
            String opName     = op.getName();
            System.out.print(" + " + returnType + " " + opName + "(");


            MBeanParameterInfo[] params = op.getSignature();
            for(int p = 0; p < params.length; p++)  {
                MBeanParameterInfo paramInfo = params[p];


                String pname = paramInfo.getName();
                String type  = paramInfo.getType();


                if (pname.equals(type)) {
                    System.out.print(type);
                } else {
                    System.out.print(type + " " + securityMBeanName);
                }


                if (p < params.length-1) {
                    System.out.print(','); 
                }
            }
            System.out.println(")");
        }
Object objUser[] = new Object[]{("userId"), ("oldPassword"), ("newPassword") };
//Object objUser[] = new Object[]{("destroy")};
String objStr[] = new String[]{("java.lang.String"), ("java.lang.String"), ("java.lang.String") };
//String objStr[] = new String[]{("java.lang.String")};


try {
//mBeanServerConnection.addNotificationListener(securityMBeanName, new PasswordListener(), null, null);
//Object responseObj = mBeanServerConnection.invoke(securityMBeanName, "jbossInternalLifecycle", objUser, objStr);
Object responseObj = mBeanServerConnection.invoke(securityMBeanName, "changeUserPassword", objUser, objStr);
System.out.println("Response:" + responseObj);




} catch (InstanceNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MBeanException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ReflectionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* @param args
* @throws IOException 
* @throws NullPointerException 
* @throws MalformedObjectNameException 
* @throws ReflectionException 
* @throws IntrospectionException 
* @throws InstanceNotFoundException 
*/
public static void main(String[] args) throws MalformedObjectNameException, NullPointerException, IOException, InstanceNotFoundException, IntrospectionException, ReflectionException {
// TODO Auto-generated method stub
new Changepwd();


}


}


For More about change password info:
http://www.rittmanmead.com/2011/10/changing-your-password-in-obiee-11g/
 
Thanks,
Satya Ranki reddy.
 

No comments:

Post a Comment