Get the current user inside jira workflow validator

680 Views Asked by At

I want to create a workflow validator which will not allow the reporter of the issue to execute certain steps from the workflow. For that purpose somehow I have to get the User object or the user id of the user executing the action. How can I do that?

2

There are 2 best solutions below

2
On BEST ANSWER

inject the JiraAuthenticationContext And then call jiraAuthenticationContext.getLoggedInUser();

you can find the documentation about the JiraAuthenticationContext here: https://docs.atlassian.com/jira/5.0.1/com/atlassian/jira/security/JiraAuthenticationContext.html

6
On

Here is how I've managed to do it:

private String getCurrentIssueProcessorId(Map<?, ?> transientVars, Map<?, ?> args){
        String processorId = (String) args.get(ARG_USER_NAME);
        if(null == processorId || processorId.isEmpty()){
            WorkflowContext workflowContext = (WorkflowContext) transientVars.get(ARG_CONTEXT);
            processorId = workflowContext.getCaller();
        }

        if(logger.isDebugEnabled()){
            logger.debug("Issue processor: " + processorId);
        }

        return processorId;
}

where ARG_CONTEXT is the string context and ARG_USER_NAME is the string username