我想创建一个工作流验证器,它不允许问题的报告者执行工作流中的某些步骤。为此,我必须以某种方式获取执行操作的用户的User对象或用户id。我该怎么做?
注入JiraAuthenticationContext
,然后调用jiraAuthenticationContext.getLoggedInUser();
您可以在此处找到有关JiraAuthenticationContext的文档:https://docs.atlassian.com/jira/5.0.1/com/atlassian/jira/security/JiraAuthenticationContext.html
以下是我如何做到的:
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;
}
其中ARG_CONTEXT
是字符串context
,ARG_USER_NAME
是字符串username