4 Replies Latest reply on Dec 2, 2014 12:51 PM by James Sodium

    Migration problem from 5.0 to 5.1 - Authenticate principal null

    vlad010788 Newbie

      Hello,

       

      I encountered a problem and I hope someone can help me with it. Maybe it is a simple one but i can't figure it out. I am a beginer in JBOSS.

       

      I have an eclipse plugin from where I connect ot Jboss to obtain some informations and restart some beans. Until now i was using Jboss 5.0 and it was working fine. I have migrated to Jboss 5.1 and now i have the following error.

       

      java.lang.SecurityException: Failed to authenticate principal=null, securityDomain=jmx-console

                at org.jboss.jmx.connector.invoker.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:89)

                at org.jboss.mx.server.Invocation.invoke(Invocation.java:90)

                at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)

                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)

                at org.jboss.system.server.jmx.LazyMBeanServer.invoke(LazyMBeanServer.java:283)

                at org.jboss.invocation.jrmp.server.JRMPProxyFactory.invoke(JRMPProxyFactory.java:180)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

                at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:157)

                at org.jboss.mx.server.Invocation.dispatch(Invocation.java:96)

                at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)

                at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)

                at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:668)

                at org.jboss.system.server.jmx.LazyMBeanServer.invoke(LazyMBeanServer.java:283)

                at org.jboss.invocation.jrmp.server.JRMPInvoker$MBeanServerAction.invoke(JRMPInvoker.java:855)

                at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:422)

                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                at java.lang.reflect.Method.invoke(Method.java:597)

                at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)

                at sun.rmi.transport.Transport$1.run(Transport.java:159)

                at java.security.AccessController.doPrivileged(Native Method)

                at sun.rmi.transport.Transport.serviceCall(Transport.java:155)

                at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)

                at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)

                at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)

                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

                at java.lang.Thread.run(Thread.java:619)

                at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)

                at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)

                at sun.rmi.server.UnicastRef.invoke(Unknown Source)

                at org.jboss.invocation.jrmp.server.JRMPInvoker_Stub.invoke(Unknown Source)

                at org.jboss.invocation.jrmp.interfaces.JRMPInvokerProxy.invoke(JRMPInvokerProxy.java:133)

                at org.jboss.invocation.InvokerInterceptor.invokeInvoker(InvokerInterceptor.java:241)

                at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:181)

                at org.jboss.jmx.connector.invoker.client.InvokerAdaptorClientInterceptor.invoke(InvokerAdaptorClientInterceptor.java:66)

                at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:70)

                at org.jboss.proxy.ClientMethodInterceptor.invoke(ClientMethodInterceptor.java:74)

                at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:101)estabished connection

       

                 at $Proxy0.getAttribute(Unknown Source)

       

      The source code is :

       

      import javax.management.ObjectName;

      import javax.naming.Context;

      import javax.naming.InitialContext;

      import org.jboss.jmx.adaptor.rmi.RMIAdaptor;

       

       

       

                private RMIAdaptor server = null;

                private ObjectName bean;

                          String providerUrl =  "localhost:1099";

                          Properties p = new Properties();

       

                p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                          p.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                          p.setProperty(Context.PROVIDER_URL, providerUrl);

                          p.setProperty(Context.SECURITY_PRINCIPAL, "admin");

                          p.setProperty(Context.SECURITY_CREDENTIALS, "admin");

       

                InitialContext ic = new InitialContext(p);

                server = (RMIAdaptor) ic.lookup("jmx/invoker/RMIAdaptor");

       

                          String  pathToTempDir ;

       

                          bean = new ObjectName("jboss.system:service=MainDeployer");

               pathToTempDir = server.getAttribute(bean, "TempDirString").toString(); // here is where it fails;

       

       

      The application does not take in consideration my username and password. I get the same error if i comment this lines .

                p.setProperty(Context.SECURITY_PRINCIPAL, "admin");

                p.setProperty(Context.SECURITY_CREDENTIALS, "admin");

      It is normal to get the error the second time, but not the first time.

       

      I apologize if I have posted this in the wrong place or haven't explained my problem correctly. I would be happy to give more details if needed.

       

      Thank you in advance,

      Vlad

        • 1. Re: Migration problem from 5.0 to 5.1 - Authenticate principal null
          vlad010788 Newbie

          if you know other ways of doing this please tell me. I would like to try .

          Thank you.

          Vlad

          • 2. Migration problem from 5.0 to 5.1 - Authenticate principal null
            Wolfgang Knauf Master

            Hi,

             

            I think you have to perform a "login" yourself. Take a look at the "security FAQ" (http://community.jboss.org/wiki/SecurityFAQ ) - it seems to be a similar problem as question 10.

             

            By the way: your provider url should be "jnp://...":

             

            String providerUrl =  "jnp://localhost:1099";

             

            Hope this helps

             

            Wolfgang

            1 of 1 people found this helpful
            • 3. Re: Migration problem from 5.0 to 5.1 - Authenticate principal null
              vlad010788 Newbie

              Thank you very much for your answer.

              I found out why it doen't work now. There where some differences in the conf/login-config.xml beetwen the 2 versions.

              The 5.0 version allowed unauthenticated access by adding this line at the jmx-console :

              <module-option name="unauthenticatedIdentity">anonymous</module-option>

               

               

              So my authentication wasn't good in the 5.0 version either, but it didn't trow any error as it did not matter.

              I will try to use the sugested authentication type. Hope I will figure it out.

               

              Thank you.

              Vlad

              • 4. Re: Migration problem from 5.0 to 5.1 - Authenticate principal null
                James Sodium Newbie

                import org.jboss.security.SecurityAssociation;

                import org.jboss.security.SimplePrincipal;

                 

                and something like this then...

                 

                 

                MBeanServerConnection serverConnection = null;

                Context context = null;

                HashMap props = new HashMap();

                props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                props.put(Context.PROVIDER_URL, "localhost:1099");

                props.put("jnp.disableDiscovery", "true");


                try
                {

                  ObjectName queueObjectName = ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName);

                  context = new InitialContext(EnvHelp.mapToHashtable(props));

                  serverConnection = (MBeanServerConnection) context.lookup("jmx/invoker/RMIAdaptor");

                  Queue queue = (Queue) context.lookup(queueName)

                 

                  SecurityAssociation.setPrincipal(new SimplePrincipal("principal"));

                  SecurityAssociation.setCredential("password");

                 

                  JMSQueueControl queueControl = (JMSQueueControl) MBeanServerInvocationHandler.newProxyInstance( serverConnection, queueObjectName, JMSQueueControl.class, false );

                 

                  System.out.println(queueControl.getName() + " contains " + queueControl.getMessageCount() + " messages");

                } catch (Exception e) {

                  e.printStackTrace();

                } finally {

                  SecurityAssociation.popRunAsIdentity();

                   try {

                  context.close();

                  } catch (Exception e) { }

                 

                }