@@ -694,22 +694,30 @@ public JiraSession getSession() {
694694 */
695695 @ Nullable
696696 public JiraSession getSession (Item item ) {
697+ return getSession (item , false );
698+ }
699+
700+ JiraSession getSession (Item item , boolean uiValidation ) {
697701 if (jiraSession == null ) {
698- jiraSession = createSession (item );
702+ jiraSession = createSession (item , uiValidation );
699703 }
700704 return jiraSession ;
701705 }
702706
707+ JiraSession createSession (Item item ) {
708+ return createSession (item , false );
709+ }
710+
703711 /**
704712 * Creates a remote access session to this Jira.
705713 *
706714 * @return null if remote access is not supported.
707715 */
708- JiraSession createSession (Item item ) {
716+ JiraSession createSession (Item item , boolean uiValidation ) {
709717 ItemGroup itemGroup = map (item );
710718 item = itemGroup instanceof Folder ? ((Folder ) itemGroup ) : item ;
711719
712- StandardUsernamePasswordCredentials credentials = resolveCredentials (item );
720+ StandardUsernamePasswordCredentials credentials = resolveCredentials (item , uiValidation );
713721
714722 if (credentials == null ) {
715723 LOGGER .fine ("no Jira credentials available for " + item );
@@ -735,8 +743,10 @@ Lock getProjectUpdateLock() {
735743 /**
736744 * This method only supports credential matching by credentialsId.
737745 * Older methods are not and will not be supported as the credentials should have been migrated already.
746+ * @param item can be <code>null</code> if top level
747+ * @param uiValidation if <code>true</code> and credentials not found at item level will not go up
738748 */
739- private StandardUsernamePasswordCredentials resolveCredentials (Item item ) {
749+ private StandardUsernamePasswordCredentials resolveCredentials (Item item , boolean uiValidation ) {
740750 if (credentialsId == null ) {
741751 LOGGER .fine ("credentialsId is null" );
742752 return null ; // remote access not supported
@@ -746,12 +756,17 @@ private StandardUsernamePasswordCredentials resolveCredentials(Item item) {
746756 .build ();
747757
748758 if (item != null ) {
749- StandardUsernamePasswordCredentials creds = CredentialsMatchers .firstOrNull (
759+ StandardUsernamePasswordCredentials credentials = CredentialsMatchers .firstOrNull (
750760 CredentialsProvider .lookupCredentials (
751761 StandardUsernamePasswordCredentials .class , item , ACL .SYSTEM , req ),
752762 CredentialsMatchers .withId (credentialsId ));
753- if (creds != null ) {
754- return creds ;
763+ if (credentials != null ) {
764+ return credentials ;
765+ }
766+ // during UI validation of the configuration we definitely don't want to expose
767+ // global credentials
768+ if (uiValidation ) {
769+ return null ;
755770 }
756771 }
757772 return CredentialsMatchers .firstOrNull (
@@ -1371,9 +1386,11 @@ public FormValidation doValidate(
13711386 site .setReadTimeout (readTimeout );
13721387 site .setThreadExecutorNumber (threadExecutorNumber );
13731388 site .setUseBearerAuth (useBearerAuth );
1374- JiraSession session = null ;
13751389 try {
1376- session = site .getSession (item );
1390+ JiraSession session = site .getSession (item , true );
1391+ if (session == null ) {
1392+ return FormValidation .error ("Cannot validate configuration" );
1393+ }
13771394 session .getMyPermissions ();
13781395 return FormValidation .ok ("Success" );
13791396 } catch (RestClientException e ) {
0 commit comments