|
|
|
@ -29,6 +29,7 @@ import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.wso2.carbon.analytics.stream.persistence.stub.EventStreamPersistenceAdminServiceStub;
|
|
|
|
|
import org.wso2.carbon.apimgt.integration.client.service.IntegrationClientService;
|
|
|
|
|
import org.wso2.carbon.base.ServerConfiguration;
|
|
|
|
|
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
|
|
|
|
|
import org.wso2.carbon.context.CarbonContext;
|
|
|
|
@ -128,6 +129,8 @@ public class DeviceMgtAPIUtils {
|
|
|
|
|
private static KeyStore trustStore;
|
|
|
|
|
private static char[] keyStorePassword;
|
|
|
|
|
|
|
|
|
|
private static IntegrationClientService integrationClientService;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password");
|
|
|
|
|
String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty(
|
|
|
|
@ -297,6 +300,23 @@ public class DeviceMgtAPIUtils {
|
|
|
|
|
return realmService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IntegrationClientService getIntegrationClientService() {
|
|
|
|
|
if (integrationClientService == null) {
|
|
|
|
|
synchronized (DeviceMgtAPIUtils.class) {
|
|
|
|
|
if (integrationClientService == null) {
|
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
|
integrationClientService = (IntegrationClientService) ctx.getOSGiService(IntegrationClientService.class, null);
|
|
|
|
|
if (integrationClientService == null) {
|
|
|
|
|
String msg = "IntegrationClientService is not initialized";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new IllegalStateException(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return integrationClientService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static RegistryService getRegistryService() {
|
|
|
|
|
RegistryService registryService;
|
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
@ -459,7 +479,7 @@ public class DeviceMgtAPIUtils {
|
|
|
|
|
return realmService.getTenantManager().getTenantId(tenantDomain);
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
throw new DeviceManagementException("Error occured while trying to " +
|
|
|
|
|
"obtain tenant id of currently logged in user");
|
|
|
|
|
"obtain tenant id of currently logged in user");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -513,8 +533,8 @@ public class DeviceMgtAPIUtils {
|
|
|
|
|
streamOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
|
|
|
|
|
streamOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
|
|
|
|
|
, new Protocol(DEFAULT_HTTP_PROTOCOL
|
|
|
|
|
, (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
|
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
, (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
|
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
eventStreamAdminServiceStub._getServiceClient().setOptions(streamOptions);
|
|
|
|
|
return eventStreamAdminServiceStub;
|
|
|
|
|
}
|
|
|
|
@ -544,8 +564,8 @@ public class DeviceMgtAPIUtils {
|
|
|
|
|
eventReciverOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
|
|
|
|
|
eventReciverOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
|
|
|
|
|
, new Protocol(DEFAULT_HTTP_PROTOCOL
|
|
|
|
|
, (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
|
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
, (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
|
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
|
|
|
|
|
receiverAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
|
|
|
|
|
return receiverAdminServiceStub;
|
|
|
|
@ -576,8 +596,8 @@ public class DeviceMgtAPIUtils {
|
|
|
|
|
eventReciverOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
|
|
|
|
|
eventReciverOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
|
|
|
|
|
, new Protocol(DEFAULT_HTTP_PROTOCOL
|
|
|
|
|
, (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
|
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
, (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
|
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
eventPublisherAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
|
|
|
|
|
return eventPublisherAdminServiceStub;
|
|
|
|
|
}
|
|
|
|
@ -608,8 +628,8 @@ public class DeviceMgtAPIUtils {
|
|
|
|
|
eventReciverOptions.setProperty(HTTPConstants.HTTP_HEADERS, list);
|
|
|
|
|
eventReciverOptions.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER
|
|
|
|
|
, new Protocol(DEFAULT_HTTP_PROTOCOL
|
|
|
|
|
, (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
|
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
, (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslContext)
|
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
|
|
|
|
|
eventStreamPersistenceAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
|
|
|
|
|
return eventStreamPersistenceAdminServiceStub;
|
|
|
|
@ -617,6 +637,7 @@ public class DeviceMgtAPIUtils {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This method is used to create the Cache that holds the event definition of the device type..
|
|
|
|
|
*
|
|
|
|
|
* @return Cachemanager
|
|
|
|
|
*/
|
|
|
|
|
public static synchronized Cache<String, EventAttributeList> getDynamicEventCache() {
|
|
|
|
@ -669,7 +690,7 @@ public class DeviceMgtAPIUtils {
|
|
|
|
|
* Initializes the SSL Context
|
|
|
|
|
*/
|
|
|
|
|
private static void initSSLConnection() throws NoSuchAlgorithmException, UnrecoverableKeyException,
|
|
|
|
|
KeyStoreException, KeyManagementException {
|
|
|
|
|
KeyStoreException, KeyManagementException {
|
|
|
|
|
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KEY_MANAGER_TYPE);
|
|
|
|
|
keyManagerFactory.init(keyStore, keyStorePassword);
|
|
|
|
|
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TRUST_MANAGER_TYPE);
|
|
|
|
|