Skip to content

Commit

Permalink
foundational work for integrating the "credentials plugin"
Browse files Browse the repository at this point in the history
step 1: figure out the UI and create new Class to handle auth

see this for details: https://issues.jenkins-ci.org/browse/JENKINS-20826
  • Loading branch information
morficus committed Dec 3, 2013
1 parent 6cfa611 commit 9234b4b
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 31 deletions.
@@ -0,0 +1,46 @@
package org.jenkinsci.plugins.ParameterizedRemoteTrigger;


import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Extension;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Descriptor;

public class Auth extends AbstractDescribableImpl<Auth> {

private final String value;
private final String username;
private final String apiToken;

@DataBoundConstructor
public Auth(String value, String username, String apiToken) {
this.value = value;
this.username = username;
this.apiToken = apiToken;
}

public String getValue() {
return this.value;
}

public Boolean isMatch(String value) {
return this.getValue().equals(value);
}

public String getUsername() {
return this.username;
}

public String getApiToken() {
return this.apiToken;
}

@Extension
public static class DescriptorImpl extends Descriptor<Auth> {
@Override
public String getDisplayName() {
return "";
}
}
}
Expand Up @@ -5,14 +5,14 @@
import java.net.URI;
import java.net.URL;

import net.sf.json.JSONObject;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;

import hudson.Extension;
import hudson.model.AbstractDescribableImpl;

import hudson.model.Descriptor;

import hudson.util.FormValidation;

/**
Expand All @@ -26,19 +26,26 @@ public class RemoteJenkinsServer extends AbstractDescribableImpl<RemoteJenkinsSe
private final URL address;
private final String displayName;
private final boolean hasBuildTokenRootSupport;
private final Auth authenticationMode;
// private final JSONObject authenticationMode;
// private final String authenticationMode;
private final String username;
private final String apiToken;

@DataBoundConstructor
public RemoteJenkinsServer(String address, String displayName, boolean hasBuildTokenRootSupport, String username,
String apiToken) throws MalformedURLException {
public RemoteJenkinsServer(String address, String displayName, boolean hasBuildTokenRootSupport,
Auth authenticationMode) throws MalformedURLException {

this.address = new URL(address);
this.displayName = displayName.trim();
this.hasBuildTokenRootSupport = hasBuildTokenRootSupport;
this.authenticationMode = authenticationMode;
// this.authenticationMode = authenticationMode;

this.username = username.trim();
this.apiToken = apiToken.trim();
// Holding on to both of these variables for legacy purposes. The seemingly 'dirty' getters for these properties
// are for the same reason.
this.username = "";
this.apiToken = "";

}

Expand All @@ -58,16 +65,32 @@ public URL getAddress() {
return address;
}

public Auth getAuthenticationMode() {
return this.authenticationMode;
}

public boolean getHasBuildTokenRootSupport() {
return this.hasBuildTokenRootSupport;
}

public String getUsername() {
return this.username;
String username = "";
if (this.username.equals("")) {
username = this.authenticationMode.getUsername();
} else {
username = this.username;
}
return username;
}

public String getApiToken() {
return this.apiToken;
String apiToken = "";
if (this.apiToken.equals("")) {
apiToken = this.authenticationMode.getApiToken();
} else {
apiToken = this.apiToken;
}
return apiToken;
}

@Override
Expand All @@ -78,6 +101,8 @@ public DescriptorImpl getDescriptor() {
@Extension
public static class DescriptorImpl extends Descriptor<RemoteJenkinsServer> {

private JSONObject authenticationMode;

/**
* In order to load the persisted global configuration, you have to call load() in the constructor.
*/
Expand All @@ -89,6 +114,10 @@ public String getDisplayName() {
return "";
}

public JSONObject doFillAuthenticationMode() {
return this.authenticationMode.getJSONObject("value");
}

/**
* Validates the given address to see that it's well-formed, and is reachable.
*
Expand Down
@@ -1,31 +1,53 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="Display name" field="displayName" >
<f:textbox />
</f:entry>
<f:entry title="Display name" field="displayName" >
<f:textbox />
</f:entry>

<f:entry title="Enable 'build token root' support" field="hasBuildTokenRootSupport">
<f:checkbox />
</f:entry>


<!-- <f:optionalBlock title="Add authentication credentials" field="needsAuthentication"> -->

<f:entry title="Authentication mode">
<table style="width:100%">

<f:radioBlock name="authenticationMode" title="None" value="none" checked="${instance.getAuthenticationMode().isMatch('none')}">
</f:radioBlock>

<f:radioBlock name="authenticationMode" title="Username + API Token" value="apiToken" checked="${instance.getAuthenticationMode().isMatch('apiToken')}">
<f:entry title="Remote Username" field="username" >
<f:textbox />
</f:entry>

<f:entry title="API Token" field="apiToken">
<f:password />
</f:entry>
</f:radioBlock>

<f:radioBlock name="authenticationMode" title="Use the Credentials Plugin" value="credentialsPlugin" checked="${instance.getAuthenticationMode().isMatch('credentialsPlugin')}">

<f:entry title="Enable 'build token root' support" field="hasBuildTokenRootSupport">
<f:checkbox />
</f:entry>
</f:radioBlock>
</table>
</f:entry>

<f:advanced title="Add/Edit username &amp; token">
<f:entry title="Remote Username" field="username" >
<!-- </f:optionalBlock> -->


<f:entry title="Remote address and port" field="address" description="Remember to indicate the protocol (i.e.: http, https, etc)" >
<f:textbox />
</f:entry>
<f:entry title="API Token" field="apiToken">
<f:password />
<f:validateButton title="Validate Address" method="validateAddress" with="address" />


<f:entry title="">
<div style="float: left">
<f:repeatableDeleteButton />
</div>
</f:entry>
</f:advanced>

<f:entry title="Remote address and port" field="address" description="Remember to indicate the protocol (i.e.: http, https, etc)" >
<f:textbox />
</f:entry>
<f:validateButton title="Validate Address" method="validateAddress" with="address" />


<f:entry title="">
<div style="float: left">
<f:repeatableDeleteButton />
</div>
</f:entry>
<hr/>
<f:entry title="">
<hr/>
</f:entry>
</j:jelly>

0 comments on commit 9234b4b

Please sign in to comment.