use of javax.net.ssl.SSLHandshakeException in project cloudstack by apache.
the class ElastistorUtil method getElastistorRestClient.
/**
* This intializes a new jersey restclient for http call with elasticenter
*/
public static ElastiCenterClient getElastistorRestClient() {
ElastiCenterClient restclient = null;
try {
String ip = getConfigurationDao().getValue("cloudbyte.management.ip");
String apikey = getConfigurationDao().getValue("cloudbyte.management.apikey");
if (ip == null) {
throw new CloudRuntimeException("set the value of cloudbyte.management.ip in global settings");
}
if (apikey == null) {
throw new CloudRuntimeException("set the value of cloudbyte.management.apikey in global settings");
}
restclient = new ElastiCenterClient(ip, apikey);
} catch (InvalidCredentialsException e) {
throw new CloudRuntimeException("InvalidCredentialsException:" + e.getMessage(), e);
} catch (InvalidParameterException e) {
throw new CloudRuntimeException("InvalidParameterException:" + e.getMessage(), e);
} catch (SSLHandshakeException e) {
throw new CloudRuntimeException("SSLHandshakeException:" + e.getMessage(), e);
} catch (ServiceUnavailableException e) {
throw new CloudRuntimeException("ServiceUnavailableException:" + e.getMessage(), e);
}
return restclient;
}
use of javax.net.ssl.SSLHandshakeException in project geode by apache.
the class LauncherLifecycleCommands method doAutoConnect.
private boolean doAutoConnect(final String locatorHostname, final int locatorPort, final String gemfirePropertiesPathname, final String gemfireSecurityPropertiesPathname, final InfoResultData infoResultData) {
boolean connectSuccess = false;
boolean jmxManagerAuthEnabled = false;
boolean jmxManagerSslEnabled = false;
Map<String, String> configurationProperties = loadConfigurationProperties(gemfireSecurityPropertiesPathname, loadConfigurationProperties(gemfirePropertiesPathname));
Map<String, String> locatorConfigurationProperties = new HashMap<>(configurationProperties);
String responseFailureMessage = null;
for (int attempts = 0; (attempts < 10 && !connectSuccess); attempts++) {
try {
ConnectToLocatorResult connectToLocatorResult = ShellCommands.connectToLocator(locatorHostname, locatorPort, ShellCommands.getConnectLocatorTimeoutInMS() / 4, locatorConfigurationProperties);
ConnectionEndpoint memberEndpoint = connectToLocatorResult.getMemberEndpoint();
jmxManagerSslEnabled = connectToLocatorResult.isJmxManagerSslEnabled();
if (!jmxManagerSslEnabled) {
configurationProperties.clear();
}
getGfsh().setOperationInvoker(new JmxOperationInvoker(memberEndpoint.getHost(), memberEndpoint.getPort(), null, null, configurationProperties, null));
String shellAndLogMessage = CliStrings.format(CliStrings.CONNECT__MSG__SUCCESS, "JMX Manager " + memberEndpoint.toString(false));
infoResultData.addLine("\n");
infoResultData.addLine(shellAndLogMessage);
getGfsh().logToFile(shellAndLogMessage, null);
connectSuccess = true;
responseFailureMessage = null;
} catch (IllegalStateException unexpected) {
if (CauseFinder.indexOfCause(unexpected, ClassCastException.class, false) != -1) {
responseFailureMessage = "The Locator might require SSL Configuration.";
}
} catch (SecurityException ignore) {
getGfsh().logToFile(ignore.getMessage(), ignore);
jmxManagerAuthEnabled = true;
// no need to continue after SecurityException
break;
} catch (AuthenticationFailedException ignore) {
getGfsh().logToFile(ignore.getMessage(), ignore);
jmxManagerAuthEnabled = true;
// no need to continue after AuthenticationFailedException
break;
} catch (SSLException ignore) {
if (ignore instanceof SSLHandshakeException) {
// try to connect again without SSL since the SSL handshake failed implying a plain text
// connection...
locatorConfigurationProperties.clear();
} else {
// another type of SSL error occurred (possibly a configuration issue); pass the buck...
getGfsh().logToFile(ignore.getMessage(), ignore);
responseFailureMessage = "Check your SSL configuration and try again.";
break;
}
} catch (Exception ignore) {
getGfsh().logToFile(ignore.getMessage(), ignore);
responseFailureMessage = "Failed to connect; unknown cause: " + ignore.getMessage();
}
}
if (!connectSuccess) {
doOnConnectionFailure(locatorHostname, locatorPort, jmxManagerAuthEnabled, jmxManagerSslEnabled, infoResultData);
}
if (StringUtils.isNotBlank(responseFailureMessage)) {
infoResultData.addLine("\n");
infoResultData.addLine(responseFailureMessage);
}
return connectSuccess;
}
use of javax.net.ssl.SSLHandshakeException in project wildfly by wildfly.
the class AbstractCertificateLoginModuleTestCase method testLoginWithCertificate.
/**
* Testing access to HTTPS connector which have configured truststore with
* trusted certificates. Client with trusted certificate is allowed to
* access both secured/unsecured resource. Client with untrusted certificate
* can only access unprotected resources.
*
* @throws Exception
*/
public void testLoginWithCertificate(String appName) throws Exception {
Assume.assumeFalse(SystemUtils.IS_JAVA_1_6 && SystemUtils.JAVA_VENDOR.toUpperCase(Locale.ENGLISH).contains("IBM"));
final URL printPrincipalUrl = getServletUrl(HTTPS_PORT, appName, PrincipalPrintingServlet.SERVLET_PATH);
final URL securedUrl = getServletUrl(HTTPS_PORT, appName, SECURED_SERVLET_WITH_SESSION);
final URL unsecuredUrl = getServletUrl(HTTPS_PORT, appName, SimpleServlet.SERVLET_PATH);
final HttpClient httpClient = getHttpsClient(CLIENT_KEYSTORE_FILE);
final HttpClient httpClientUntrusted = getHttpsClient(UNTRUSTED_KEYSTORE_FILE);
try {
makeCallWithHttpClient(printPrincipalUrl, httpClient, HttpServletResponse.SC_FORBIDDEN);
String responseBody = makeCallWithHttpClient(securedUrl, httpClient, HttpServletResponse.SC_OK);
assertEquals("Secured page was not reached", SimpleSecuredServlet.RESPONSE_BODY, responseBody);
String principal = makeCallWithHttpClient(printPrincipalUrl, httpClient, HttpServletResponse.SC_OK);
assertEquals("Unexpected principal", "cn=client", principal.toLowerCase());
responseBody = makeCallWithHttpClient(unsecuredUrl, httpClientUntrusted, HttpServletResponse.SC_OK);
assertEquals("Secured page was not reached", SimpleServlet.RESPONSE_BODY, responseBody);
try {
makeCallWithHttpClient(securedUrl, httpClientUntrusted, HttpServletResponse.SC_FORBIDDEN);
} catch (SSLHandshakeException e) {
// OK
} catch (java.net.SocketException se) {
// OK - on windows usually fails with this one
}
} finally {
httpClient.getConnectionManager().shutdown();
httpClientUntrusted.getConnectionManager().shutdown();
}
}
use of javax.net.ssl.SSLHandshakeException in project wildfly by wildfly.
the class HTTPSWebConnectorTestCase method testVerifyingConnector.
/**
* @test.tsfi tsfi.keystore.file
* @test.tsfi tsfi.truststore.file
* @test.objective Testing default HTTPs connector with verify-client attribute set to "true". The CLIENT-CERT
* authentication (BaseCertLoginModule) is configured for this test. Trusted client is allowed to access
* both secured/unsecured resource. Untrusted client is not allowed to access anything.
* @test.expectedResult Trusted client has access to protected and unprotected resources. Untrusted client can't access
* anything.
* @throws Exception
*/
@Test
@InSequence(1)
public void testVerifyingConnector() throws Exception {
final HttpClient httpClient = getHttpClient(CLIENT_KEYSTORE_FILE);
final HttpClient httpClientUntrusted = getHttpClient(UNTRUSTED_KEYSTORE_FILE);
try {
final URL printPrincipalUrl = getServletUrl(HTTPS_PORT_VERIFY_TRUE, PrincipalPrintingServlet.SERVLET_PATH);
final URL securedUrl = getServletUrl(HTTPS_PORT_VERIFY_TRUE, SECURED_SERVLET_WITH_SESSION);
final URL unsecuredUrl = getServletUrl(HTTPS_PORT_VERIFY_TRUE, SimpleServlet.SERVLET_PATH);
String principal = makeCallWithHttpClient(printPrincipalUrl, httpClient, HttpServletResponse.SC_OK);
assertEquals("Unexpected principal", "cn=client", principal.toLowerCase());
String responseBody = makeCallWithHttpClient(securedUrl, httpClient, HttpServletResponse.SC_OK);
assertEquals("Secured page was not reached", SimpleSecuredServlet.RESPONSE_BODY, responseBody);
try {
makeCallWithHttpClient(unsecuredUrl, httpClientUntrusted, HttpServletResponse.SC_FORBIDDEN);
fail("Untrusted client should not be authenticated.");
} catch (SSLHandshakeException | SSLPeerUnverifiedException | SocketException e) {
//depending on the OS and the version of HTTP client in use any one of these exceptions may be thrown
//in particular the SocketException gets thrown on Windows
// OK
}
try {
makeCallWithHttpClient(printPrincipalUrl, httpClientUntrusted, HttpServletResponse.SC_FORBIDDEN);
fail("Untrusted client should not be authenticated.");
} catch (SSLHandshakeException | SSLPeerUnverifiedException | SocketException e) {
// OK
}
try {
makeCallWithHttpClient(securedUrl, httpClientUntrusted, HttpServletResponse.SC_FORBIDDEN);
fail("Untrusted client should not be authenticated.");
} catch (SSLHandshakeException | SSLPeerUnverifiedException | SocketException e) {
// OK
}
} finally {
httpClient.getConnectionManager().shutdown();
httpClientUntrusted.getConnectionManager().shutdown();
}
}
use of javax.net.ssl.SSLHandshakeException in project wildfly by wildfly.
the class HTTPSWebConnectorTestCase method testNonVerifyingConnector.
/**
* @test.tsfi tsfi.keystore.file
* @test.tsfi tsfi.truststore.file
* @test.objective Testing default HTTPs connector with verify-client attribute set to "false". The CLIENT-CERT
* authentication (BaseCertLoginModule) is configured for this test. Trusted client is allowed to access
* both secured/unsecured resource. Untrusted client can only access unprotected resources.
* @test.expectedResult Trusted client has access to protected and unprotected resources. Untrusted client has only access
* to unprotected resources.
* @throws Exception
*/
@Test
@InSequence(1)
public void testNonVerifyingConnector() throws Exception {
Assume.assumeFalse(SystemUtils.IS_JAVA_1_6 && SystemUtils.JAVA_VENDOR.toUpperCase(Locale.ENGLISH).contains("IBM"));
final URL printPrincipalUrl = getServletUrl(HTTPS_PORT_VERIFY_FALSE, PrincipalPrintingServlet.SERVLET_PATH);
final URL securedUrl = getServletUrl(HTTPS_PORT_VERIFY_FALSE, SECURED_SERVLET_WITH_SESSION);
final URL unsecuredUrl = getServletUrl(HTTPS_PORT_VERIFY_FALSE, SimpleServlet.SERVLET_PATH);
final HttpClient httpClient = getHttpClient(CLIENT_KEYSTORE_FILE);
final HttpClient httpClientUntrusted = getHttpClient(UNTRUSTED_KEYSTORE_FILE);
try {
makeCallWithHttpClient(printPrincipalUrl, httpClient, HttpServletResponse.SC_FORBIDDEN);
String responseBody = makeCallWithHttpClient(securedUrl, httpClient, HttpServletResponse.SC_OK);
assertEquals("Secured page was not reached", SimpleSecuredServlet.RESPONSE_BODY, responseBody);
String principal = makeCallWithHttpClient(printPrincipalUrl, httpClient, HttpServletResponse.SC_OK);
assertEquals("Unexpected principal", "cn=client", principal.toLowerCase());
responseBody = makeCallWithHttpClient(unsecuredUrl, httpClientUntrusted, HttpServletResponse.SC_OK);
assertEquals("Secured page was not reached", SimpleServlet.RESPONSE_BODY, responseBody);
try {
makeCallWithHttpClient(securedUrl, httpClientUntrusted, HttpServletResponse.SC_FORBIDDEN);
} catch (SSLHandshakeException e) {
// OK
} catch (java.net.SocketException se) {
// OK - on windows usually fails with this one
}
} finally {
httpClient.getConnectionManager().shutdown();
httpClientUntrusted.getConnectionManager().shutdown();
}
}
Aggregations