Skip to content

Commit

Permalink
check required permission on test connection request (#20)
Browse files Browse the repository at this point in the history
Co-authored-by: Piotr Lugowski <piotr.lugowski@dynatrace.com>
  • Loading branch information
lugowskii and lugowskii committed Mar 11, 2020
1 parent 1e769d4 commit b6e5570
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
import hudson.util.ListBoxModel;
import hudson.util.Secret;
import jenkins.model.GlobalConfiguration;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
Expand Down Expand Up @@ -186,7 +187,11 @@ public FormValidation doTestDynatraceConnection(
@QueryParameter("username") final String username,
@QueryParameter("validateCerts") final boolean validateCerts,
@QueryParameter("password") final String password) {

final Jenkins instance = Jenkins.getInstance();
if (instance == null) {
throw new IllegalStateException("Jenkins instance not available. Could not handle test connection request.");
}
instance.checkPermission(Jenkins.ADMINISTER);
try {
final SystemProfiles connection = new SystemProfiles(new DynatraceClient(new BasicServerConfiguration(username, password, protocol.startsWith("https"), host, Integer.parseInt(port), validateCerts, 10000)));
try {
Expand Down

0 comments on commit b6e5570

Please sign in to comment.