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/or…
the getLocalUser() method is deprecated in lieu of getUserReference() but I'd really
rather deal with a String if at all possible.