Enterprise Java Development@TOPIC@

Chapter 112. EJB Security RMI Client

112.1. JBoss Remoting
112.2. EJBClient
112.3. Security Sanity Check
112.4. Summary

  • factory.initial set to JBoss Remoting implementation

  • provider.url set to address of JBoss server

  • ejb.context set to "true" to use this library to establish EJB contexts

  • url.pkgs option and used for alternate namespaces (e.g., "ejb:")


  • Using generic JBoss Remoting JNDI name


  • Client provides credentials in JNDI prior to obtaining InitialContext

  • Must use current JNDI Context to lookup @Remote


  • Client can switch credentials with a change in InitialContexts and @Remote reference


  • Fixed credentials can be placed in jndi.properties when known and not changing


  • factory.initial not important, will delegate to naming extension

  • url.pkgs defines Java package with EJBClient extensions

  • provider.url ignored in this case

  • ejb.context not used and set to false in this case


  • SSL_ENABLED=false - example setup does not yet cover SSL and would require trustStore

  • SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER - disallowing default user to be set to $local

  • callback.handler.class=info.ejava...BasicCallbackHandler - provider credentials via callback

Figure 112.8. CallbackHandler used to Provide Credentials

import javax.security.auth.callback.CallbackHandler;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.sasl.RealmCallback;
public class BasicCallbackHandler implements CallbackHandler {
    private String name;
    private char[] password;
    private String realm="ApplicationRealm";
    public BasicCallbackHandler(String name, String password) {
        this.name = name;
        setPassword(password);
    }
    public void handle(Callback[] callbacks) 
        throws UnsupportedCallbackException, IOException {
        for (Callback cb : callbacks) {
            if (cb instanceof NameCallback) {
                ((NameCallback)cb).setName(name);                
            }
            else if (cb instanceof PasswordCallback) {
                ((PasswordCallback)cb).setPassword(password);
            }
            else if (cb instanceof RealmCallback) {
                ((RealmCallback)cb).setText(realm);
            }
            else {
                throw new UnsupportedCallbackException(cb);
            }
        }
    }
}

  • Class was registered in jboss-ejb-client.properties

  • Class responds to handle() callbacks


  • CallbackHandler accessed at class-scope

  • Must register credentials at class level

  • Credentials tied to connection. Cannot change identities without breaking and re-establishing connection (with proprietary API)


  • EJBClient stores credentials with connection

  • Must establish new connection to have CallbackHandler called again


  • No need to get new InitialContext or new lookup of @Remote


  • Fixed credentials can be placed in jboss-ejb-client.properties when known and not changing


  • Implement security query methods in a EJB


  • Client asserts security query results to verify setup correctly


  • EJBAccessException thrown when accessing method not allowed


  • Access to method protected by declarative security granted

  • Results of programmatic security checks returned in formatted text string