Forums

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

Is it possible to access the request URL from a ScriptRunner "web panel" fragment?

Kamran Ansari May 10, 2022

Problem I'm trying to solve:

I would like to programmatically display a banner message if our Jira instance was being accessed via a URL other than the base URL configured for the application (preferred URL). For instance, if someone was accessing Jira through a special DNS alias reserved for our Jira system administration team.

I have tried a couple of approaches but haven't found any success so far:

1. Comparison of Request URL to base URL in Condition section of the fragment configuration:

import com.atlassian.jira.plugin.webfragment.model.JiraHelper

def success = 1 // Be an optimist

def jirahelper = new JiraHelper();
def req = jirahelper.getRequest()
if (req == null)
{
log.warn("Request object was null - can't proceed.")
success = 0

// This is where the problem is - the request object always
  // comes badk null. Audit log contains a bunch of messages
// that indicate the condition check failed for the fragment.
// ("Script fragment condition has failed for username XYZ")
}
else
{
def url = req.getRequestURL().toString();
success = (url != null)

if (success)
{
// Compare the url with the base URL here and set success accordingly
}
}

return success

 

2. Almost identical code as above in the "Provider class/script" section, with the "Condition" section empty. I got identical results.

Question: Is it even possible to access the Request URL in a "web panel" fragment, and if so, how to go about it?

For sake of completeness, the code needs to run regardless of the context of an issue or project, or whether the user is logged on or not.

 

Many thanks,

Kamran

0 answers

Suggest an answer

Log in or Sign up to answer