moved default input and output configurations to global properties

revert-dabc3590
ayyoob 8 years ago
parent 06d646c87a
commit 0abbf55714

@ -69,9 +69,14 @@ public class HTTPMessageServlet extends HttpServlet {
this.tenantId = tenantId; this.tenantId = tenantId;
this.exposedTransports = eventAdapterConfiguration.getProperties().get( this.exposedTransports = eventAdapterConfiguration.getProperties().get(
HTTPEventAdapterConstants.EXPOSED_TRANSPORTS); HTTPEventAdapterConstants.EXPOSED_TRANSPORTS);
String globalContentValidator = globalProperties.get(HTTPEventAdapterConstants.
ADAPTER_CONF_CONTENT_VALIDATOR_TYPE);
String contentValidatorType = eventAdapterConfiguration.getProperties().get( String contentValidatorType = eventAdapterConfiguration.getProperties().get(
HTTPEventAdapterConstants.ADAPTER_CONF_CONTENT_VALIDATOR_TYPE); HTTPEventAdapterConstants.ADAPTER_CONF_CONTENT_VALIDATOR_TYPE);
if (globalContentValidator != null && !globalContentValidator.isEmpty() ) {
contentValidatorType = globalContentValidator;
}
if (contentValidatorType == null || HTTPEventAdapterConstants.DEFAULT.equals(contentValidatorType)) { if (contentValidatorType == null || HTTPEventAdapterConstants.DEFAULT.equals(contentValidatorType)) {
contentValidator = InputAdapterServiceDataHolder.getInputAdapterExtensionService() contentValidator = InputAdapterServiceDataHolder.getInputAdapterExtensionService()
.getDefaultContentValidator(); .getDefaultContentValidator();

@ -191,7 +191,11 @@ public class MQTTAdapterListener implements MqttCallback, Runnable {
} }
} }
} }
try {
mqttClient.connect(connectionOptions); mqttClient.connect(connectionOptions);
} catch (MqttException e) {
log.error("Broker is unreachable, Waiting.....");
}
mqttClient.subscribe(topic); mqttClient.subscribe(topic);
} }

@ -105,10 +105,18 @@ public class MQTTBrokerConnectionConfiguration {
this.brokerUrl = PropertyUtils.replaceMqttProperty(url); this.brokerUrl = PropertyUtils.replaceMqttProperty(url);
this.dcrUrl = PropertyUtils this.dcrUrl = PropertyUtils
.replaceMqttProperty(globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_DCR_URL)); .replaceMqttProperty(globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_DCR_URL));
this.contentValidatorType = globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_CONTENT_VALIDATOR_TYPE);
if (contentValidatorType == null || contentValidatorType.isEmpty()) {
this.contentValidatorType = eventAdapterConfiguration.getProperties() this.contentValidatorType = eventAdapterConfiguration.getProperties()
.get(MQTTEventAdapterConstants.ADAPTER_CONF_CONTENT_VALIDATOR_TYPE); .get(MQTTEventAdapterConstants.ADAPTER_CONF_CONTENT_VALIDATOR_TYPE);
}
String cleanSession = globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION);
if (cleanSession == null || cleanSession.isEmpty()) {
this.cleanSession = Boolean.parseBoolean(eventAdapterConfiguration.getProperties() this.cleanSession = Boolean.parseBoolean(eventAdapterConfiguration.getProperties()
.get(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION)); .get(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION));
} else {
this.cleanSession = Boolean.parseBoolean(cleanSession);
}
//If global properties are available those will be assigned else constant values will be assigned //If global properties are available those will be assigned else constant values will be assigned
if (globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_KEEP_ALIVE) != null) { if (globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_KEEP_ALIVE) != null) {
keepAlive = Integer.parseInt((globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_KEEP_ALIVE))); keepAlive = Integer.parseInt((globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_KEEP_ALIVE)));

