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