com.ibm.as400.security.auth

Class Swapper



  • public class Swapper
    extends Object
    Provides utility methods to perform credential swaps for existing remote connections. The methods in this class allow you to do work under a different user, providing you've obtained a ProfileTokenCredential probably from AS400.getProfileToken().

    Comparison with the swap() methods of ProfileTokenCredential:

    The swap() methods of this class have as one of their arguments either an AS400 object or a Connection object. The contract of these methods is to swap the profile in use for a specified connection. Here is the usage pattern:

     AS400 conn1 = new AS400(sysName, userID, password);
     ProfileTokenCredential myCred = new ProfileTokenCredential(....);
     Swapper.swap(conn1, myCred);
     // conn1 is now running under the new (swapped-to) profile
     

    In constrast, the contract of the swap() methods of class ProfileTokenCredential is to swap the profile in use for the current thread of execution. They don't swap the profile in use for a specific AS400 object, but rather for any subsequently-created AS400 objects. Here is the usage pattern:

     AS400 conn1 = new AS400();
     ProfileTokenCredential myCred = new ProfileTokenCredential(....);
     myCred.swap();
     AS400 conn2 = new AS400();  // conn2 is running under the swapped-to profile.
     // conn1 is still running under the original profile.
     

    The Swapper.swap() methods are useful for swapping credentials for existing remote connections. The ProfileTokenCredential.swap() methods are useful for swapping the current thread of execution when running natively in an IBM i JVM.

    This class is mostly based on a prototype contributed by Steve Johnson-Evers.