docs: @Override
      public IUserInstance getUserInstance(HttpServletRequest request) throws PortalException {
          try {
              request = this.portalRequestUtils.getOriginalPortalRequest(request);
          } catch (IllegalArgumentException iae) {
              // ignore, just means that this isn't a wrapped request
          }
  
          // Use request attributes first for the fastest possible retrieval
          IUserInstance userInstance = (IUserInstance) request.getAttribute(KEY);
          if (userInstance != null) {
              return userInstance;
          }
  
          final IPerson person;
          try {
              // Retrieve the person object that is associated with the request
              person = this.personManager.getPerson(request);
          } catch (Exception e) {
              logger.error("Exception while retrieving IPerson!", e);
              throw new PortalSecurityException("Could not retrieve IPerson", e);
          }
  
          if (person == null) {
              throw new PortalSecurityException(
                      "PersonManager returned null person for this request.  With no user, there's no UserInstance.  Is PersonManager misconfigured?  RDBMS access misconfigured?");
          }
  
          final HttpSession session = request.getSession();
          if (session == null) {
              throw new IllegalStateException(
                      "HttpServletRequest.getSession() returned a null session for request: "
                              + request);
          }
  
          // Return the UserInstance object if it's in the session
          UserInstanceHolder userInstanceHolder = getUserInstanceHolder(session);
          if (userInstanceHolder != null) {
              userInstance = userInstanceHolder.getUserInstance();
  
              if (userInstance != null) {
                  return userInstance;
              }
          }
  
          // Create either a UserInstance or a GuestUserInstance
          final LocaleManager localeManager = this.getLocaleManager(request, person);
          final String userAgent = this.getUserAgent(request);
          final IUserProfile userProfile =
                  this.getUserProfile(request, person, localeManager, userAgent);
  
          // Create the user layout manager and user instance object
          IUserLayoutManager userLayoutManager =
                  userLayoutManagerFactory.getUserLayoutManager(person, userProfile);
  
          final UserPreferencesManager userPreferencesManager =
                  new UserPreferencesManager(person, userProfile, userLayoutManager);
          userInstance = new UserInstance(person, userPreferencesManager, localeManager);
  
          // Ensure the newly created UserInstance is cached in the session
          if (userInstanceHolder == null) {
              userInstanceHolder = new UserInstanceHolder();
          }
          userInstanceHolder.setUserInstance(userInstance);
          session.setAttribute(KEY, userInstanceHolder);
          request.setAttribute(KEY, userInstance);
  
          // Return the new UserInstance
          return userInstance;
      }