Hi community,
I've developed a custom rest plugin with routines to automate some of my team tasks.
I am using scripts in post-functions to run the rest API's:
(...)
def issueRest = remote.request(Method.POST,ContentType.JSON) { req ->
uri.path = ("/rest/myrest/latest/mymethod")
headers.'Authorization' = "Basic ${"defaultusers:pass".bytes.encodeBase64().toString()}"
body = [
"skuList" : arrayOfSkus,
"customFieldModelsList" : [
[ "name" : "Customfield 01", "value" : "Value 01" ],
[ "name" : "Customfield 02", "value" : "Value 02" ]
]
]
response.success = { resp6,json ->
log.warn "Success! ${resp6.status}"
}
response.failure = { resp6,json ->
log.warn "Request failed with status ${resp6.status}"
}
}
(...)
The code is working perfectly. But, the changes will always be made with the default user.
I need to change the "defaultuser" to the current user. But, the ApplicationUser (com.atlassian.jira.component.ComponentAccessor.getJiraAuthenticationContext().getUser()) doesn't have the password value or any value related to the session.
How can I do it?
Best Regards.
You can't get the password for another user. It would completely nullify all security if you could look up another user's password.
The only way to do this is to make a REST call that can accept the username and then internally has the permission to act on behalf of that user. Several JIRA REST calls do this depending on what you are trying to accomplish.
Your alternative is to perform the update directly in the code. Jira allows you to pass in the user as part of the update call. In that case, the update is recorded as the user that you pass in. You can't do this through REST.
Hi @Derek Fields _RightStar_ ,
Thank you for replying.
I've added the user as parameter in the request body:
(...)
body = [
"skuList" : arrayOfSkus,
"customFieldModelsList" : [
[ "name" : "Customfield 01", "value" : "Value 01" ],
[ "name" : "Customfield 02", "value" : "Value 02" ]
],
"user" : username
]
(...)
The code executes the method with the received user. This approach solved my problem.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.