public class JenkinsClient {

	private static final String EMPTY_STRING = "";
	private static final String DEPTH_PARAM = "depth";
	private static final String DEPTH_VALUE = "100";

	private URI serverURI;
	private String username;
	private String password;

	public JenkinsClient(URI serverURI) {
		this.serverURI = serverURI;
	}

	public JenkinsClient(URI serverURI, String username, String password) {
		this(serverURI);
		this.username = username;
		this.password = password;
	}

	public HttpResponse<String> get(String path) throws JenkinsClientException {
		return get(createURI(path));
	}

	public HttpResponse<String> getDepth(String path) throws JenkinsClientException {
		URIBuilder uri = createURI(path);
		uri.addParameter(DEPTH_PARAM, DEPTH_VALUE);

		return get(uri);
	}

	public HttpResponse<String> getByURL(String url) throws JenkinsClientException {
		try {
			URIBuilder uri = new URIBuilder(url);

			return get(uri);
		} catch (URISyntaxException exception) {
			throw new JenkinsClientException(exception);
		}
	}

	public HttpResponse<String> getDepthByURL(String url) throws JenkinsClientException {
		try {
			URIBuilder uri = new URIBuilder(url);
			uri.addParameter(DEPTH_PARAM, DEPTH_VALUE);

			return get(uri);
		} catch (URISyntaxException exception) {
			throw new JenkinsClientException(exception);
		}
	}

	public HttpResponse<String> postXML(String path) throws JenkinsClientException {
		return post(createURI(path), EMPTY_STRING, MediaType.APPLICATION_XML_VALUE);
	}

	public HttpResponse<String> postXML(String path, String requestBody) throws JenkinsClientException {
		return post(createURI(path), requestBody, MediaType.APPLICATION_XML_VALUE);
	}

