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

Andreas Kroschel December 17, 2019

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
Leonard Chew
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 17, 2019

This should do the job:

import com.atlassian.jira.component.ComponentAccessor

if (!ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser())
{ return true }
Andreas Kroschel December 17, 2019

This does the trick. Thank you very much!

Like Leonard Chew likes this
mfabris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 10, 2021

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.

Rodolfo So June 16, 2022

Hi @Andreas Kroschel 

 

Do you have sample screenshot for this result?

 

Thanks

Andreas Kroschel June 21, 2022

autologin.png

0 votes
Andreas Kroschel June 21, 2022

 

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