Results 1 to 4 of 4

Thread: Strange behaviour of JndiTemplate

  1. #1
    Join Date
    Oct 2004
    Location
    Moscow
    Posts
    32

    Default Strange behaviour of JndiTemplate

    Hello!

    I have configured spring JMX with SAP WAS. SAP WAS requires to pass user auth information to InitialContext like:

    Code:
    properties.put(Context.SECURITY_PRINCIPAL, this.username);
    properties.put(Context.SECURITY_CREDENTIALS, this.password);
    new InitialContext(properties);
    In order to lookup server I use JndiObjectFactoryBean and JndiTemplate.
    The user's auth information is passed as environment property of JndiTemplate.

    But I get
    Code:
    java.security.AccessControlException: access denied (javax.management.MBeanPermission javax.management.modelmbean.RequiredModelMBean#-[:
    I have extends JndiTemplate
    Code:
    public class CustomJndiTemplate extends JndiTemplate {
    
        private static Log logger = LogFactory.getLog(CustomJndiTemplate.class);
    
        protected Context createInitialContext() throws NamingException {
            return super.createInitialContext();
        }
    
        public Object lookup(final String string) throws NamingException {
            Object objMBeanServer = createInitialContext().lookup(string);
            return  objMBeanServer;
        }
    }

    It works!

    Then I change the code:
    Code:
    public class CustomJndiTemplate extends JndiTemplate {
    
        private static Log logger = LogFactory.getLog(CustomJndiTemplate.class);
    
        protected Context createInitialContext() throws NamingException {
            logger.debug("@@@@@@@ Environement=" + getEnvironment());
            return new InitialContext(getEnvironment());
        }
    
    
        public Object lookup(final String string) throws NamingException {
            logger.debug("@@@@@@@ Lookup=" + getEnvironment());
              return execute(new JndiCallback() {
    			public Object doInContext(Context ctx) throws NamingException {
                    logger.debug("@@@@@@@ Lookup2=" + ctx.getEnvironment());
                    return ctx.lookup(string);
    			}
    		});
        }
    }
    It doesn't work! The same exception.

    My Log content:

    Code:
    jmx.CustomJndiTemplate - @@@@@@@ Lookup={java.naming.security.principal=Administrator, java.naming.security.credentials=abcd1234}
    jmx.CustomJndiTemplate - @@@@@@@ Environement={java.naming.security.principal=Administrator, java.naming.security.credentials=abcd1234}
    jmx.CustomJndiTemplate$1 - @@@@@@@ Lookup2={java.naming.factory.initial=com.sap.engine.services.jndi.InitialContextFactoryImpl, java.naming.security.principal=Administrator, server=true, java.naming.security.credentials=abcd1234}
    jndi.JndiLocatorSupport - Located object with JNDI name [jmx]

    I suppose the problem is with inner class but I have no idea why it dosn't work.

    Could you explain why it doesn't work?

  2. #2

    Default

    your line of code new InitialContext() has to use the constructor with appropriate properties INCLUDING a context factory class name for WAS.

  3. #3
    Join Date
    Oct 2004
    Location
    Moscow
    Posts
    32

    Default

    Quote Originally Posted by jonnio View Post
    your line of code new InitialContext() has to use the constructor with appropriate properties INCLUDING a context factory class name for WAS.
    I am connectiong from local Web application. I suppose a context factory class is not necessary. It works fine without a context factory.

  4. #4

    Default

    Ahhh...so you get the default context factory which is some WAS class, I'm sure.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •