Skip to content

Commit

Permalink
Performance - Only add trust when needed.
Browse files Browse the repository at this point in the history
May fix issue JENKINS-44430
  • Loading branch information
p4paul committed Feb 14, 2018
1 parent ba5a2fd commit 5d1319a
Showing 1 changed file with 23 additions and 15 deletions.
@@ -1,6 +1,8 @@
package org.jenkinsci.plugins.p4.client;

import com.perforce.p4java.PropertyDefs;
import com.perforce.p4java.exception.ConnectionException;
import com.perforce.p4java.exception.P4JavaException;
import com.perforce.p4java.impl.mapbased.rpc.RpcPropertyDefs;
import com.perforce.p4java.option.UsageOptions;
import com.perforce.p4java.server.IOptionsServer;
Expand All @@ -19,8 +21,7 @@
*/
public class ConnectionFactory {

private static Logger logger = Logger.getLogger(ConnectionFactory.class
.getName());
private static Logger logger = Logger.getLogger(ConnectionFactory.class.getName());

private static IOptionsServer currentP4;

Expand All @@ -46,23 +47,32 @@ public static IOptionsServer getConnection(ConnectionConfig config)

IOptionsServer iserver = getRawConnection(config);

// Add trust for SSL connections
if (config.isSsl()) {
String serverTrust = iserver.getTrust();
if (!serverTrust.equalsIgnoreCase(config.getTrust())) {
logger.warning("Trust mismatch! Server fingerprint: "
+ serverTrust);
// Connect and update current P4 connection
try {
iserver.connect();
} catch (ConnectionException e) {
if (config.isSsl()) {
addTrust(iserver, config);
iserver.connect();
} else {
iserver.addTrust(config.getTrust());
throw e;
}
}

// Connect and update current P4 connection
iserver.connect();
currentP4 = iserver;
return iserver;
}

// Add trust for SSL connections
private static void addTrust(IOptionsServer iserver, ConnectionConfig config) throws P4JavaException {
String serverTrust = iserver.getTrust();
if (!serverTrust.equalsIgnoreCase(config.getTrust())) {
logger.warning("Trust mismatch! Server fingerprint: " + serverTrust);
} else {
iserver.addTrust(config.getTrust());
logger.fine("addTrust - ok: " + config.getTrust());
}
}

public static FormValidation testConnection(ConnectionConfig config) {

// Test for SSL connections
Expand All @@ -71,9 +81,7 @@ public static FormValidation testConnection(ConnectionConfig config) {
if (config.isSsl()) {
String serverTrust = iserver.getTrust();
if (!serverTrust.equalsIgnoreCase(config.getTrust())) {
return FormValidation
.error("Trust mismatch! Server fingerprint: "
+ serverTrust);
return FormValidation.error("Trust mismatch! Server fingerprint: " + serverTrust);
} else {
iserver.addTrust(config.getTrust());
}
Expand Down

0 comments on commit 5d1319a

Please sign in to comment.