Looks like you did not read http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents#HTheXWik... fully and are mixing ExecutionContext and XWikiContext, ExecutionContext does not have any typed methods, it's just a map basically and most of the time you don't really use it directly but use an API that manipulate the context. For what you need the simplest in a component is usually to use org.xwiki.bridge.DocumentAccessBridge component (from xwiki-platform-bridge module) until a proper user manager api is introduced. On Thu, Nov 27, 2014 at 7:19 AM, Bryn Jeffries <[email protected]> wrote:
What's the right way to get the current user from the execution context within a Java component?
Taking the example from the guide (http://platform.xwiki.org/xwiki/bin/view/DevGuide/WritingComponents) I thought it would be something like the following, which won't compile for me due to the getLocalUser symbol not being found.
import org.xwiki.context.Execution; import org.xwiki.context.ExecutionContext; ... @Inject private Execution execution;
@Override public String sayHello() { ExecutionContext context = execution.getContext();
String user = context.getLocalUser(); return "Hello " + user;
}
I note that in http://nexus.xwiki.org/nexus/service/local/repositories/releases/archive/org... the getLocalUser() method is deprecated in lieu of getUserReference() but I'd really rather deal with a String if at all possible. _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne