Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

jiraAuthenticationContext.getLoggedInUser() return null

Manh Tuan Do May 12, 2019

Here is my code:

 private static final Logger log = LoggerFactory.getLogger(ImportTestCaseServlet.class);

@Autowired
TestCaseService testCaseService;
@Autowired
DeviceService deviceService;
@Autowired
UploadFileService uploadFileService;
@Autowired
ProjectService projectService;
@Autowired
private TesterPerformanceService testerPerformanceService;
@Autowired
JiraAuthenticationContext jiraAuthenticationContext;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
final String deviceType = req.getParameter(DEVICE_TYPE);
final String importType = req.getParameter(IMPORT_DEVICE_TYPE);
resp.setContentType(CONTENT_TYPE);
resp.setCharacterEncoding(CHARACTER_ENCODING);
final Map<String, String> errors = new HashMap<>();
final Map<String, Object> data = new HashMap<>();

ApplicationUser user = jiraAuthenticationContext.getLoggedInUser();

long projectId = Long.parseLong(req.getParameter(PARAMETER_PROJECT_ID));
String role = testerPerformanceService.getRole(user, projectId);

final ProjectManager projectManager = ComponentAccessor.getProjectManager();
final Project project = projectManager.getProjectObj(Long.parseLong(req.getParameter(PARAMETER_PROJECT_ID)));
if (Objects.equals(role, PROJECT_ROLE_QC_LEAD) && Objects.equals(importType, IMPORT_TYPE_IMPORT_DEVICE)) {
errors.put(MESSAGE_ERROR_TEST_CASE_TYPE, DEVICE_PERMISSION);
}
if (StringUtils.equalsIgnoreCase(importType, IMPORT_TYPE_UPDATE_ASSIGNEE) && StringUtils.isBlank(deviceType)) {
errors.put(MESSAGE_ERROR_TEST_CASE_TYPE, TEST_CASE_TYPE_REQUIRED);
}
if (errors.size() > 0) {
resp.getWriter().write(new Gson().toJson(errors));
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
} else {
final ResultMessage resultMessage = deviceService.imports(req, resp);
if (resultMessage.getCode() == HttpServletResponse.SC_OK) {
data.put(Constants.LIST_FILE_UP_LOAD, uploadFileService.findAllByProjectId(project.getId(), null));
data.put(Constants.TOTAL_ROWS_IMPORT_SUCCESS, resultMessage.getTotalRowSuccess());
data.put(Constants.TOTAL_ROWS_IMPORT_ERROR, resultMessage.getTotalRowError());
data.put(Constants.TOTAL_ROWS, resultMessage.getTotalRows());
resp.getWriter().write(new Gson().toJson(data));
resp.setStatus(HttpServletResponse.SC_OK);
} else {
errors.put(MESSAGE_ERROR_SERVICE, resultMessage.getMessage());
resp.getWriter().write(new Gson().toJson(errors));
resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
}

Please explain ,why return jiraAuthenticationContext.getLoggedInUser() null. 

2 answers

0 votes
Nhac Tat Nguyen
Contributor
November 18, 2020

It could be the person who makes the request did not log in.

0 votes
Prakash Kumar
Contributor
May 12, 2019

hi @Manh Tuan Do ,

 

Try this ,

ApplicationUser user=ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

 

Let me know if it works for you or not.

Manh Tuan Do May 12, 2019

I try it but  not working

Prakash Kumar
Contributor
May 12, 2019

Hi @Manh Tuan Do ,

 

I guess above method is now deprecated. so can you please try this,

ApplicationUser user=ComponentAccessor.getJiraAuthenticationContext().getUser();

Manh Tuan Do May 12, 2019

I use version 7.7.1, on my version getLoggedInUser () is supported, getUser has not been used anymore. although I tried both getUser () but it didn't work.

Thanks you!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events