Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
target
bin
.metadata
**/integrationTest.properties
**/integrationTest.properties
/target/
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<!-- Artifact Information -->
<groupId>com.openshift</groupId>
<artifactId>openshift-java-client</artifactId>
<version>2.6.1.Final</version>
<version>2.6.2.Final</version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seem to change api - should it not be 2.7.0 then ?

<packaging>jar</packaging>
<name>OpenShift Java Client</name>
<url>http://openshift.redhat.com</url>
Expand Down
80 changes: 53 additions & 27 deletions src/main/java/com/openshift/client/OpenShiftConnectionFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012 Red Hat, Inc.
* Copyright (c) 2012-2014 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand All @@ -14,8 +14,10 @@
import java.io.IOException;

import com.openshift.client.IHttpClient.ISSLCertificateCallback;
import com.openshift.client.configuration.AbstractOpenshiftConfiguration.ConfigurationOptions;
import com.openshift.client.configuration.IOpenShiftConfiguration;
import com.openshift.client.configuration.OpenShiftConfiguration;
import com.openshift.client.utils.SSLUtils;
import com.openshift.internal.client.AbstractOpenShiftConnectionFactory;
import com.openshift.internal.client.IRestService;
import com.openshift.internal.client.RestService;
Expand All @@ -33,7 +35,7 @@
*
*/
public class OpenShiftConnectionFactory extends AbstractOpenShiftConnectionFactory {
private IOpenShiftConfiguration configuration = null;
private IOpenShiftConfiguration configuration;
/**
* Establish a connection with the clientId along with user's password.
* User's login and Server URL are retrieved from the local configuration
Expand All @@ -49,11 +51,7 @@ public class OpenShiftConnectionFactory extends AbstractOpenShiftConnectionFacto
* @throws OpenShiftException
*/
public IOpenShiftConnection getConnection(final String clientId, final String password) throws OpenShiftException {
try {
configuration = new OpenShiftConfiguration();
} catch (IOException e) {
throw new OpenShiftException(e, "Failed to load OpenShift configuration file.");
}
IOpenShiftConfiguration configuration = getConfiguration();
return getConnection(clientId, configuration.getRhlogin(), password, configuration.getLibraServer());
}

Expand All @@ -75,12 +73,7 @@ public IOpenShiftConnection getConnection(final String clientId, final String pa
*/
public IOpenShiftConnection getConnection(final String clientId, final String username, final String password)
throws OpenShiftException {
try {
configuration = new OpenShiftConfiguration();
} catch (IOException e) {
throw new OpenShiftException(e, "Failed to load OpenShift configuration file.");
}
return getConnection(clientId, username, password, configuration.getLibraServer());
return getConnection(clientId, username, password, getConfiguration().getLibraServer());
}

/**
Expand Down Expand Up @@ -115,6 +108,23 @@ public IOpenShiftConnection getConnection(final String clientId, final String us
return getConnection(clientId, username, password, null, null, serverUrl, null);
}

public IOpenShiftConnection getConnection(final String clientId, final String username, final String password,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference from this getconnection and other getconnections ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are all overloads. There's now an overload with a regex to exclude ciphers.

final String authKey, final String authIV, final String serverUrl,
final ISSLCertificateCallback sslCertificateCallback) throws OpenShiftException {
return getConnection(clientId, username, password, authKey, authIV, serverUrl, sslCertificateCallback, createCipherExclusionRegex(getConfiguration()));
}

protected String createCipherExclusionRegex(IOpenShiftConfiguration configuration) {
if(configuration.getDisableBadSSLCiphers() == ConfigurationOptions.YES
|| (configuration.getDisableBadSSLCiphers() == ConfigurationOptions.AUTO) && !SSLUtils.supportsDHECipherKeysOf(1024 + 64)) {
// jdk < 1.8 only support DHE cipher keys <= 1024 bit
// https://issues.jboss.org/browse/JBIDE-18454
return SSLUtils.CIPHER_DHE_REGEX;
} else {
return null;
}
}

/**
* Establish a connection with the clientId along with user's login and
* password.
Expand All @@ -133,31 +143,47 @@ public IOpenShiftConnection getConnection(final String clientId, final String us
* @throws OpenShiftException
*/
public IOpenShiftConnection getConnection(final String clientId, final String username, final String password,
final String authKey, final String authIV, final String serverUrl,
final ISSLCertificateCallback sslCertificateCallback) throws OpenShiftException {
if (configuration == null) {
try {
configuration = new OpenShiftConfiguration();
} catch (IOException e) {
throw new OpenShiftException(e, "Failed to load OpenShift configuration file.");
}
}
final String authKey, final String authIV, final String serverUrl,
final ISSLCertificateCallback sslCertificateCallback, String exludeSSLCipherRegex)
throws OpenShiftException {

Assert.notNull(clientId);
Assert.notNull(username);
Assert.notNull(password);
Assert.notNull(serverUrl);

IHttpClient httpClient = createClient(
clientId, username, password, authKey, authIV, serverUrl, sslCertificateCallback, exludeSSLCipherRegex);
try {
IHttpClient httpClient =
new UrlConnectionHttpClientBuilder()
return getConnection(clientId, username, password, serverUrl, httpClient);
} catch (IOException e) {
throw new OpenShiftException(e, "Failed to establish connection for user ''{0}}''", username);
}
}

protected IHttpClient createClient(final String clientId, final String username, final String password,
final String authKey, final String authIV, final String serverUrl,
final ISSLCertificateCallback sslCertificateCallback, String exludeSSLCipherRegex) {
return new UrlConnectionHttpClientBuilder()
.setCredentials(username, password, authKey, authIV)
.setSSLCertificateCallback(sslCertificateCallback)
.setConfigTimeout(configuration.getTimeout())
.setConfigTimeout(getConfiguration().getTimeout())
.excludeSSLCipher(exludeSSLCipherRegex)
.client();
return getConnection(clientId, username, password, serverUrl, httpClient);
}

protected IOpenShiftConfiguration getConfiguration() throws OpenShiftException {
if (this.configuration == null) {
this.configuration = createConfiguration();
}
return this.configuration;
}

protected IOpenShiftConfiguration createConfiguration() throws OpenShiftException {
try {
return new OpenShiftConfiguration();
} catch (IOException e) {
throw new OpenShiftException(e, "Failed to establish connection for user ''{0}}''", username);
throw new OpenShiftException(e, "Failed to load OpenShift configuration file.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Red Hat, Inc.
* Copyright (c) 2011-2014 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand Down Expand Up @@ -33,26 +33,42 @@ public abstract class AbstractOpenshiftConfiguration implements IOpenShiftConfig
protected static final String KEY_LIBRA_SERVER = "libra_server";
protected static final String KEY_LIBRA_DOMAIN = "libra_domain";


protected static final String KEY_PASSWORD = "rhpassword";
protected static final String KEY_CLIENT_ID = "client_id";

protected static final String KEY_TIMEOUT = "timeout";
protected static final String DEFAULT_OPENSHIFT_TIMEOUT = "180000"; //3 minutes
protected static final String DEFAULT_OPENSHIFT_TIMEOUT = "180000"; // 3mins

protected static final String KEY_DISABLE_BAD_SSL_CIPHERS = "disable_bad_sslciphers";

private static final Pattern QUOTED_REGEX = Pattern.compile("['\"]*([^'\"]+)['\"]*");
private static final char SINGLEQUOTE = '\'';

private static final String SYSPROPERTY_PROXY_PORT = "proxyPort";
private static final String SYSPROPERTY_PROXY_HOST = "proxyHost";
private static final String SYSPROPERTY_PROXY_SET = "proxySet";

private Properties properties;
private File file;

// TODO: implement

private boolean doSSLChecks = false;

public enum ConfigurationOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this really need to be public api ?

YES, NO, AUTO;

private static ConfigurationOptions safeValueOf(String string) {
if (string == null) {
return NO;
}

try {
return valueOf(string.toUpperCase());
} catch (IllegalArgumentException e) {
return NO;
}
}
}

protected AbstractOpenshiftConfiguration() throws FileNotFoundException, IOException {
this(null, null);
}
Expand Down Expand Up @@ -164,34 +180,45 @@ protected String removeQuotes(String value) {
return value;
}
}

public String getPassword() {
return properties.getProperty(KEY_PASSWORD);
}

public String getClientId() {
return properties.getProperty(KEY_CLIENT_ID);
}

public ConfigurationOptions getDisableBadSSLCiphers() {
return ConfigurationOptions.safeValueOf(
removeQuotes(properties.getProperty(KEY_DISABLE_BAD_SSL_CIPHERS)));
}

public void setDisableBadSSLCiphers(ConfigurationOptions option) {
properties.setProperty(KEY_DISABLE_BAD_SSL_CIPHERS, option.toString());
}

public void setEnableSSLCertChecks(boolean doSSLChecks) {
this.doSSLChecks = doSSLChecks;
}

public boolean getProxySet() {
String set = properties.getProperty(SYSPROPERTY_PROXY_SET);

if (set != null)
return Boolean.parseBoolean(removeQuotes(set));
else
return false;
return toBoolean(removeQuotes(properties.getProperty(SYSPROPERTY_PROXY_SET)));
}

public String getProxyHost() {
return removeQuotes(properties.getProperty(SYSPROPERTY_PROXY_HOST));
}

public String getProxyPort() {
return removeQuotes(properties.getProperty(SYSPROPERTY_PROXY_PORT));
}

private boolean toBoolean(String string) {
if (string != null) {
return Boolean.parseBoolean(string);
} else {
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Red Hat, Inc.
* Copyright (c) 2011-2014 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand All @@ -14,7 +14,6 @@
import java.io.IOException;
import java.util.Properties;

import com.openshift.client.IHttpClient;
import com.openshift.client.OpenShiftException;

/**
Expand All @@ -36,6 +35,7 @@ protected Properties getProperties(File file, Properties defaultProperties) {
properties.put(KEY_LIBRA_SERVER, LIBRA_SERVER);
properties.put(KEY_LIBRA_DOMAIN, LIBRA_DOMAIN);
properties.put(KEY_TIMEOUT, DEFAULT_OPENSHIFT_TIMEOUT);
properties.put(KEY_DISABLE_BAD_SSL_CIPHERS, ConfigurationOptions.NO.toString());
return properties;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2011 Red Hat, Inc.
* Copyright (c) 2011-2014 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is made available under the terms of the
* Eclipse Public License v1.0 which accompanies this distribution,
Expand All @@ -12,25 +12,31 @@

import java.util.Properties;

import com.openshift.client.configuration.AbstractOpenshiftConfiguration.ConfigurationOptions;

/**
* @author André Dietisheim
* @author Corey Daley
*/
public interface IOpenShiftConfiguration {

public abstract String getRhlogin();
public String getRhlogin();

public abstract void setRhlogin(String rhlogin);
public void setRhlogin(String rhlogin);

public abstract String getLibraServer();
public String getLibraServer();

public abstract void setLibraServer(String libraServer);
public void setLibraServer(String libraServer);

public abstract String getLibraDomain();
public String getLibraDomain();

public Integer getTimeout();

public abstract void setLibraDomain(String libraDomain);
public void setLibraDomain(String libraDomain);

public ConfigurationOptions getDisableBadSSLCiphers();

public void setDisableBadSSLCiphers(ConfigurationOptions option);

public Properties getProperties();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected Properties getProperties(File file, Properties defaultProperties) {
copySystemProperty(KEY_PASSWORD, properties);
copySystemProperty(KEY_CLIENT_ID, properties);
copySystemProperty(KEY_OPENSHIFT_TIMEOUT, properties);
copySystemProperty(KEY_DISABLE_BAD_SSL_CIPHERS, properties);
return properties;
}

Expand Down
Loading