java.lang.Object
org.jboss.as.test.shared.integration.ejb.security.Util

public class Util extends Object
Holder for couple of utility methods used while testing EJB3 security.
Author:
Darran Lofthouse
  • Constructor Details

    • Util

      public Util()
  • Method Details

    • createRemoteEjbJndiContext

      public static String createRemoteEjbJndiContext(String appName, String moduleName, String distinctName, String beanName, String viewClassName, boolean isStateful)
      Creates JNDI context string based on given parameters. See details at https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI
      Parameters:
      appName - - typically the ear name without the .ear - could be empty string when deploying just jar with EJBs
      moduleName - - jar file name without trailing .jar
      distinctName - - AS7 allows each deployment to have an (optional) distinct name - could be empty string when not specified
      beanName - - The EJB name which by default is the simple class name of the bean implementation class
      viewClassName - - the remote view is fully qualified class name of @Remote EJB interface
      isStateful - - if the bean is stateful set to true
      Returns:
      - JNDI context string to use in your client JNDI lookup
    • createNamingContext

      public static Context createNamingContext() throws NamingException
      Helper to create InitialContext with necessary properties.
      Returns:
      new InitialContext.
      Throws:
      NamingException
    • switchIdentity

      public static <T> T switchIdentity(String username, String password, Callable<T> callable) throws Exception
      Switch the user's identity using Elytron.
      Type Parameters:
      T - the result type of the callable task
      Parameters:
      username - the new username
      password - the new password
      callable - the callable task to execute under the new identity
      Returns:
      the result of the callable task
      Throws:
      Exception - if an error occurs while switching the user's identity or if an error occurs while executing the callable task
    • switchIdentity

      public static <T> T switchIdentity(String username, String password, Callable<T> callable, ClassLoader classLoader) throws Exception
      Switch the user's identity using Elytron.
      Type Parameters:
      T - the result type of the callable task
      Parameters:
      username - the new username
      password - the new password
      callable - the callable task to execute under the new identity
      classLoader - the class loader to use when checking for a security domain association
      Returns:
      the result of the callable task
      Throws:
      Exception - if an error occurs while switching the user's identity or if an error occurs while executing the callable task
    • switchIdentity

      public static <T> T switchIdentity(String username, String password, Callable<T> callable, boolean validateException) throws Exception
      Switch the user's identity using Elytron.
      Type Parameters:
      T - the result type of the callable task
      Parameters:
      username - the new username
      password - the new password
      callable - the callable task to execute under the new identity
      validateException - whether or not to validate an exception thrown by the callable task
      useClientLoginModule - true if ClientLoginModule should be used for legacy security, false if SecurityClientFactory should be used for legacy security instead
      Returns:
      the result of the callable task
      Throws:
      Exception - if an error occurs while switching the user's identity or if an error occurs while executing the callable task
    • switchIdentity

      public static <T> T switchIdentity(String username, String password, Callable<T> callable, boolean validateException, ClassLoader classLoader) throws Exception
      Switch the user's identity using Elytron.
      Type Parameters:
      T - the result type of the callable task
      Parameters:
      username - the new username
      password - the new password
      callable - the callable task to execute under the new identity
      validateException - whether or not to validate an exception thrown by the callable task false if SecurityClientFactory should be used for legacy security instead
      classLoader - the class loader to use when checking for a security domain association
      Returns:
      the result of the callable task
      Throws:
      Exception - if an error occurs while switching the user's identity or if an error occurs while executing the callable task
    • switchIdentitySCF

      public static <T> T switchIdentitySCF(String username, String password, Callable<T> callable) throws Exception
      Switch the user's identity using Elytron.
      Type Parameters:
      T - the result type of the callable task
      Parameters:
      username - the new username
      password - the new password
      callable - the callable task to execute under the new identity
      Returns:
      the result of the callable task
      Throws:
      Exception - if an error occurs while switching the user's identity or if an error occurs while executing the callable task