6 Replies Latest reply on Apr 12, 2013 1:37 AM by jaikiran pai

    Handling EJB authentication failures

    raylite3 Apprentice

      Hello,

       

      I am using JBoss 7.2.0.Final. I am testing the EJB remote client example (https://github.com/jboss-jdf/jboss-as-quickstart/tree/master/ejb-remote) and want to handle a authentication failure.

       

      But I find that authentication failures are also thrown as IllegalStateException.

       

      Is there anyway to get a authentication exception? If need be, I can register a listener/interceptor using the lower level jboss-remoting API also. Would appreciate any pointers.

       

      Thanks.

        • 1. Re: Handling EJB authentication failures
          jaikiran pai Master

          You'll have to use the jboss-remoting API to establish/create a connection yourself. A failing connection creation will throw the exception and you can then handle it. A successful connection can be passed on to the EJBClientContext to register it as a receiver.

          • 2. Re: Handling EJB authentication failures
            jaikiran pai Master

            By the way, those failures aren't really EJB authentication failures. They are connection failures to the server from a remote client. EJB doesn't really play a role at that point.

            • 3. Re: Handling EJB authentication failures
              raylite3 Apprentice

              Thanks, in this case, the connection failures are because of authentication failure (incorrect password). But the exception I get back is still a IllegalStateException (though I see a SaslException logged, I cannot get access to that exception).

               

              Any pointers/test cases that I can take a look at for using the jboss-remoting API to create connection and then use it for the EJBClientContext.

              • 4. Re: Handling EJB authentication failures
                jaikiran pai Master

                Kiran Anantha wrote:

                 

                Thanks, in this case, the connection failures are because of authentication failure (incorrect password). But the exception I get back is still a IllegalStateException (though I see a SaslException logged, I cannot get access to that exception).

                One of the jobs of the EJB client API is to try and auto connect to the configured destination(s). If it can't then it logs the problem and continues since failing of a connection creation shouldn't stop the EJB client API for functioning. Now at a later point during the EJB invocation, if the EJB client API finds that it has no receivers (whatever the reason is), it throws that IllegalStateException because *at that point* the receiver is necessary for it to function.

                 

                 

                Kiran Anantha wrote:

                 

                Any pointers/test cases that I can take a look at for using the jboss-remoting API to create connection and then use it for the EJBClientContext.

                See this testcase for example https://github.com/jbossas/jboss-ejb-client/blob/master/src/test/java/org/jboss/ejb/client/test/client/EJBClientAPIUsageTestCase.java#L85. Once you get the remoting connection on that line, you can just do a EJBClientContext#register(connection).

                1 of 1 people found this helpful
                • 5. Re: Handling EJB authentication failures
                  raylite3 Apprentice

                  OK, I got this working but how do I tear down/close the connections? In my Eclipse environment, I see 2 threads running even after I close the context.

                   

                          final Endpoint endpoint = Remoting.createEndpoint("endpoint", OptionMap.EMPTY);

                          endpoint.addConnectionProvider("remote", new RemoteConnectionProviderFactory(), OptionMap.create(Options.SSL_ENABLED, Boolean.FALSE));

                          URI uri = new URI("remote://localhost:4547");

                          EJBClientContext ejbClientContext = null;

                          Connection connection = null;

                          try {

                                    // open a connection

                          OptionMap connectionOptionMap = OptionMap

                            .create(

                                      Options.SASL_POLICY_NOANONYMOUS, Boolean.FALSE,

                                      Options.SASL_POLICY_NOPLAINTEXT, Boolean.FALSE);

                           final IoFuture<Connection> futureConnection = endpoint.connect(uri, connectionOptionMap, new SampleClientCallbackHandler());

                                    connection = IoFutureHelper.get(futureConnection, 5, TimeUnit.SECONDS);

                                    ejbClientContext = EJBClientContext.create();

                                    ejbClientContext.registerConnection(connection);

                         

                                    String appName = "";

                          String moduleName = "testtx";

                          String beanName = RemoteSample.class.getName();

                          String distinctName = "";

                          final StatelessEJBLocator<RemoteSample> statelessEJBLocator = new StatelessEJBLocator<RemoteSample>(RemoteSample.class, appName, moduleName, beanName, distinctName);

                          final RemoteSample proxy = EJBClient.createProxy(statelessEJBLocator);

                          proxy.method1();//invocation

                          } catch (RuntimeException ex) {

                                    // check if RuntimeException wraps a SaslException

                                    System.err.println("Could not connect to " + uri);

                          } finally {

                                    ejbClientContext.close();

                                    connection.close();

                          }

                  • 6. Re: Handling EJB authentication failures
                    jaikiran pai Master

                    You have to close the endpoint too.