7 Replies Latest reply: Nov 21, 2012 4:35 PM by eagle_eye RSS

    Password Change on OBIEE using a Webservice...

    eagle_eye
      Hi All,
      With a lot of help from expets on the web, I have put together a webservice routine which allows a user to change their password from within a dashboard. I have used Oracle JDeveloper 11g Release 2 11.1.2.1.0, Java(TM) Platform 1.6.0_24. The source code is as below.

      package obieeweb;
      import java.lang.management.ManagementFactory;
      import java.net.InetAddress;
      import java.util.HashMap;
      import java.util.Set;

      import javax.jws.WebMethod;
      import javax.jws.WebParam;
      import javax.jws.WebService;
      import javax.management.MBeanServer;
      import javax.management.ObjectName;
      import javax.management.remote.JMXConnectorServer;
      import javax.management.remote.JMXConnectorServerFactory;
      import javax.management.remote.JMXServiceURL;

      @WebService(name = "STLOBIEEWebServices", serviceName = "STLOBIEEWebServicesService", portName = "STLOBIEEWebServicesPort")
      public class OBIEEWebServices {


      @WebMethod
      public String OBIEEWebService(@WebParam(name = "arg0")
      String userId, @WebParam(name = "arg1")
      String oldPassword, @WebParam(name = "arg2")
      String newPassword, @WebParam(name = "arg3")
      String confirmPassword) throws Exception
      {
      MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
      HashMap env = new HashMap();


      final String hostname = InetAddress.getLocalHost().getHostName();
      final int port = 10000;
      JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi://"hostname":"port"/jndi/rmi://"hostname":"port"/jmxrmi");
      JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl,env, mbs);

      ObjectName securityMBeanName = new ObjectName("Security:Name=myrealmDefaultAuthenticator");
      Object[] params = new Object[] { userId, oldPassword, newPassword};
      String[] signature = new String[] {"java.lang.String", "java.lang.String", "java.lang.String"};
      if (newPassword.equals(confirmPassword)) {
      try
      {
      mbs.invoke(securityMBeanName, "changeUserPassword", params,signature);
      }
      catch(Exception e)
      {
      return e+"|Error changing Password.";
      }
      return "Password changed successfully.";
      }
      else
      {
      return "Passwords don't match. Try again.";
      }
      }


      @WebMethod(exclude = true)
      public static void main() throws Exception {
      String confirmPassword, newPassword, oldPassword, userId;
      confirmPassword = " ";
      newPassword = " ";
      oldPassword = " ";
      userId = " ";
      OBIEEWebServices ow = new OBIEEWebServices();
      ow.OBIEEWebService( userId, oldPassword, newPassword, confirmPassword);
      }
      }

      I get the following error

      weblogic.management.NoAccessRuntimeException: [Management:141102]Subject: principals=[] does not have access to perform Admin actions.|Error changing Password.

      After serarching through the forums, it appears that this piece of code should run as an admin user instead of anynymous. Various suggestions either did not work or did not compile. Any suggestions would be most appreciated. I must admit I am a newbie and have not had a lot of exposure in this area.

      Thanks
        • 1. Re: Password Change on OBIEE using a Webservice...
          vladodias
          Hi,

          Have you tried something like this?
          String[] credentials = new String[] {"admin","adminadmin"};
          env.put(JMXConnector.CREDENTIALS, credentials);
          ...
          ...
          MBeanServer mbserver = ManagementFactory.getPlatformMBeanServer();
          final JMXServiceURL jmxUrl = new JMXServiceURL(jmxRmiStr);
          final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxUrl,env);
          Have a look at these...
          http://openejb.apache.org/examples-trunk/dynamic-proxy-to-access-mbean/
          https://subversion.assembla.com/svn/VikrantJMXMonitor/src/org/rrd4j/demo/JMXDemoClient.java

          Cheers,
          Vlad
          • 2. Re: Password Change on OBIEE using a Webservice...
            eagle_eye
            Hi Vlad,
            thanks for your prompt reply. I am trying to plug in this information into my code to make it work. Some clarification on the following

            final String jmxRmiStr ="service:jmx:rmi:///jndi/rmi:<<<<my server id: port>>>>>/jmxrmi"; -- server id and port to be replaceed
            String[] credentials = new String[] {"admin","adminadmin"}; -- is this the username and password of a user that has admin privs

            last but not least, does this go in the "public static void main()" section of my code. I am a newbie to Java and Webservices, hence the confusion and thanks for your help.
            Regards
            Anup
            • 3. Re: Password Change on OBIEE using a Webservice...
              vladodias
              eagle_eye wrote:
              final String jmxRmiStr ="service:jmx:rmi:///jndi/rmi:<<<<my server id: port>>>>>/jmxrmi"; -- server id and port to be replaceed
              yes, you already did that in your code as serviceUrl
              String[] credentials = new String[] {"admin","adminadmin"}; -- is this the username and password of a user that has admin privs
              yes
              >
              last but not least, does this go in the "public static void main()" section of my code. I am a newbie to Java and Webservices, hence the confusion and thanks for your help.
              no, that should be in the web service method


              Assuming that the code you posted above was working but without admin privileges, you just have to add the environment part to the code...

              Where you have this...
              final String hostname = InetAddress.getLocalHost().getHostName();
              final int port = 10000;
              JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi://"hostname":"port"/jndi/rmi://"hostname":"port"/jmxrmi");
              JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl,env, mbs);
              
              ObjectName securityMBeanName = new ObjectName("Security:Name=myrealmDefaultAuthenticator");
              You should have this...
              final String hostname = InetAddress.getLocalHost().getHostName();
              final int port = 10000;
              JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi://"hostname":"port"/jndi/rmi://"hostname":"port"/jmxrmi");
              
              //
              String[] credentials = new String[] {"admin","adminadmin"};
              env.put(JMXConnector.CREDENTIALS, credentials);
              //
              
              
              JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl,env, mbs);
              
              ObjectName securityMBeanName = new ObjectName("Security:Name=myrealmDefaultAuthenticator");
              I didn't verify syntax... But you'll get the idea

              Cheers,
              Vlad
              • 4. Re: Password Change on OBIEE using a Webservice...
                eagle_eye
                Thanks for the update Vlad. made the following changes ...

                JMXServiceURL serviceUrl = new JMXServiceURL("service:jmx:rmi://"+hostname+":"+port+"/jndi/rmi://"+hostname+":"+port+"/jmxrmi");
                // new code added
                String[] credentials = new String[] {"weblogic","********"};
                env.put(JMXConnector.CREDENTIALS, credentials);
                // end of new code
                JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl, env, mbs);

                Get the following error...not sure if I did the right thing.

                weblogic.management.NoAccessRuntimeException: [Management:141102]Subject: principals=[] does not have access to perform Admin actions.|Error changing Password

                Regards
                Anup
                • 5. Re: Password Change on OBIEE using a Webservice...
                  vladodias
                  Code looks alright... But, clearly is not passing the credentials... The problem is the way to pass the credentials may vary among implementations...

                  Weblogic may be different than the samples that are on the public domain... Either the env is not right or the way to get the mbean instance is not right, maybe both...

                  Will do a little more research and get back to you...
                  • 6. Re: Password Change on OBIEE using a Webservice...
                    vladodias
                    Found the appropriated documentation... It says...
                    Oracle recommends that you use WebLogic Server classes to connect from remote JMX clients. However, it is possible for remote JMX clients to connect to a WebLogic Server JMX agent using only the classes in the JDK. To do so....
                    I believe you're not using the recommended approach... So it's up to you if you want to change your approach or perform the steps needed to connect via JDK only...

                    The document has a complete example for the recommended approach... Example 4-2 works, I've tested...

                    Have a look at...
                    http://docs.oracle.com/cd/E23943_01/web.1111/e13728/accesswls.htm#JMXCU144

                    Cheers,
                    Vlad
                    • 7. Re: Password Change on OBIEE using a Webservice...
                      eagle_eye
                      Thanks Vlad, I will have a read and try this approach and let you know how I go. You have been really helpful and prompt mate, a beer is on me if you are ever down in Melbourne.
                      Cheers
                      Anup