Svetlin Zarev
Svetlin Zarev

Reputation: 15723

Get the current user inside jira workflow validator

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?

Upvotes: 3

Views: 751

Answers (2)

Lama
Lama

Reputation: 2972

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

Upvotes: 1

Svetlin Zarev
Svetlin Zarev

Reputation: 15723

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

Upvotes: 0

Related Questions