I made a quartz schedule. The mehtod getUser returns null. Why?And how to get user for searchService?
public class MyJob implements Job { @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { JiraAuthenticationContext authenticationContext = ComponentAccessor.getJiraAuthenticationContext(); final User user = authenticationContext.getUser().getDirectoryUser(); }
You can set the user like this:
UserUtil userUtil = (UserUtil) ComponentAccessor.getComponentOfType(UserUtil.class); ApplicationUser user = userUtil.getUserByName("some-user"); JiraAuthenticationContext jac = (JiraAuthenticationContext) ComponentAccessor.getComponentOfType (JiraAuthenticationContext.class); jac.setLoggedInUser(user);
While Shravan provides a workaround, an answer to the problem at hand is not given yet. As I bumped into this myself, I investigated and quickly came to the real reason: an authentication context is only available for code directly in the execution path of a web request, be it via the web portal or via REST interface.
If you want to run code asynchronously, then you are not tied to a particular user session so you don't get a user object from the authentication context. If user information is needed to handle your async code, either choose a fixed user, or pass the user info from the web-request to the async code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.