Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/src/main/java/hudson/AboutJenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public Permission getRequiredPermission() {
return Jenkins.READ;
}

@Override
public boolean hasRequiredPermission() {
return Jenkins.get().hasAnyPermission(Jenkins.MANAGE_AND_SYSTEM_READ);
}

@NonNull
@Override
public Category getCategory() {
Expand Down
13 changes: 13 additions & 0 deletions core/src/main/java/hudson/model/ManagementLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ public boolean getRequiresConfirmation() {
return Jenkins.ADMINISTER;
}

/**
* Checks if the current user has the minimum required permission to view this Management Link.
* <p>
* Subclasses may override this method instead of {@link #getRequiredPermission()} to perform more complex permission checks,
* for example, checking either {@link Jenkins#MANAGE} or {@link Jenkins#SYSTEM_READ}.
* </p>
* @see #getRequiredPermission()
* @since TODO
*/
public boolean hasRequiredPermission() {
return Jenkins.get().hasPermission(getRequiredPermission());
}

/**
* Define if the rendered link will use the default GET method or POST.
* @return true if POST must be used
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/jenkins/management/ConfigureLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public Permission getRequiredPermission() {
return Jenkins.READ;
}

@Override
public boolean hasRequiredPermission() {
return Jenkins.get().hasAnyPermission(Jenkins.MANAGE_AND_SYSTEM_READ);
}

@Override
public String getUrlName() {
return "configure";
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/management/StatisticsLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public String getDescription() {
@NonNull
@Override
public Permission getRequiredPermission() {
return Jenkins.MANAGE;
return Jenkins.READ;
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/jenkins/management/SystemInfoLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public Permission getRequiredPermission() {
return Jenkins.READ;
}

@Override
public boolean hasRequiredPermission() {
return Jenkins.get().hasAnyPermission(Jenkins.MANAGE_AND_SYSTEM_READ);
}

@Override
public String getUrlName() {
return "systemInfo";
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/model/Jenkins.java
Original file line number Diff line number Diff line change
Expand Up @@ -5173,7 +5173,7 @@
if (link.getIconFileName() == null) {
continue;
}
if (!Jenkins.get().hasPermission(link.getRequiredPermission())) {
if (!link.hasRequiredPermission()) {
continue;
}
byCategory.computeIfAbsent(link.getCategory(), c -> new ArrayList<>()).add(link);
Expand Down Expand Up @@ -5860,7 +5860,7 @@
new PermissionScope[]{PermissionScope.JENKINS});

@Restricted(NoExternalUse.class) // called by jelly
public static final Permission[] MANAGE_AND_SYSTEM_READ =

Check warning on line 5863 in core/src/main/java/jenkins/model/Jenkins.java

View check run for this annotation

ci.jenkins.io / SpotBugs

MS_MUTABLE_ARRAY

HIGH: jenkins.model.Jenkins.MANAGE_AND_SYSTEM_READ is a mutable array
Raw output
<p> A final static field references an array and can be accessed by malicious code or by accident from another package. This code can freely modify the contents of the array.</p>
new Permission[] { MANAGE, SYSTEM_READ };

public static final Permission READ = new Permission(PERMISSIONS, "Read", Messages._Hudson_ReadPermission_Description(), Permission.READ, PermissionScope.JENKINS);
Expand Down
Loading