Skip to content

Commit 1e43ef3

Browse files
committed
[JENKINS-75609] Missing avatar for private when Jenkins security is enabled
Fix code that retrieves a Jenkins item using an ACL context to avoid a null result when Jenkins security is enabled.
1 parent 6d9153c commit 1e43ef3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/avatars/BitbucketAvatarImageSource.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.cloudbees.plugins.credentials.common.StandardCredentials;
3131
import edu.umd.cs.findbugs.annotations.NonNull;
3232
import edu.umd.cs.findbugs.annotations.Nullable;
33+
import hudson.security.ACL;
34+
import hudson.security.ACLContext;
3335
import java.util.logging.Level;
3436
import java.util.logging.Logger;
3537
import jenkins.authentication.tokens.api.AuthenticationTokens;
@@ -59,7 +61,12 @@ public BitbucketAvatarImageSource(@NonNull String avatarURL, @NonNull String ser
5961
public AvatarImage fetch() {
6062
try {
6163
if (canFetch()) {
62-
SCMNavigatorOwner owner = Jenkins.get().getItemByFullName(scmOwner, SCMNavigatorOwner.class);
64+
SCMNavigatorOwner owner = null;
65+
// to access item when security (not matrix) is enabled or
66+
// logged user does not have READ(DISCOVER) access on the item
67+
try (ACLContext as = ACL.as2(ACL.SYSTEM2)) { // JENKINS-75609
68+
owner = Jenkins.get().getItemByFullName(scmOwner, SCMNavigatorOwner.class);
69+
}
6370
if (owner != null) {
6471
StandardCredentials credentials = BitbucketCredentials.lookupCredentials(serverURL, owner, credentialsId, StandardCredentials.class);
6572
BitbucketAuthenticator authenticator = AuthenticationTokens.convert(BitbucketAuthenticator.authenticationContext(serverURL), credentials);

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/extension/GitClientAuthenticatorExtension.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import hudson.plugins.git.GitSCM;
3737
import hudson.plugins.git.extensions.GitSCMExtension;
3838
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;
39+
import hudson.security.ACL;
40+
import hudson.security.ACLContext;
3941
import java.util.Objects;
4042
import jenkins.authentication.tokens.api.AuthenticationTokens;
4143
import jenkins.model.Jenkins;
@@ -95,7 +97,12 @@ private BitbucketAuthenticator authenticator() {
9597
}
9698
StandardCredentials credentials;
9799
if (scmOwner != null) {
98-
Item owner = Jenkins.get().getItemByFullName(scmOwner, Item.class);
100+
Item owner = null;
101+
// to access item when security (not matrix) is enabled or
102+
// logged user does not have READ(DISCOVER) access on the item
103+
try (ACLContext as = ACL.as2(ACL.SYSTEM2)) {
104+
owner = Jenkins.get().getItemByFullName(scmOwner, Item.class);
105+
}
99106
if (owner == null) {
100107
throw new IllegalStateException("Item " + scmOwner + " seems to be relocated, perform a 'Scan project Now' action to refresh old data");
101108
}

0 commit comments

Comments
 (0)