It seems that ProfileTokenCredential.swap() doesn't work even when running natively (on IBM i). According to the documentation:
Note: swap() is supported only when running natively on IBM i. It is unsupported as a remote operation.
However I get the following exception:
com.ibm.as400.security.auth.SwapFailedException: Request is not supported.
at com.ibm.as400.security.auth.AS400CredentialImplRemote.swap(AS400CredentialImplRemote.java:193)
at com.ibm.as400.security.auth.AS400Credential.swap(AS400Credential.java:1193)
at AS400SwapProfileTest.main(AS400SwapProfileTest.java:28)
It is strange that in the call stack there is AS400CredentialImplRemote class. In jt400.jar I cannot find native implementation of the AS400Credential. Not even in jt400Native.jar.
AS400Credential.implClassNameNative() returns allways null:
String implClassNameNative()
{
return null;
}
Where can I find the jar file with the native implementation so that the swap() works?
You need to use the jt400Native.jar file that is shipped on the system. It is available in the following locations.
/qibm/proddata/os400/jt400/lib/java6/jt400Native.jar
/qibm/proddata/os400/jt400/lib/java8/jt400Native.jar
/qibm/proddata/os400/jt400/lib/java9/jt400Native.jar
/qibm/proddata/os400/jt400/lib/jt400Native.jar
When using the swap support, you need to make sure your application is single-threaded, as the swap function applies to the entire job (not just the current thread).