Brainstorming: how to identify a special user after a proxy using basic auth

We have build a proxy that uses one special user (let’s call him XWiki.ProxyReadonly) with oidc.skipped=true&basicauth=1 that is allowed to only read the wiki. That is to provide the wiki on places where no internet is available.

We want to use some special styling mostly to hide some buttons.

My first approach was to use SSX that is used only for XWiki.ProxyReadonly. But it’s not working this way.

#set($currentUserReference = $services.user.getCurrentUserReference())
#set($currentUser = $xwiki.getDocument($currentUserReference))
$currentUser

Code above does not output XWiki.ProxyReadonly as it would in the original wiki but it’s outputting nothing.

A second approach serving css depending on the url won’t work either.

$doc.getExternalURL()

This will output either wiki-prod or wiki-test but not wiki-readonly-proxy.

Currently we are using this:

/*
 - $currentUser returns NOTHING - the user can't be identified after the proxy
 - not the best check, but it works for now
 - the URL is not wiki-readonly-proxy but unfortunately wiki-prod or wiki-test
 - therefore, a check on the URL is unfortunately not possible
*/
#set($currentUserReference = $services.user.getCurrentUserReference())
#set($currentUser = $xwiki.getDocument($currentUserReference))
#if(!$currentUser)
  /* remove notification bell */
  #tmNotifications {
      display: none;
  }
  /* remove user avatar */
  #xwikimainmenu li.navbar-avatar {
      display: none;
  }
  /* remove like button */
  #contentcolumn .like-container {
      display: none;
  }
  /* remove watch-button - was in notification bell before */
  #watchButton {
      display: none;
  }
  /* now add a padding */
  form#globalsearch {
      padding-right: 15px;
  }
#end

It works but I don’t find it satisfactory. And I’m not sure if it’s future proof. Perhaps there are still pitfalls lurking somewhere that we cannot see at present.

Any idea for a better solution?

Regards, Simpel

Hi @Simpel,

What about creating a UIX page that checks whether the current user is the proxy user, and then using an SSX object to apply the appropriate styling instead of parsing velocity content in SSX?

Also, why isn’t #if ($xcontext.user == ‘XWiki.ProxyReadonly‘) code here #end working?

That works perfect.

So what is the difference between

#set($currentUserReference = $services.user.getCurrentUserReference())
#set($currentUser = $xwiki.getDocument($currentUserReference))

and

$xcontext.user?

I think the question is why #if(!$currentUser) isn’t working as expected?
$xcontext.user returns java.lang.String XWiki.UserName
$xwiki.getDocument($currentUserReference) returns com.xpn.xwiki.api.Document XWiki.UserName.
So what were you trying to compare the document against?

I want to know, who (which account) is using the wiki. Best I get a string to compare with.