Skip to content

Commit

Permalink
[FIXED JENKINS-18485] Introduce Computer.EXTENDED_READ permission
Browse files Browse the repository at this point in the history
    From now on user needs:
      Computer.CREATE to use 'create-node' CLI command
      Computer.DELETE to use 'delete-node' CLI command
      Computer.CONFIGURE to use 'update-node' CLI command and its REST alternative
      Computer.EXTENDED_READ to use 'get-node' CLI command and its REST alternative
  • Loading branch information
olivergondza committed Aug 13, 2013
1 parent 3e45ce9 commit 5db147e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/cli/GetNodeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String getShortDescription() {
@Override
protected int run() throws IOException {

node.checkPermission(Computer.READ);
node.checkPermission(Computer.EXTENDED_READ);

Jenkins.XSTREAM2.toXMLUTF8(node, stdout);

Expand Down
7 changes: 2 additions & 5 deletions core/src/main/java/hudson/model/Computer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp)

if (req.getMethod().equals("GET")) {
// read
checkPermission(READ);
checkPermission(EXTENDED_READ);
rsp.setContentType("application/xml");
Jenkins.XSTREAM2.toXMLUTF8(getNode(), rsp.getOutputStream());
return;
Expand Down Expand Up @@ -1350,11 +1350,8 @@ public boolean accept(File dir, String name) {
}

public static final PermissionGroup PERMISSIONS = new PermissionGroup(Computer.class,Messages._Computer_Permissions_Title());
/**
* Permission to configure slaves.
*/
public static final Permission READ = new Permission(PERMISSIONS,"Read", Messages._Computer_ReadPermission_Description(), Permission.READ, PermissionScope.COMPUTER);
public static final Permission CONFIGURE = new Permission(PERMISSIONS,"Configure", Messages._Computer_ConfigurePermission_Description(), Permission.CONFIGURE, PermissionScope.COMPUTER);
public static final Permission EXTENDED_READ = new Permission(PERMISSIONS,"ExtendedRead", Messages._Computer_ExtendedReadPermission_Description(), CONFIGURE, PermissionScope.COMPUTER);
public static final Permission DELETE = new Permission(PERMISSIONS,"Delete", Messages._Computer_DeletePermission_Description(), Permission.DELETE, PermissionScope.COMPUTER);
public static final Permission CREATE = new Permission(PERMISSIONS,"Create", Messages._Computer_CreatePermission_Description(), Permission.CREATE, PermissionScope.COMPUTER);
public static final Permission DISCONNECT = new Permission(PERMISSIONS,"Disconnect", Messages._Computer_DisconnectPermission_Description(), Jenkins.ADMINISTER, PermissionScope.COMPUTER);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/hudson/model/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ CLI.wait-node-offline.shortDescription=Wait for a node to become offline
Computer.Caption=Slave {0}
Computer.NoSuchSlaveExists=No such slave "{0}" exists. Did you mean "{1}"?
Computer.Permissions.Title=Slave
Computer.ReadPermission.Description=This permission allows users to read slave configuration.
Computer.ExtendedReadPermission.Description=This permission allows users to read slave configuration.
Computer.ConfigurePermission.Description=This permission allows users to configure slaves.
Computer.DeletePermission.Description=This permission allows users to delete existing slaves.
Computer.CreatePermission.Description=This permission allows users to create slaves.
Expand Down
6 changes: 3 additions & 3 deletions test/src/test/java/hudson/cli/GetNodeCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class GetNodeCommandTest {
.invokeWithArgs("MySlave")
;

assertThat(result.stderr(), containsString("user is missing the Slave/Read permission"));
assertThat(result.stderr(), containsString("user is missing the Slave/ExtendedRead permission"));
assertThat("No output expected", result.stdout(), isEmptyString());
assertThat("Command is expected to fail", result.returnCode(), equalTo(-1));
}
Expand All @@ -67,7 +67,7 @@ public class GetNodeCommandTest {
j.createSlave("MySlave", null, null);

final CLICommandInvoker.Result result = command
.authorizedTo(Computer.READ, Jenkins.READ)
.authorizedTo(Computer.EXTENDED_READ, Jenkins.READ)
.invokeWithArgs("MySlave")
;

Expand All @@ -80,7 +80,7 @@ public class GetNodeCommandTest {
@Test public void getNodeShouldFailIfNodeDoesNotExist() throws Exception {

final CLICommandInvoker.Result result = command
.authorizedTo(Computer.READ, Jenkins.READ)
.authorizedTo(Computer.EXTENDED_READ, Jenkins.READ)
.invokeWithArgs("MySlave")
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void configXmlGetShouldYieldNodeConfiguration() throws Exception {

GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy();
rule.jenkins.setAuthorizationStrategy(auth);
auth.add(Computer.READ, "user");
auth.add(Computer.EXTENDED_READ, "user");

final OutputStream outputStream = captureOutput();

Expand Down

0 comments on commit 5db147e

Please sign in to comment.