Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,369,750
Community Members
 
Community Events
168
Community Groups

Scriptrunner: Show a web panel only for not logged in users

I want to show a web panel with Scriptrunner only to not logged in users and can't find the right condition for this. What I've tried:

if (url.contains('login'))

— works, but is too simple: it doesn't match login forms on the primary dashboard page.

import com.atlassian.jira.component.ComponentAccessor
[…]if (currentUser.key == null)

— doesn't work, never seems to be null. Any ideas?

 

Thanks in avance,

Andreas

 

2 answers

1 accepted

1 vote
Answer accepted

This should do the job:

import com.atlassian.jira.component.ComponentAccessor

if (!ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser())
{ return true }

This does the trick. Thank you very much!

Like Leonard Chew likes this

Thanks a lot! this works also for "script fragments" - useful for writing a message about login that only not-yet-logged-in users should see.

Hi @Andreas Kroschel 

 

Do you have sample screenshot for this result?

 

Thanks

 

I had to blur company information. Basically our banner says, when inside our network, please use SSO auto login, instead of typing again the credentials:

 

Condition

 

import com.atlassian.jira.component.ComponentAccessor

if (!ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser())
{ return true }

 

Code:

 

writer.write("<div style='background-color: white; border: 1px solid #C1C7D0; 4px; padding: 2px; font-weight: normal; text-align: center;'>&#x2139;&#xFE0F; Passwortloser Login: Bitte verwenden Sie <span style='background-color: rgba(9, 30, 66, 0.08); border-radius: 3.01px'>Auto-Login</span>, ohne Benutzernamen und Passwort anzugeben (nur innerhalb des ••••••••••••••).</div>")

 

Suggest an answer

Log in or Sign up to answer