	public HttpResponse<String> postURLEncoded(String path, String requestBody) throws JenkinsClientException {
		return post(createURI(path), requestBody, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
	}

	private HttpResponse<String> get(URIBuilder uriBuilder) throws JenkinsClientException {
		try {
			GetRequest getRequest = Unirest.get(uriBuilder.build().toString());

			if (StringUtils.hasText(username)) {
				getRequest.basicAuth(username, password);
			}

			return getRequest.header(ConfigurationUtil.getConfiguration("CONTENT_TYPE"), MediaType.APPLICATION_XML_VALUE)
					.asString();
		} catch (UnirestException | URISyntaxException exception) {
			throw new JenkinsClientException(exception);
		}
	}

	private HttpResponse<String> post(URIBuilder uriBuilder, String requestBody, String mediaType)
			throws JenkinsClientException {
		try {
			HttpRequestWithBody post = Unirest.post(uriBuilder.build().toString());

			if (StringUtils.hasText(username)) {
				post.basicAuth(username, password);
			}

			return post.header(ConfigurationUtil.getConfiguration("CONTENT_TYPE"), mediaType)
					.body(requestBody)
					.asString();
		} catch (UnirestException | URISyntaxException exception) {
			throw new JenkinsClientException(exception);
		}
	}

	private URIBuilder createDefaultURI() {
		return new URIBuilder(serverURI);
	}

	private URIBuilder createURI(String path) {
		return createDefaultURI().setPath(path);
	}
} public class Build {

	private int number;
	private String description;
	private String displayName;
	private String result;
	private String url;
	private ChangeSet changeSet;

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDisplayName() {
		return displayName;
	}

	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public ChangeSet getChangeSet() {
		return changeSet;
	}

	public void setChangeSet(ChangeSet changeSet) {
		this.changeSet = changeSet;
	}
} public enum CoverageType {

	PACKAGES, FILES, CLASSES, METHODS, LINES, CONDITIONALS
} public class Job {

	private String description;
	private String name;
	private boolean buildable;
	private List<Build> builds;
	private Build lastBuild;
	private Build lastCompletedBuild;
	private Build lastFailedBuild;
	private Build lastStableBuild;
	private Build lastSuccessfulBuild;
	private int nextBuildNumber;

	public Job(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getName() {
		return name;
	}

	public boolean isBuildable() {
		return buildable;
	}

	public void setBuildable(boolean buildable) {
		this.buildable = buildable;
	}

	public List<Build> getBuilds() {
		return builds;
	}

	public void setBuilds(List<Build> builds) {
		this.builds = builds;
	}

	public Build getLastBuild() {
		return lastBuild;
	}

	public void setLastBuild(Build lastBuild) {
		this.lastBuild = lastBuild;
	}

	public Build getLastCompletedBuild() {
		return lastCompletedBuild;
	}

	public void setLastCompletedBuild(Build lastCompletedBuild) {
		this.lastCompletedBuild = lastCompletedBuild;
	}

	public Build getLastFailedBuild() {
		return lastFailedBuild;
	}

	public void setLastFailedBuild(Build lastFailedBuild) {
		this.lastFailedBuild = lastFailedBuild;
	}

	public Build getLastStableBuild() {
		return lastStableBuild;
	}

	public void setLastStableBuild(Build lastStableBuild) {
		this.lastStableBuild = lastStableBuild;
	}

	public Build getLastSuccessfulBuild() {
		return lastSuccessfulBuild;
	}

	public void setLastSuccessfulBuild(Build lastSuccessfulBuild) {
		this.lastSuccessfulBuild = lastSuccessfulBuild;
	}

	public int getNextBuildNumber() {
		return nextBuildNumber;
	}

	public void setNextBuildNumber(int nextBuildNumber) {
		this.nextBuildNumber = nextBuildNumber;
	}
} public class ListView {

	private String name;
	private String description;
	private List<Job> jobs = new LinkedList<>();

	public ListView(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Job> getJobs() {
		return jobs;
	}

	public void setJobs(List<Job> jobs) {
		this.jobs = jobs;
	}
} public enum Permission {

	HUDSON_ADMINISTER("hudson.model.Hudson.Administer"),
	HUDSON_CONFIGURE_UPDATE_CENTER("hudson.model.Hudson.ConfigureUpdateCenter"),
	HUDSON_READ("hudson.model.Hudson.Read"),
	HUDSON_RUN_SCRIPTS("hudson.model.Hudson.RunScripts"),
	HUDSON_UPLOAD_PLUGINS("hudson.model.Hudson.UploadPlugins"),
	CREDENTIALS_CREATE("com.cloudbees.plugins.credentials.CredentialsProvider.Create"),
	CREDENTIALS_DELETE("com.cloudbees.plugins.credentials.CredentialsProvider.Delete"),
	CREDENTIALS_MANAGE_DOMAINS("com.cloudbees.plugins.credentials.CredentialsProvider.ManageDomains"),
	CREDENTIALS_UPDATE("com.cloudbees.plugins.credentials.CredentialsProvider.Update"),
	CREDENTIALS_VIEW("com.cloudbees.plugins.credentials.CredentialsProvider.View"),
	COMPUTER_BUILD("hudson.model.Computer.Build"),
	COMPUTER_CONFIGURE("hudson.model.Computer.Configure"),
	COMPUTER_CONNECT("hudson.model.Computer.Connect"),
	COMPUTER_CREATE("hudson.model.Computer.Create"),
	COMPUTER_DELETE("hudson.model.Computer.Delete"),
	COMPUTER_DISCONNECT("hudson.model.Computer.Disconnect"),
	ITEM_BUILD("hudson.model.Item.Build"),
	ITEM_CANCEL("hudson.model.Item.Cancel"),
	ITEM_CONFIGURE("hudson.model.Item.Configure"),
	ITEM_CREATE("hudson.model.Item.Create"),
	ITEM_DELETE("hudson.model.Item.Delete"),
	ITEM_DISCOVER("hudson.model.Item.Discover"),
	ITEM_READ("hudson.model.Item.Read"),
	ITEM_WORKSPACE("hudson.model.Item.Workspace"),
	RUN_DELETE("hudson.model.Run.Delete"),
	RUN_UPDATE("hudson.model.Run.Update"),
	VIEW_CONFIGURE("hudson.model.View.Configure"),
	VIEW_CREATE("hudson.model.View.Create"),
	VIEW_DELETE("hudson.model.View.Delete"),
	VIEW_READ("hudson.model.View.Read"),
	SCM_TAG("hudson.scm.SCM.Tag");

	private String value;

	private Permission(String value) {
		this.value = value;
	}

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

	private String name;
	private String url;
	private String version;
	private boolean compatibleWithInstalledVersion;
	private String excerpt;
	private String title;
	private String wiki;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public boolean isCompatibleWithInstalledVersion() {
		return compatibleWithInstalledVersion;
	}

	public void setCompatibleWithInstalledVersion(boolean compatibleWithInstalledVersion) {
		this.compatibleWithInstalledVersion = compatibleWithInstalledVersion;
	}

	public String getExcerpt() {
		return excerpt;
	}

	public void setExcerpt(String excerpt) {
		this.excerpt = excerpt;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getWiki() {
		return wiki;
	}

	public void setWiki(String wiki) {
		this.wiki = wiki;
	}
} public interface AuthorizationStrategy { } public class CoverageElement {

	private String name;
	private int denominator;
	private int numerator;
	private double ratio;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getDenominator() {
		return denominator;
	}

	public void setDenominator(int denominator) {
		this.denominator = denominator;
	}

	public int getNumerator() {
		return numerator;
	}

	public void setNumerator(int numerator) {
		this.numerator = numerator;
	}

	public double getRatio() {
		return ratio;
	}

	public void setRatio(double ratio) {
		this.ratio = ratio;
	}
} public class CoverageReport {

	private String name;
	private List<CoverageElement> elements;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public List<CoverageElement> getElements() {
		return elements;
	}

	public void setElements(List<CoverageElement> elements) {
		this.elements = elements;
	}
} public enum ReportType {

	COVERAGE_REPORT, TEST_RESULTS_REPORT, STATIC_ANALYSIS_REPORT;
} public class StaticAnalysisReport {

	private Map<String, Integer> violations;
	private int violationsCount;

	public Map<String, Integer> getViolations() {
		return violations;
	}

	public void setViolations(Map<String, Integer> violations) {
		this.violations = violations;
	}

	public int getViolationsCount() {
		return violationsCount;
	}

	public void setViolationsCount(int violationsCount) {
		this.violationsCount = violationsCount;
	}
} public class TestResultsReport {

	private double duration;
	private boolean empty;
	private int failCount;
	private int passCount;
	private int skipCount;

	public double getDuration() {
		return duration;
	}

	public void setDuration(double duration) {
		this.duration = duration;
	}

	public boolean isEmpty() {
		return empty;
	}

	public void setEmpty(boolean empty) {
		this.empty = empty;
	}

	public int getFailCount() {
		return failCount;
	}

	public void setFailCount(int failCount) {
		this.failCount = failCount;
	}

	public int getPassCount() {
		return passCount;
	}

	public void setPassCount(int passCount) {
		this.passCount = passCount;
	}

	public int getSkipCount() {
		return skipCount;
	}

	public void setSkipCount(int skipCount) {
		this.skipCount = skipCount;
	}
} public interface SecurityRealm { } public class JenkinsClientException extends Exception {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3803262531306995968L;

	public JenkinsClientException(Throwable throwable) {
		super(throwable);
	}

} public class JenkinsServerException extends Exception {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4991901531451402986L;

	public JenkinsServerException(String message) {
		super(message);
	}

	public JenkinsServerException(Throwable throwable) {
		super(throwable);
	}

} public final class ConfigurationUtil {

	private static final String BASE_NAME = "br.com.vicenteneto.api.jenkins.configuration";
	private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BASE_NAME);

	public static String getConfiguration(String key) {

		try {
			return RESOURCE_BUNDLE.getString(key);
		} catch (MissingResourceException exception) {
			return "!" + key + "!";
		}
	}

	private ConfigurationUtil() { }
} public final class GroovyUtil {

	public static String concatenateStrings(String... strings) {

		StringBuilder strBuilder = new StringBuilder();
		for (String str : strings) {
			strBuilder.append(str);
		}
		return strBuilder.toString();
	}

	public static String executeScript(JenkinsClient jenkinsClient, String script) throws JenkinsServerException {

		try {
			String postScript = String.format(ConfigurationUtil.getConfiguration("SCRIPT"), script);
			HttpResponse<String> response = jenkinsClient
					.postURLEncoded(ConfigurationUtil.getConfiguration("URL_SCRIPT_TEXT"), postScript);

			if (response.getStatus() == HttpStatus.SC_FORBIDDEN) {
				throw new JenkinsServerException(ConfigurationUtil.getConfiguration("FORBIDDEN_ERROR"));
			}

			return response.getBody();
		} catch (JenkinsClientException exception) {
			throw new JenkinsServerException(exception);
		}
	}

	public static String generateGroovyScript(SecurityRealm security) throws JenkinsServerException {

		if (security instanceof HudsonPrivateSecurityRealm) {
			return generateHudsonPrivateSecurityRealm((HudsonPrivateSecurityRealm) security);
		} else if (security instanceof LDAPSecurityRealm) {
			return generateLDAPSecurityRealm((LDAPSecurityRealm) security);
		}

		throw new JenkinsServerException(ConfigurationUtil.getConfiguration("UNKNOW_SECURITY_REALM"));
	}

	public static String generateGroovyScript(AuthorizationStrategy authorization) throws JenkinsServerException {

		if (authorization instanceof FullControlOnceLoggedInAuthorizationStrategy) {
			return generateFullControlOnceLoggedInAuthorizationStrategy();
		} else if (authorization instanceof UnsecuredAuthorizationStrategy) {
			return generateUnsecuredAuthorizationStrategy();
		} else if (authorization instanceof ProjectMatrixAuthorizationStrategy) {
			return generateProjectMatrixAuthorizationStrategy((ProjectMatrixAuthorizationStrategy) authorization);
		}

		throw new JenkinsServerException(ConfigurationUtil.getConfiguration("UNKNOWN_AUTHORIZATION_STRATEGY"));
	}

	private static String generateHudsonPrivateSecurityRealm(HudsonPrivateSecurityRealm security) {

		boolean allowsSignUp = security.isAllowsSignUp();
		return String.format(ConfigurationUtil.getConfiguration("GROOVY_DEF_HUDSON_PRIVATE_SECURITY_REALM"), allowsSignUp);
	}

	private static String generateLDAPSecurityRealm(LDAPSecurityRealm security) {

		String server = security.getServer();
		String rootDN = security.getRootDN();
		String userSearchBase = security.getUserSearchBase();
		String userSearch = security.getUserSearch();
		String groupSearchBase = security.getGroupSearchBase();
		String groupSearchFilter = security.getGroupSearchFilter();
		String groupMembershipFilter = security.getGroupMembershipFilter();
		String managerDN = security.getManagerDN();
		String managerPassword = security.getManagerPassword();
		boolean inhibitInferRootDN = security.isInhibitInferRootDN();

		return String.format(ConfigurationUtil.getConfiguration("GROOVY_DEF_LDAP_SECURITY_REALM"), server, rootDN,
				userSearchBase, userSearch, groupSearchBase, groupSearchFilter, groupMembershipFilter, managerDN,
				managerPassword, inhibitInferRootDN);
	}

	private static String generateFullControlOnceLoggedInAuthorizationStrategy() {

		return ConfigurationUtil.getConfiguration("GROOVY_DEF_FULL_CONTROL_ONCE_LOGGED_IN_AUTHORIZATION_STRATEGY");
	}

	private static String generateUnsecuredAuthorizationStrategy() {

		return ConfigurationUtil.getConfiguration("GROOVY_DEF_UNSECURED_AUTHORIZATION_STRATEGY");
	}

	private static String generateProjectMatrixAuthorizationStrategy(ProjectMatrixAuthorizationStrategy authorization) {

		StringBuilder sbScript = new StringBuilder();
		sbScript.append(ConfigurationUtil.getConfiguration("GROOVY_DEF_PROJECT_MATRIX_AUTHORIZATION_STRATEGY"));

		for (String sid : authorization.getGrantedPermissions().keySet()) {
			for (Permission permission : authorization.getGrantedPermissions().get(sid)) {
				sbScript.append(
						String.format(ConfigurationUtil.getConfiguration("GROOVY_ADD_PERMISSION_TO_AUTHORIZATION"), permission.getValue(), sid));
			}
		}

		return sbScript.toString();
	}

	private GroovyUtil() { }
} public final class ReportUtil {

	public static String getBaseReportUrl(ReportType reportType) {

		if (reportType.equals(ReportType.COVERAGE_REPORT)) {
			return ConfigurationUtil.getConfiguration("URL_GET_COVERAGE_REPORT");
		} else if (reportType.equals(ReportType.TEST_RESULTS_REPORT)) {
			return ConfigurationUtil.getConfiguration("URL_GET_TEST_RESULTS_REPORT");
		} else {
			return ConfigurationUtil.getConfiguration("URL_GET_STATIC_ANALYSIS_REPORT");
		}
	}

	private ReportUtil() { }
}
import java.net.URI;
import java.util.List;
import org.apache.http.HttpStatus;
import org.json.JSONObject;
import com.google.gson.Gson;
import com.mashape.unirest.http.HttpResponse;
import br.com.vicenteneto.api.jenkins.client.JenkinsClient;
import br.com.vicenteneto.api.jenkins.domain.Build;
import br.com.vicenteneto.api.jenkins.domain.CoverageType;
import br.com.vicenteneto.api.jenkins.domain.Job;
import br.com.vicenteneto.api.jenkins.domain.ListView;
import br.com.vicenteneto.api.jenkins.domain.Permission;
import br.com.vicenteneto.api.jenkins.domain.Plugin;
import br.com.vicenteneto.api.jenkins.domain.authorization.AuthorizationStrategy;
import br.com.vicenteneto.api.jenkins.domain.report.CoverageElement;
import br.com.vicenteneto.api.jenkins.domain.report.CoverageReport;
import br.com.vicenteneto.api.jenkins.domain.report.ReportType;
import br.com.vicenteneto.api.jenkins.domain.report.StaticAnalysisReport;
import br.com.vicenteneto.api.jenkins.domain.report.TestResultsReport;
import br.com.vicenteneto.api.jenkins.domain.security.SecurityRealm;
import br.com.vicenteneto.api.jenkins.exception.JenkinsClientException;
import br.com.vicenteneto.api.jenkins.exception.JenkinsServerException;
import br.com.vicenteneto.api.jenkins.util.ConfigurationUtil;
import br.com.vicenteneto.api.jenkins.util.GroovyUtil;
import br.com.vicenteneto.api.jenkins.util.ReportUtil;
	}
	
	public void deleteJob(String jobName) throws JenkinsServerException {

		if (!checkJobExists(jobName)) {
			throw new JenkinsServerException(
					String.format(ConfigurationUtil.getConfiguration("JOB_DOES_NOT_EXISTS"), jobName));
		}

		String script = ConfigurationUtil.getConfiguration("GROOVY_DELETE_ITEM");
		GroovyUtil.executeScript(jenkinsClient, String.format(script, jobName));

		if (checkJobExists(jobName)) {
			throw new JenkinsServerException(
					String.format(ConfigurationUtil.getConfiguration("ERROR_DELETING_JOB"), jobName));
		}
	}

	public void addJobToView(String viewName, String jobName) throws JenkinsServerException {

		if (!checkViewExists(viewName)) {
			throw new JenkinsServerException(
					String.format(ConfigurationUtil.getConfiguration("VIEW_DOES_NOT_EXISTS"), viewName));
		}
		if (!checkJobExists(jobName)) {
			throw new JenkinsServerException(
					String.format(ConfigurationUtil.getConfiguration("JOB_DOES_NOT_EXISTS"), jobName));
		}

		String script = ConfigurationUtil.getConfiguration("GROOVY_ADD_JOB_TO_VIEW");
		GroovyUtil.executeScript(jenkinsClient, String.format(script, viewName, jobName));
	}

	public int executeJob(String jobName) throws JenkinsServerException {
		if (!checkJobExists(jobName)) {
			throw new JenkinsServerException(
					String.format(ConfigurationUtil.getConfiguration("JOB_DOES_NOT_EXISTS"), jobName));
		}

		Job job = getJobByName(jobName);
		String script = ConfigurationUtil.getConfiguration("GROOVY_RUN_JOB");
		GroovyUtil.executeScript(jenkinsClient, String.format(script, jobName));

		return job.getNextBuildNumber();
	}

	public Build getBuild(String jobName, int buildNumber) throws JenkinsServerException {

		try {
			if (!checkJobExists(jobName)) {
				throw new JenkinsServerException(
						String.format(ConfigurationUtil.getConfiguration("JOB_DOES_NOT_EXISTS"), jobName));
			}

			String url = String.format(ConfigurationUtil.getConfiguration("URL_GET_BUILD"), jobName, buildNumber);
			HttpResponse<String> httpResponse = jenkinsClient.get(url);

			if (httpResponse.getStatus() == HttpStatus.SC_NOT_FOUND) {
				throw new JenkinsServerException(
						String.format(ConfigurationUtil.getConfiguration("BUILD_NOT_FOUND"), buildNumber, jobName));
			}

			return gson.fromJson(httpResponse.getBody(), Build.class);
		} catch (JenkinsClientException exception) {
			throw new JenkinsServerException(exception);
		}
	}

	public void addUserToProjectMatrix(String jobName, String username, List<Permission> permissions)
			throws JenkinsServerException {

		if (!checkJobExists(jobName)) {
			throw new JenkinsServerException(
					String.format(ConfigurationUtil.getConfiguration("JOB_DOES_NOT_EXISTS"), jobName));
		}

		if (!checkAuthorizationStrategyIsProjectMatrix()) {
			throw new JenkinsServerException(ConfigurationUtil.getConfiguration("AUTHORIZATION_STRATEGY_ERROR"));
		}

		String propertyName = ConfigurationUtil.getConfiguration("GROOVY_DEF_AUTHORIZATION_MATRIX_PROPERTY");
		String job = String.format(ConfigurationUtil.getConfiguration("GROOVY_GET_ITEM"), jobName);
		String addAuthorizationMatrixProperty = ConfigurationUtil.getConfiguration("GROOVY_ADD_AUTHORIZATION_MATRIX_PROPERTY");
		String property = ConfigurationUtil.getConfiguration("GROOVY_GET_PROPERTY");
		String jobSave = ConfigurationUtil.getConfiguration("GROOVY_JOB_SAVE");

		StringBuilder sbAddProperties = new StringBuilder();
		for (Permission permission : permissions) {
			sbAddProperties
					.append(String.format(ConfigurationUtil.getConfiguration("GROOVY_ADD_PERMISSION_TO_PROPERTY"), permission.getValue(), username));
		}

		String script = GroovyUtil.concatenateStrings(propertyName, job, addAuthorizationMatrixProperty, property, sbAddProperties.toString(), jobSave);
		GroovyUtil.executeScript(jenkinsClient, script);
	}

	public void removeUserFromProjectMatrix(String jobName, String username) throws JenkinsServerException {

		if (!checkJobExists(jobName)) {
			throw new JenkinsServerException(
					String.format(ConfigurationUtil.getConfiguration("JOB_DOES_NOT_EXISTS"), jobName));
		}

		if (!checkAuthorizationStrategyIsProjectMatrix()) {
			throw new JenkinsServerException(ConfigurationUtil.getConfiguration("AUTHORIZATION_STRATEGY_ERROR"));
		}

		String propertyName = ConfigurationUtil.getConfiguration("GROOVY_DEF_AUTHORIZATION_MATRIX_PROPERTY");
		String job = String.format(ConfigurationUtil.getConfiguration("GROOVY_GET_ITEM"), jobName);
		String addAuthorizationMatrixProperty = ConfigurationUtil.getConfiguration("GROOVY_ADD_AUTHORIZATION_MATRIX_PROPERTY");
		String property = ConfigurationUtil.getConfiguration("GROOVY_GET_PROPERTY");
		String removeUserPermissions = String.format(ConfigurationUtil.getConfiguration("GROOVY_REMOVE_USER_FROM_GRANTED_PERMISSIONS"), username);
		String jobSave = ConfigurationUtil.getConfiguration("GROOVY_JOB_SAVE");

		String script = GroovyUtil.concatenateStrings(propertyName, job, addAuthorizationMatrixProperty, property, removeUserPermissions, jobSave);
		GroovyUtil.executeScript(jenkinsClient, script);
	}

	public CoverageReport getCoverageReport(String jobName, int buildNumber) throws JenkinsServerException {

		String jsonReport = getJsonReport(jobName, buildNumber, ReportType.COVERAGE_REPORT);