@ -44,10 +44,10 @@ public class MQTTEventAdapter implements OutputEventAdapter {
private Map<String, String> globalProperties; private Map<String, String> globalProperties;
private MQTTAdapterPublisher mqttAdapterPublisher; private MQTTAdapterPublisher mqttAdapterPublisher;
private int connectionKeepAliveInterval; private int connectionKeepAliveInterval;
private String qos;
private static ThreadPoolExecutor threadPoolExecutor; private static ThreadPoolExecutor threadPoolExecutor;
private static final Log log = LogFactory.getLog(MQTTEventAdapter.class); private static final Log log = LogFactory.getLog(MQTTEventAdapter.class);
private int tenantId; private int tenantId;
private MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration;
public MQTTEventAdapter(OutputEventAdapterConfiguration eventAdapterConfiguration, public MQTTEventAdapter(OutputEventAdapterConfiguration eventAdapterConfiguration,
Map<String, String> globalProperties) { Map<String, String> globalProperties) {
@ -117,11 +117,11 @@ public class MQTTEventAdapter implements OutputEventAdapter {
@Override @Override
public void connect() { public void connect() {
MQTTBrokerConnectionConfiguration mqttBrokerConnectionConfiguration = mqttBrokerConnectionConfiguration =
new MQTTBrokerConnectionConfiguration(eventAdapterConfiguration, globalProperties); new MQTTBrokerConnectionConfiguration(eventAdapterConfiguration, globalProperties);
String clientId = eventAdapterConfiguration.getStaticProperties().get( String clientId = eventAdapterConfiguration.getStaticProperties().get(
MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID); MQTTEventAdapterConstants.ADAPTER_CONF_CLIENTID);
qos = eventAdapterConfiguration.getStaticProperties().get(MQTTEventAdapterConstants.ADAPTER_MESSAGE_QOS);
mqttAdapterPublisher = new MQTTAdapterPublisher(mqttBrokerConnectionConfiguration, clientId, tenantId); mqttAdapterPublisher = new MQTTAdapterPublisher(mqttBrokerConnectionConfiguration, clientId, tenantId);
} }
@ -179,11 +179,7 @@ public class MQTTEventAdapter implements OutputEventAdapter {
} }
} }
} }
if (qos == null || qos.trim().isEmpty()) { mqttAdapterPublisher.publish(mqttBrokerConnectionConfiguration.getQos(), message.toString(), topic);
mqttAdapterPublisher.publish(message.toString(), topic);
} else {
mqttAdapterPublisher.publish(Integer.parseInt(qos), message.toString(), topic);
}
} catch (Throwable t) { } catch (Throwable t) {
EventAdapterUtil.logAndDrop(eventAdapterConfiguration.getName(), message, null, t, log, tenantId); EventAdapterUtil.logAndDrop(eventAdapterConfiguration.getName(), message, null, t, log, tenantId);
} }

@ -34,6 +34,7 @@ public class MQTTBrokerConnectionConfiguration {
private boolean cleanSession = true; private boolean cleanSession = true;
private int keepAlive; private int keepAlive;
private boolean globalCredentailSet; private boolean globalCredentailSet;
private int qos;
public String getTokenUrl() { public String getTokenUrl() {
return tokenUrl; return tokenUrl;
@ -75,6 +76,9 @@ public class MQTTBrokerConnectionConfiguration {
return globalCredentailSet; return globalCredentailSet;
} }
public int getQos() {
return qos;
}
public MQTTBrokerConnectionConfiguration(OutputEventAdapterConfiguration eventAdapterConfiguration, public MQTTBrokerConnectionConfiguration(OutputEventAdapterConfiguration eventAdapterConfiguration,
Map<String, String> globalProperties) { Map<String, String> globalProperties) {
adapterName = eventAdapterConfiguration.getName(); adapterName = eventAdapterConfiguration.getName();
@ -98,14 +102,28 @@ public class MQTTBrokerConnectionConfiguration {
if (scopes == null) { if (scopes == null) {
this.scopes = MQTTEventAdapterConstants.EMPTY_STRING; this.scopes = MQTTEventAdapterConstants.EMPTY_STRING;
} }
String cleanSession = globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION);
if (cleanSession == null || cleanSession.isEmpty()) {
this.cleanSession = Boolean.parseBoolean(eventAdapterConfiguration.getStaticProperties() this.cleanSession = Boolean.parseBoolean(eventAdapterConfiguration.getStaticProperties()
.get(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION)); .get(MQTTEventAdapterConstants.ADAPTER_CONF_CLEAN_SESSION));
} else {
this.cleanSession = Boolean.parseBoolean(cleanSession);
}
//If global properties are available those will be assigned else constant values will be assigned //If global properties are available those will be assigned else constant values will be assigned
if (globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_KEEP_ALIVE) != null) { if (globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_KEEP_ALIVE) != null) {
keepAlive = Integer.parseInt((globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_KEEP_ALIVE))); keepAlive = Integer.parseInt((globalProperties.get(MQTTEventAdapterConstants.ADAPTER_CONF_KEEP_ALIVE)));
} else { } else {
keepAlive = MQTTEventAdapterConstants.ADAPTER_CONF_DEFAULT_KEEP_ALIVE; keepAlive = MQTTEventAdapterConstants.ADAPTER_CONF_DEFAULT_KEEP_ALIVE;
} }
String qosVal = globalProperties.get(MQTTEventAdapterConstants.ADAPTER_MESSAGE_QOS);
if (qosVal == null || qosVal.isEmpty()) {
this.qos = Integer.parseInt(qosVal);
} else {
qosVal = eventAdapterConfiguration.getStaticProperties().get(MQTTEventAdapterConstants.ADAPTER_MESSAGE_QOS);
this.qos = Integer.parseInt(qosVal);
}
} }
} }

