1 Reply Latest reply on Aug 7, 2009 11:09 AM by Shervin Asgari

    Custom authentication fails with testng

    Shervin Asgari Master


      I have a custom authentication from my app which doesnt use identitystore. I used to in my testng test case have:

      // disables security, since this is a FacesRequest pages.xml kicks in
      // the IdentityManager has an interface for creating user, later we might
      // want to use our own service layer instead
      IdentityManager m = IdentityManager.instance();
      m.createUser("admin", "admin");
      m.grantRole("admin", "admin");
      // enables it again

      However, since I use authenticator:
      <security:identity authenticate-method="#{authenticator.authenticate}"/>

      I cannot use the identitymanager to login anymore. I also cannot use the login.xhtml because it is too complicated. (I send email with onetime password etc).

      If I try to manually login in my test:

      //Add the username as role

      I get the following exception:

      [testng] WARN  [org.jboss.seam.security.jaas.SeamLoginModule] Error invoking login method
      [testng] javax.el.ELException: java.lang.NullPointerException

      And I can see that it tries to run the authenticator method. Now my question is

      1. Can I somehow tell testng to not run authenticator for tests only, so that the above code would just login the test user?

      2. If that is not possible, how can I get the identitymanager to work programatically from the tests, even though I am havent enabled it in components.xml?

      3. How has anybody else with a custom login method done this? Can I see some examples?