2 Replies Latest reply on Jul 31, 2012 3:27 PM by raylite3

    Handling authentication failures during remote EJB invocation from client

    raylite3

      Hello,

      I am looking up and invoking a remote EJB from a standalone client using these instructions:

       

      https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

       

      But when I encounter authentication failures I see that a SaslException is logged but the exception I catch only has a IllegalStateException and has no root cause set on it.

       

      This is my client code:

       

      try {

            Hashtable<String, Object> jndiProperties = new Hashtable<String, Object>();     

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

            Context ctx;

            try {

              ctx = new InitialContext(jndiProperties);

           } catch (Exception ex) {   

              Throwable ex1 = ex.getCause();

              while (ex1 != null && ex1.getCause() != null) {

                 ex1 = ex1.getCause();

               }

              if (ex1 instanceof SaslException) {

                throw (SaslException)ex1;

              }

              throw ex;

           }

       

           RemoteEJB lookup = (RemoteEJB) ctx.lookup("ejb:/TestAuth//RemoteEJB!com.testauth.RemoteEJB");

           System.out.println(lookup.process("test"));

           } catch (Exception ex) {

              Throwable ex1 = ex.getCause();

              if (ex1 == null) {

                  System.err.println("No root cause");

              }

              while (ex1 != null && ex1.getCause() != null) {

                  ex1 = ex1.getCause();

              }

      }

       

      Is there any way I can catch authentication exceptions so they can be handled appropriately?