@Override
    public UserIdentity getServiceUserIdentity() {

        // Ideally the token will get recreated by the refresh queue just before
        // it expires so callers to this will find a token that is good to use and
        // thus won't be contended.
        final boolean didCreate;
        if (serviceUserIdentity == null) {
            synchronized (this) {
                if (serviceUserIdentity == null) {
                    serviceUserIdentity = createServiceUserIdentity();
                    didCreate = true;
                } else {
                    didCreate = false;
                }
            }
        } else {
            didCreate = false;
        }

        // Make sure it is up-to-date before giving it out
        if (!didCreate && serviceUserIdentity instanceof final HasRefreshable hasRefreshable) {
            NullSafe.consume(hasRefreshable.getRefreshable(), refreshable ->
                    refreshable.refreshIfRequired(RefreshMode.JUST_IN_TIME, refreshManager::addOrUpdate));
        }

        return serviceUserIdentity;
    }
Extracts the authenticated user's identity from http request when that
request is part of a UI based authentication flow with the IDP
stroom-security/stroom-security-common-impl/src/main/java/stroom/security/common/impl/AbstractUserIdentityFactory.java