AuthInfo.setThreadDefault(...) and Single-Instance COM Objects |
|
This article applies to Java applications accessing COM components.
As discussed in our documentation page on Security and Authentication, you can use setThreadDefault(...) if you want authentication to be done on a per-thread basis. This mechanism works only if the COM component you are accessing is multi-instance. A COM application is multi-instance if a user can instantiate more than one instance of the application at a given time in a given desktop. Examples of multi-instance COM applications are Microsoft Word and Excel.
AuthInfo.setThreadDefault(...) will have a different behavior if the COM component it is authenticating to is single-instance. A single-instance COM application is one where a user can invoke only one instance of it. If the user attempts to invoke another instance, the same existing instance is returned to the user. If you have several threads running in a single Java process and you want to use setThreadDefault(...) to authenticate to a single-instance COM component, only the first thread needs to call setThreadDefault(...). All the remaining threads will re-use the authentication of the first one. If you try calling setThreadDefault(...) on the second thread, passing it the wrong authentication credentials (like a wrong username or password), the second thread will still be allowed access to the COM component. This is because the entire Java process has already been authenticated to that single instance of the COM component. Further calls to setThreadDefault(...) have no effect.
Note: If your COM component is a dll and you use setdllhost to surrogate that dll, the COM component effectively becomes a single-instance COM object.