Skip to content

Commit

Permalink
Merge pull request #1 from andrerod/multimodule_2
Browse files Browse the repository at this point in the history
Factoring out service runtime
  • Loading branch information
André Rodrigues committed Dec 13, 2013
2 parents e042ce4 + 49403a6 commit 782b8fa
Show file tree
Hide file tree
Showing 1,119 changed files with 102,549 additions and 2,078 deletions.
5 changes: 5 additions & 0 deletions microsoft-azure-api-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
</developers>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,10 @@
* limitations under the License.
*/

package com.microsoft.windowsazure.services.management.models;
package com.microsoft.windowsazure;

import org.apache.http.impl.client.CloseableHttpClient;

/**
* The base result class for all the result of service management operation.
*
*/
public class DeleteAffinityGroupResult extends OperationResult {

public DeleteAffinityGroupResult(int statusCode, String requestId) {
super(statusCode, requestId);
}

public AffinityGroupInfo getValue() {
// TODO Auto-generated method stub
return null;
}

public abstract class CloudCredentials {
public abstract CloseableHttpClient initializeClient();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.microsoft.windowsazure.management;

import java.io.IOException;
import java.security.GeneralSecurityException;
import javax.net.ssl.SSLContext;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

public class CertificateCloudCredentials extends SubscriptionCloudCredentials {
private String _subscriptionId;
private KeyStoreCredential _keyStoreCredential;

public CertificateCloudCredentials(String subscriptionId)
{
this._subscriptionId = subscriptionId;
}

public CertificateCloudCredentials(String subscriptionId, KeyStoreCredential keyStoreCredential)
{
this._subscriptionId = subscriptionId;
this._keyStoreCredential = keyStoreCredential;
}

@Override
public String getSubscriptionId()
{
return _subscriptionId;
}

public void setSubscriptionId(String subscriptionId)
{
_subscriptionId = subscriptionId;
}

public KeyStoreCredential getKeyStoreCredential()
{
return _keyStoreCredential;
}

public void setKeyStoreCredential(KeyStoreCredential keyStoreCredential)
{
_keyStoreCredential = keyStoreCredential;
}

@Override
public CloseableHttpClient initializeClient()
{
try {
SSLContext sslcontext = SSLContextFactory.create(this.getKeyStoreCredential());

return HttpClients.custom()
.setSSLSocketFactory(new SSLConnectionSocketFactory(sslcontext))
.build();
}
catch (IOException e)
{
return null;
}
catch (GeneralSecurityException e)
{
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package com.microsoft.windowsazure.services.management.implementation;
package com.microsoft.windowsazure.management;

import java.io.IOException;

Expand Down Expand Up @@ -50,6 +50,10 @@ public KeyStoreCredential(String keyStorePath, String keyStorePassword, KeyStore
this.keyStoreType = keyStoreType;
}

public KeyStoreCredential(String keyStorePath, String keyStorePassword) throws IOException {
this(keyStorePath, keyStorePassword, KeyStoreType.jks);
}

/**
* Gets the type of the key store.
*
Expand All @@ -76,5 +80,4 @@ public String getKeystorePassword() {
public String getKeyStorePath() {
return this.keyStorePath;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* limitations under the License.
*/

package com.microsoft.windowsazure.services.management.implementation;
package com.microsoft.windowsazure.management;

/**
* The Enum representing the type of the KeyStore.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.microsoft.windowsazure.services.management;
package com.microsoft.windowsazure.management;

import com.microsoft.windowsazure.services.core.Configuration;

Expand All @@ -26,29 +26,31 @@ public class ManagementConfiguration {
* Defines the path of the keystore.
*
*/
public final static String KEYSTORE_PATH = "management.keystore.path";
public final static String KEYSTORE_PATH = "AZURE_MANAGEMENT_KEYSTORE_PATH";

/**
* Defines the password of the keystore.
*
*/
public final static String KEYSTORE_PASSWORD = "management.keystore.password";
public final static String KEYSTORE_PASSWORD = "AZURE_MANAGEMENT_KEYSTORE_PASSWORD";

/**
* Defines the type of the keystore.
*/
public static final String KEYSTORE_TYPE = "management.keystore.type";
public static final String KEYSTORE_TYPE = "AZURE_MANAGEMENT_KEYSTORE_TYPE";

/**
* Defines the URI of service management.
*
*/
public final static String URI = "management.uri";
public final static String URI = "AZURE_MANAGEMENT_URI";

/**
* Defines the subscription ID of the Windows Azure account.
*/
public static final String SUBSCRIPTION_ID = "management.subscription.id";
public static final String SUBSCRIPTION_ID = "AZURE_SUBSCRIPTION_ID";

public static final String SUBSCRIPTION_CLOUD_CREDENTIALS = "AZURE_SUBSCRIPTION_CLOUD_CREDENTIALS";

/**
* Creates a service management configuration using specified URI, and subscription ID.
Expand Down Expand Up @@ -97,8 +99,10 @@ else if (profile.length() != 0 && !profile.endsWith(".")) {
configuration.setProperty(profile + SUBSCRIPTION_ID, subscriptionId);
configuration.setProperty(profile + KEYSTORE_PATH, keyStoreLocation);
configuration.setProperty(profile + KEYSTORE_PASSWORD, keyStorePassword);


configuration.setProperty(profile + SUBSCRIPTION_CLOUD_CREDENTIALS,
new CertificateCloudCredentials(subscriptionId));

return configuration;
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.microsoft.windowsazure.management;

public class OperationResponse {
private int _httpStatusCode;

/**
* Gets the HTTP status code for the request.
*/
public int getStatusCode() { return this._httpStatusCode; }

/**
* Sets the HTTP status code for the request.
*/
public void setStatusCode(int httpStatusCode) { this._httpStatusCode = httpStatusCode; }

private String _requestId;

/**
* Gets the request identifier.
*/
public String getRequestId() { return this._requestId; }

/**
* Sets the request identifier.
*/
public void setRequestId(String requestId) { this._requestId = requestId; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
* limitations under the License.
*/

package com.microsoft.windowsazure.services.management.implementation;
package com.microsoft.windowsazure.management;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.SecureRandom;

import javax.net.ssl.HttpsURLConnection;
import java.security.cert.X509Certificate;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

/**
* A factory for creating SSLContext instance.
Expand All @@ -43,7 +46,7 @@ public class SSLContextFactory {
* @throws IOException
* when an I/O exception has occurred.
*/
public static SSLContext createSSLContext(KeyStoreCredential keyStoreCredential) throws GeneralSecurityException,
public static SSLContext create(KeyStoreCredential keyStoreCredential) throws GeneralSecurityException,
IOException {
if (keyStoreCredential == null) {
throw new IllegalArgumentException("KeyStoreCredential cannot be null.");
Expand Down Expand Up @@ -78,11 +81,26 @@ public static SSLContext create(String keyStorePath, String keyStorePassword, Ke
throw new IllegalArgumentException("The type of the keystore cannot be null");
}

InputStream keyStoreInputStream = new FileInputStream(keyStorePath);
InputStream keyStoreInputStream = new FileInputStream(new File(keyStorePath));
KeyManager[] keyManagers = getKeyManagers(keyStoreInputStream, keyStorePassword, keyStoreType);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagers, null, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
sslContext.init(keyManagers, new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
System.out.println("getAcceptedIssuers =============");
return null;
}

public void checkClientTrusted(X509Certificate[] certs,
String authType) {
System.out.println("checkClientTrusted =============");
}

public void checkServerTrusted(X509Certificate[] certs,
String authType) {
System.out.println("checkServerTrusted =============");
}
} }, new SecureRandom());

keyStoreInputStream.close();
return sslContext;
}
Expand All @@ -107,7 +125,8 @@ private static KeyManager[] getKeyManagers(InputStream keyStoreInputStream, Stri

KeyStore keyStore = KeyStore.getInstance(keyStoreType.name());
keyStore.load(keyStoreInputStream, keyStorePassword.toCharArray());
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
String defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm();
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(defaultAlgorithm);
keyManagerFactory.init(keyStore, keyStorePassword.toCharArray());

return keyManagerFactory.getKeyManagers();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright Microsoft Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.microsoft.windowsazure.management;

import com.microsoft.windowsazure.CloudCredentials;

public abstract class SubscriptionCloudCredentials extends CloudCredentials {
/*
* When you create a Windows Azure subscription, it is uniquely
* identified by a subscription ID. The subscription ID forms part of
* the URI for every call that you make to the Service Management API.
*/
public abstract String getSubscriptionId();
}
Loading

0 comments on commit 782b8fa

Please sign in to comment.