private static boolean canDiscoverItem ( @ Nonnull final String fullName ) { final Jenkins jenkins = Jenkins . getInstance ( ) ; // Fast check to avoid security context switches Item item = null ; try { item = jenkins . getItemByFullName ( fullName ) ; } catch ( AccessDeniedException ex ) { // ignore, we will fall-back later } if ( item != null ) { return true ; } // Probably it failed due to the missing Item.DISCOVER // We try to retrieve the job using SYSTEM user and to check permissions manually. final Authentication userAuth = Jenkins . getAuthentication ( ) ; try ( ACLContext acl = ACL . as ( ACL . SYSTEM ) ) { final Item itemBySystemUser = jenkins . getItemByFullName ( fullName ) ; if ( itemBySystemUser == null ) { return false ; } // To get the item existence fact, a user needs Item.DISCOVER for the item // and Item.READ for all container folders. boolean canDiscoverTheItem = itemBySystemUser . hasPermission ( userAuth , Item . DISCOVER ) ; if ( canDiscoverTheItem ) { ItemGroup < ? > current = itemBySystemUser . getParent ( ) ; do { if ( current instanceof Item ) { final Item i = ( Item ) current ; current = i . getParent ( ) ; if ( ! i . hasPermission ( userAuth , Item . READ ) ) { canDiscoverTheItem = false ; } } else { current = null ; } } while ( canDiscoverTheItem && current != null ) ; } return canDiscoverTheItem ; } }
Checks if the current user can Discover the item . If yes it may be displayed as a text in Fingerprint UIs .