Created
March 15, 2012 13:43
-
-
Save vmassol/2044262 to your computer and use it in GitHub Desktop.
Execute As User
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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