My controller looks like this
@Controller
@IgnoreJwt
public class MainController {
private final StorageService storageService;
@Autowired
public MainController(StorageService storageService) {
this.storageService = storageService;
}
.
.
.
@RequestMapping(value = "/clipboard", method = RequestMethod.GET)
public ModelAndView render(@AuthenticationPrincipal AtlassianHostUser hostUser) {
// in this case, hostUser is not NULL
ModelAndView modelAndView = new ModelAndView("clipboardDialog");
return modelAndView;
}
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String handleFileUpload(@AuthenticationPrincipal AtlassianHostUser hostUser,
@RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes) {
// In this case, hostUser is null. The only difference in both the method is
// the previous method is of type GET and this one is of POST
hostUser.getUserKey(); // Causing NPE because hostUser is null
My descriptor is shown below
{
"key": "copy-paste-plugin",
"baseUrl": "${addon.base-url}",
"name": "Copy Paste (Spring Boot)",
"authentication": {
"type": "jwt"
},
"lifecycle": {
"installed": "/installed",
"uninstalled": "/uninstalled"
},
"scopes": [
"READ",
"WRITE"
"ACT_AS_USER"
],
"modules": {
"dialogs": [
{
"url": "/clipboard",
"options": {
"size": "large",
"chrome": true,
"header": {
"value": "${copypaste.clipboard-dialog-name}"
}
},
"key": "dialog-module-key",
"conditions": [
{
"condition": "user_is_logged_in"
}
]
}
],
"keyboardShortcuts": [
{
"shortcut": "v",
"target": {
"type": "dialogmodule",
"key": "dialog-module-key"
},
"context": "GLOBAL",
"name": {
"value": "Attach File Keyboard Shortcut"
},
"key": "keyboard-shortcut-key-v"
}
],
"generalPages": [
{
"url": "/upload",
"key": "upload",
"location": "none",
"name": {
"value": "Attach a file"
},
"conditions": [
{
"condition": "user_is_logged_in"
}
]
}
]
}
}
Upload form: clipboardDialog.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout">
<head th:insert="~{layout :: CommonBaseLayout}">
<title>Copy Paste Plugin</title>
</head>
<body>
<div style="height:100%;">
<div id="target" contenteditable="true" style="height:400px;width:inherit;display:block;border: solid 1px #000;margin:10px 0;"></div>
</div>
<form class="aui" method="post" id="file-input-form" enctype="multipart/form-data" action="/upload">
<fieldset>
<legend><span>File upload</span></legend>
<div class="field-group">
<label for="file-upload-example">Upload
file</label>
<input class="upfile" type="file" id="file-upload-example" name="file"/>
</div>
</fieldset>
<div class="buttons-container">
<div class="buttons">
<input class="button submit" type="submit" value="Save" id="comment-save-button"/>
<a class="cancel" href="#">Cancel</a>
</div>
</div>
</form>
<script type="text/javascript" src="/js/DateUtil.js"></script>
<script type="text/javascript" src="/js/main.js"></script>
</body>
</html>
In the above dialog there are two buttons #1 is input type submit button and #2 is dialog’s submit button. I am currently using #1 input type submit button to submit the form request. Because this plugin is work in progress so the dialog’s submit button is unused.
What am I missing in above code which is causing AtlassianHostUser as null?