JBoss Community

Re: remote ejb client username is encrypted at the server(JBOSS7.1 CR1)

created by apparaonali in JBoss AS 7 Development - View the full discussion

Thanks for your quick reply.

 

When my test sesion bean trying to get the principal from the EJBContext, it is throwing the above error. Please find the detais of my test below.

 

TestBean:

=======

 

 

 

 

@Stateless

@SecurityDomain(value = "AppuLogin")

public class SessionBean implements

SessionBeanInterface {

     @Resource private EJBContext context;

          Principal pp =  context.getCallerPrincipal();

     @Override

     public String getPrincipal() {

          System.out.println(pp.toString());

 

 

          return (String) (context.getCallerPrincipal().getName());

     }

 

 

 

 



#

 

}

 

Standalone Remote Client code:

=========================

public class RemoteEJBClient {
   
    private static final String USER_LOGIN_NAME = "admin";
    private static final String USER_PASSWORD = "admin";
   
    static {
        Security.addProvider(new JBossSaslProvider());
    }

   
    public static final String AUTH_LOGIN_CONFIG = "java.security.auth.login.config";
   
    public static final String AUTH_CONF = "/auth.conf";

    public static void main(String[] args) throws Exception {
       
        if (System.getProperties().getProperty(RemoteEJBClient.AUTH_LOGIN_CONFIG) == null) {
            URL url = RemoteEJBClient.class.getClass().getResource(RemoteEJBClient.AUTH_CONF);
            if (url != null) {
                System.getProperties().setProperty(RemoteEJBClient.AUTH_LOGIN_CONFIG, url.toString());
            }
        }
       

        AppCallbackHandler callbackHandler = new AppCallbackHandler(USER_LOGIN_NAME, USER_PASSWORD.toCharArray());
        LoginContext loginContext = new LoginContext("logincontextname", callbackHandler);
        loginContext.login();

       
        final Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        final Context context = new InitialContext(jndiProperties);


        invokeStatelessBean(context);
    }

    private static void invokeStatelessBean(Context context) throws NamingException, LoginException {

        final SessionBeanInterface statelessSessionBeanInterface = lookupRemoteStatelessCalculator(context);
        System.out.println("Obtained a remote stateless SessionBeanInterface for invocation");
        try {
            final String principal = statelessSessionBeanInterface.getPrincipal();
            System.out.println("EJB principal " + statelessSessionBeanInterface.getPrincipal());
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }


    private static SessionBeanInterface lookupRemoteStatelessCalculator(Context context) throws NamingException, LoginException {

       

        final String appName = "TestEAR";
        final String moduleName = "TestEJB";
        final String distinctName = "";
        final String beanName = "SessionBean";
        final String viewClassName = SessionBeanInterface.class.getName();
        System.out.println("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);

        return (SessionBeanInterface) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName
                + "!" + viewClassName);
    }

}

 

Client ejb properties:

===============

 

 

 

 

 

 

 

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

 

remote.connections=default

 

remote.connection.default.host=

localhost

 

remote.connection.default.port = 4447

remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

 

remote.connection.two.host=

localhost

 

remote.connection.two.port = 4447

remote.connection.two.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

 

aut.conf:

======

logincontextname

{

org.jboss.security.ClientLoginModule required

;

};

Reply to this message by going to Community

Start a new discussion in JBoss AS 7 Development at Community