0 Replies Latest reply on Oct 11, 2017 10:59 PM by ww20171011

    How to programmtically set Principal and Credential in InitialContext

    ww20171011

      Hi all

      I am working on JEE project migrated from Webloic 10 to Wildfly 10.

      I have classA calling classB in which it checks whether the caller is a certain role. In WLS10, the classA has some code like:

            weblogic.jndi.Environment env = new weblogic.jndi.Environment();

            env.setProviderUrl("t3://localhost:80");

            env.setSecurityPrincipal("BATCH_USER");

            env.setSecurityCredentials("BATCH_XYZ");

            // Instantiate JNDI context

            return env.getInitialContext();

       

      In Wildfly10, I am trying to convert the above code to:

          Properties env = new Properties();

          env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

          env.put( Context.SECURITY_PRINCIPAL, "BATCH_USER");

          env.put( Context.SECURITY_CREDENTIALS, "BATCH_XYZ");

         // Instantiate JNDI context

          return new InitialContext( env );

       

      However in classB, new InitialContext().getCallerPrincipal().getName() always returns "anonymous" instead of "BATCH_USER"

      I am not sure what I am missing here

      Thanks very much in advance

       

      W.W