@ -63,23 +63,14 @@ public class DeviceAuthorizer implements Authorizer {
private static DeviceAccessAuthorizationAdminService deviceAccessAuthorizationAdminService; private static DeviceAccessAuthorizationAdminService deviceAccessAuthorizationAdminService;
private static final String CDMF_SERVER_BASE_CONTEXT = "/api/device-mgt/v1.0"; private static final String CDMF_SERVER_BASE_CONTEXT = "/api/device-mgt/v1.0";
private static final String DEVICE_MGT_SERVER_URL = "deviceMgtServerUrl"; private static final String DEVICE_MGT_SERVER_URL = "deviceMgtServerUrl";
private static final String STAT_PERMISSION = "statsPermission";
private static final String DEVICE_ID = "deviceId"; private static final String DEVICE_ID = "deviceId";
private static final String DEVICE_TYPE = "deviceType"; private static final String DEVICE_TYPE = "deviceType";
private static Log log = LogFactory.getLog(DeviceAuthorizer.class); private static Log log = LogFactory.getLog(DeviceAuthorizer.class);
private static List<String> statPermissions;
public DeviceAuthorizer() { public DeviceAuthorizer() {
} }
@Override @Override
public void init(Map<String, String> globalProperties) { public void init(Map<String, String> globalProperties) {
statPermissions = getPermissions(globalProperties);
if (statPermissions != null && !statPermissions.isEmpty()) {
for (String permission : statPermissions) {
PermissionUtil.putPermission(permission);
}
}
try { try {
deviceAccessAuthorizationAdminService = Feign.builder().client(getSSLClient()).logger(new Slf4jLogger()) deviceAccessAuthorizationAdminService = Feign.builder().client(getSSLClient()).logger(new Slf4jLogger())
.logLevel(Logger.Level.FULL).requestInterceptor(new OAuthRequestInterceptor(globalProperties)) .logLevel(Logger.Level.FULL).requestInterceptor(new OAuthRequestInterceptor(globalProperties))
@ -102,9 +93,6 @@ public class DeviceAuthorizer implements Authorizer {
AuthorizationRequest authorizationRequest = new AuthorizationRequest(); AuthorizationRequest authorizationRequest = new AuthorizationRequest();
authorizationRequest.setTenantDomain(authenticationInfo.getTenantDomain()); authorizationRequest.setTenantDomain(authenticationInfo.getTenantDomain());
if (statPermissions != null && !statPermissions.isEmpty()) {
authorizationRequest.setPermissions(statPermissions);
}
authorizationRequest.setUsername(authenticationInfo.getUsername()); authorizationRequest.setUsername(authenticationInfo.getUsername());
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId); deviceIdentifier.setId(deviceId);
@ -137,14 +125,6 @@ public class DeviceAuthorizer implements Authorizer {
return deviceMgtServerUrl; return deviceMgtServerUrl;
} }
private List<String> getPermissions(Map<String, String> properties) {
String stats = properties.get(STAT_PERMISSION);
if (stats != null && !stats.isEmpty()) {
return Arrays.asList(stats.replace("\n", "").split(" "));
}
return null;
}
private static Client getSSLClient() { private static Client getSSLClient() {
return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() { return new Client.Default(getTrustedSSLSocketFactory(), new HostnameVerifier() {
@Override @Override

@ -1,76 +0,0 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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 org.wso2.carbon.device.mgt.output.adapter.websocket.authorization;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.device.mgt.output.adapter.websocket.internal.WebsocketEventAdaptorServiceDataHolder;
import org.wso2.carbon.registry.api.Resource;
import org.wso2.carbon.registry.core.Registry;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import java.util.StringTokenizer;
/**
* Utility class which holds necessary utility methods required for persisting permissions in
* registry.
*/
public class PermissionUtil {
public static final String PERMISSION_PROPERTY_NAME = "name";
private static Log log = LogFactory.getLog(DeviceAuthorizer.class);
public static void putPermission(String permission) {
try {
StringTokenizer tokenizer = new StringTokenizer(permission, "/");
String lastToken = "", currentToken, tempPath;
while (tokenizer.hasMoreTokens()) {
currentToken = tokenizer.nextToken();
tempPath = lastToken + "/" + currentToken;
if (!checkResourceExists(tempPath)) {
createRegistryCollection(tempPath, currentToken);
}
lastToken = tempPath;
}
} catch (org.wso2.carbon.registry.api.RegistryException e) {
log.error("Failed to creation permission in registry" + permission, e);
}
}
public static void createRegistryCollection(String path, String resourceName)
throws org.wso2.carbon.registry.api.RegistryException {
Resource resource = getGovernanceRegistry().newCollection();
resource.addProperty(PERMISSION_PROPERTY_NAME, resourceName);
getGovernanceRegistry().beginTransaction();
getGovernanceRegistry().put(path, resource);
getGovernanceRegistry().commitTransaction();
}
public static boolean checkResourceExists(String path)
throws RegistryException {
return getGovernanceRegistry().resourceExists(path);
}
public static Registry getGovernanceRegistry() throws RegistryException {
return WebsocketEventAdaptorServiceDataHolder.getRegistryService()
.getGovernanceSystemRegistry(MultitenantConstants.SUPER_TENANT_ID);
}
}

@ -28,7 +28,7 @@ import javax.ws.rs.core.MediaType;
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@Path("/admin/authorization") @Path("/admin/authorization/stat")
/** /**
* This interface provided the definition of the device - user access verification service. * This interface provided the definition of the device - user access verification service.
*/ */

Loading…
Cancel
Save