Preemptive authentication means that a client adds authentication credentials to all requests, no matter if the server asks for them or not.

Typically, a server returns a "401 Unauthorized" response to unauthorized requests. For some use cases, this isn’t what you want. Preemptive authentication is a common approach to reduce the load on network and the server itself, for example.

By adding a default request property to the TLcdInputStreamFactory, you can set up preemptive authentication. The Authorization header will then be added to each request made.

TLcdInputStreamFactory inputStreamFactory = new TLcdInputStreamFactory();
String credentials = "username" + ":" + "password";
String encodedAuth = Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.UTF_8));
inputStreamFactory.setDefaultRequestProperty("Authorization", "Basic " + encodedAuth);

LuciadFusion is an example of a server that can require preemptive authentication. If LuciadFusion is configured to allow anonymous access to services, the client needs to use preemptive authentication for non-anonymous access. If the client doesn’t provide authentication credentials when a user tries to access such a service, LuciadFusion never returns a "401 Unauthorized" response. Instead, it treats the client as an anonymous one.