Skip to content

Instantly share code, notes, and snippets.

@vmassol
Created March 15, 2012 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmassol/2044262 to your computer and use it in GitHub Desktop.
Save vmassol/2044262 to your computer and use it in GitHub Desktop.
Execute As User
@Override
public void executeAsUser(DocumentReference executingUserReference, DocumentReference securityDocumentReference,
Runnable runnable) throws IRCBotException
{
XWikiContext xwikiContext = getXWikiContext();
DocumentReference currentUserReference = xwikiContext.getUserReference();
XWikiDocument currentDocument = xwikiContext.getDoc();
try {
// Set executing user in the XWiki Context
xwikiContext.setUserReference(executingUserReference);
// Set the security document which is used to test permissions
xwikiContext.setDoc(new XWikiDocument(securityDocumentReference));
runnable.run();
} finally {
xwikiContext.setUserReference(currentUserReference);
xwikiContext.setDoc(currentDocument);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment