From 401ad2846cd7ca19eaaeacc095acf852c34c6d44 Mon Sep 17 00:00:00 2001 From: GPrathap Date: Tue, 8 Nov 2016 16:19:45 +0530 Subject: [PATCH] removing mb mqtt authorization extension. This has been moved to https://github.com/wso2/carbon-device-mgt-plugins/pull/403 --- .../pom.xml | 100 ------------- .../DeviceAccessBasedMQTTAuthorizer.java | 133 ------------------ .../internal/AuthorizationDataHolder.java | 57 -------- .../AuthorizationServiceComponent.java | 72 ---------- .../components/mb-extensions/pom.xml | 38 ----- .../pom.xml | 80 ----------- .../src/main/resources/build.properties | 19 --- .../src/main/resources/p2.inf | 1 - .../features/mb-extensions-feature/pom.xml | 40 ------ modules/iot-extensions/pom.xml | 40 ------ pom.xml | 1 - 11 files changed, 581 deletions(-) delete mode 100644 modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/pom.xml delete mode 100644 modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java delete mode 100644 modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/internal/AuthorizationDataHolder.java delete mode 100644 modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/internal/AuthorizationServiceComponent.java delete mode 100644 modules/iot-extensions/components/mb-extensions/pom.xml delete mode 100644 modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/pom.xml delete mode 100644 modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/src/main/resources/build.properties delete mode 100644 modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/src/main/resources/p2.inf delete mode 100644 modules/iot-extensions/features/mb-extensions-feature/pom.xml delete mode 100644 modules/iot-extensions/pom.xml diff --git a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/pom.xml b/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/pom.xml deleted file mode 100644 index 6bea07b3..00000000 --- a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - mb-extensions - org.wso2.iot - 1.0.0-SNAPSHOT - ../pom.xml - - - 4.0.0 - org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization - bundle - WSO2 Carbon - Component - MQTT - Authorization Manager - MQTT authorization manager based on Carbon device manager - http://wso2.org - - - - org.wso2.carbon - org.wso2.carbon.utils - - - org.wso2.carbon - org.wso2.carbon.core - - - org.wso2.andes.wso2 - andes - 3.1.2 - - - org.wso2.carbon - org.wso2.carbon.user.api - - - org.wso2.carbon - org.wso2.carbon.user.core - - - - - - - org.apache.felix - maven-scr-plugin - - - org.apache.felix - maven-bundle-plugin - true - - - ${project.artifactId} - ${project.artifactId} - - org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.internal - - - !org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.internal, - org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.* - - - org.apache.log4j, - org.dna.mqtt.moquette.server, - org.wso2.andes.configuration.enums, - org.wso2.andes.mqtt, - org.wso2.carbon.context, - org.apache.commons.logging, - org.osgi.service.component, - org.wso2.carbon.user.core.service, - org.wso2.carbon.user.core.tenant, - org.wso2.carbon.user.api - - - - - - - - - diff --git a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java b/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java deleted file mode 100644 index bd122392..00000000 --- a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/DeviceAccessBasedMQTTAuthorizer.java +++ /dev/null @@ -1,133 +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.andes.extensions.device.mgt.mqtt.authorization; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.dna.mqtt.moquette.server.IAuthorizer; -import org.wso2.andes.configuration.enums.MQTTAuthoriztionPermissionLevel; -import org.wso2.andes.mqtt.MQTTAuthorizationSubject; -import org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.internal.AuthorizationDataHolder; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.user.api.UserRealm; -import org.wso2.carbon.user.api.UserStoreException; - -import java.util.List; - -/** - * Authorize the connecting users against Carbon Permission Model. Intended usage is - * via providing fully qualified class name in broker.xml - *

- * This is just a simple authorization model. For dynamic topics use an implementation based on IAuthorizer - */ -public class DeviceAccessBasedMQTTAuthorizer implements IAuthorizer { - - private static Log logger = LogFactory.getLog(DeviceAccessBasedMQTTAuthorizer.class); - private static final String CONNECTION_PERMISSION = "/permission/admin/device-mgt/user"; - private static final String ADMIN_PERMISSION = "/permission/admin/device-mgt/admin"; - private static final String SCOPE_IDENTIFIER = "scope"; - private static final String UI_EXECUTE = "ui.execute"; - private static final String MQTT_PUBLISHER_SCOPE_IDENTIFIER = "mqtt-publisher"; - private static final String MQTT_SUBSCRIBER_SCOPE_IDENTIFIER = "mqtt-subscriber"; - private static final String DEVICE_MGT_SCOPE_IDENTIFIER = "device-mgt"; - - /** - * {@inheritDoc} Authorize the user against carbon device mgt model. - */ - @Override - public boolean isAuthorizedForTopic(MQTTAuthorizationSubject authorizationSubject, String topic, - MQTTAuthoriztionPermissionLevel permissionLevel) { - - if (isUserAuthorized(authorizationSubject, ADMIN_PERMISSION, UI_EXECUTE)) { - System.out.println("isAuthorizedForTopic - user is auth success !"); - return true; - } - String topics[] = topic.split("/"); - if (topics.length < 3) { - System.out.println("isAuthorizedForTopic topic name invalid"); - return false; - } - String tenantIdFromTopic = topics[0]; - if (!tenantIdFromTopic.equals(authorizationSubject.getTenantDomain())) { - System.out.println("isAuthorizedForTopic tenantID invalid"); - return false; - } - String deviceType = topics[1]; - String deviceId = topics[2]; - Object scopeObject = authorizationSubject.getProperties().get(SCOPE_IDENTIFIER); - - if (!deviceId.isEmpty() && !deviceType.isEmpty() && scopeObject != null) { - List scopes = (List) scopeObject; - String permissionScope = MQTT_PUBLISHER_SCOPE_IDENTIFIER; - if (permissionLevel == MQTTAuthoriztionPermissionLevel.SUBSCRIBE) { - permissionScope = MQTT_SUBSCRIBER_SCOPE_IDENTIFIER; - } - String requiredScope = DEVICE_MGT_SCOPE_IDENTIFIER + ":" + deviceType + ":" + deviceId + ":" - + permissionScope; - for (String scope : scopes) { - if (requiredScope.equals(scope)) { - System.out.println("isAuthorizedForTopic - Pass"); - return true; - } - } - } - System.out.println("isAuthorizedForTopic - Failed"); - return false; - } - - /** - * {@inheritDoc} Authorized the user against carbon device mgt model. - */ - @Override - public boolean isAuthorizedToConnect(MQTTAuthorizationSubject authorizationSubject) { - return isUserAuthorized(authorizationSubject, CONNECTION_PERMISSION, UI_EXECUTE); - } - - /** - * Check whether the client is authorized with the given permission and action. - * - * @param authorizationSubject this contains the client information - * @param permission Carbon permission that requires for the use - * @param action Carbon permission action that requires for the given permission. - * @return boolean - true if user is authorized else return false. - */ - private boolean isUserAuthorized(MQTTAuthorizationSubject authorizationSubject, String permission, String action) { - String username = authorizationSubject.getUsername(); - try { - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( - authorizationSubject.getTenantDomain(), true); - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - UserRealm userRealm = AuthorizationDataHolder.getInstance().getRealmService() - .getTenantUserRealm(tenantId); - if (userRealm != null && userRealm.getAuthorizationManager() != null) { - return userRealm.getAuthorizationManager().isUserAuthorized(username, permission, action); - } - System.out.println("isUserAuthorized failse"); - return false; - } catch (UserStoreException e) { - String errorMsg = String.format("Unable to authorize the user : %s", username); - logger.error(errorMsg, e); - System.out.println("isUserAuthorized failed"); - return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } -} \ No newline at end of file diff --git a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/internal/AuthorizationDataHolder.java b/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/internal/AuthorizationDataHolder.java deleted file mode 100644 index c2d9e967..00000000 --- a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/internal/AuthorizationDataHolder.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2014, 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.andes.extensions.device.mgt.mqtt.authorization.internal; - -import org.wso2.carbon.user.core.service.RealmService; -import org.wso2.carbon.user.core.tenant.TenantManager; - -public class AuthorizationDataHolder { - - private RealmService realmService; - private TenantManager tenantManager; - - private static AuthorizationDataHolder thisInstance = new AuthorizationDataHolder(); - - private AuthorizationDataHolder() {} - - public static AuthorizationDataHolder getInstance() { - return thisInstance; - } - - public RealmService getRealmService() { - return realmService; - } - - public void setRealmService(RealmService realmService) { - this.realmService = realmService; - this.setTenantManager(realmService); - } - - private void setTenantManager(RealmService realmService) { - if (realmService == null) { - throw new IllegalStateException("Realm service is not initialized properly"); - } - this.tenantManager = realmService.getTenantManager(); - } - - public TenantManager getTenantManager() { - return tenantManager; - } - -} diff --git a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/internal/AuthorizationServiceComponent.java b/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/internal/AuthorizationServiceComponent.java deleted file mode 100644 index b0827e1b..00000000 --- a/modules/iot-extensions/components/mb-extensions/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization/src/main/java/org/wso2/carbon/andes/extensions/device/mgt/mqtt/authorization/internal/AuthorizationServiceComponent.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2014, 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.andes.extensions.device.mgt.mqtt.authorization.internal; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.user.core.service.RealmService; - -/** - * @scr.component name="org.wso2.carbon.devicemgt.policy.manager" immediate="true" - * @scr.reference name="user.realmservice.default" - * interface="org.wso2.carbon.user.core.service.RealmService" - * cardinality="1..1" - * policy="dynamic" - * bind="setRealmService" - * unbind="unsetRealmService" - */ -@SuppressWarnings("unused") -public class AuthorizationServiceComponent { - - private static Log log = LogFactory.getLog(AuthorizationServiceComponent.class); - - protected void activate(ComponentContext componentContext) { - } - - @SuppressWarnings("unused") - protected void deactivate(ComponentContext componentContext) { - } - - - /** - * Sets Realm Service - * - * @param realmService An instance of RealmService - */ - protected void setRealmService(RealmService realmService) { - if (log.isDebugEnabled()) { - log.debug("Setting Realm Service"); - } - AuthorizationDataHolder.getInstance().setRealmService(realmService); - } - - /** - * Unsets Realm Service - * - * @param realmService An instance of RealmService - */ - protected void unsetRealmService(RealmService realmService) { - if (log.isDebugEnabled()) { - log.debug("Unsetting Realm Service"); - } - AuthorizationDataHolder.getInstance().setRealmService(null); - } - -} diff --git a/modules/iot-extensions/components/mb-extensions/pom.xml b/modules/iot-extensions/components/mb-extensions/pom.xml deleted file mode 100644 index 5538ae32..00000000 --- a/modules/iot-extensions/components/mb-extensions/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - org.wso2.iot - iot-extensions - 1.0.0-SNAPSHOT - ../../pom.xml - - - 4.0.0 - mb-extensions - pom - WSO2 Carbon - MB Extension - http://wso2.org - - - org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization - - diff --git a/modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/pom.xml b/modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/pom.xml deleted file mode 100644 index 5b54749e..00000000 --- a/modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/pom.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - mb-extensions-feature - org.wso2.iot - 1.0.0-SNAPSHOT - ../pom.xml - - - 4.0.0 - org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature - pom - WSO2 Carbon - MQTT Authorization Feature - http://wso2.org - This feature contains the bundles required for mqtt authorization - - - - org.wso2.iot - org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization - - - - - - org.wso2.maven - carbon-p2-plugin - ${carbon.p2.plugin.version} - - - 4-p2-feature-generation - package - - p2-feature-gen - - - org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization - ../../etc/feature.properties - - - org.wso2.carbon.p2.category.type:server - org.eclipse.equinox.p2.type.group:true - - - - - org.wso2.iot:org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization:${carbon.iot.device.mgt.version} - - - - org.wso2.carbon.core.server:${carbon.kernel.version} - - - - - - - - - diff --git a/modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/src/main/resources/build.properties b/modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/src/main/resources/build.properties deleted file mode 100644 index ddedd58d..00000000 --- a/modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/src/main/resources/build.properties +++ /dev/null @@ -1,19 +0,0 @@ -# -# Copyright (c) 2005-2014, 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. -# - -custom = true diff --git a/modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/src/main/resources/p2.inf b/modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/src/main/resources/p2.inf deleted file mode 100644 index 7ab37b9d..00000000 --- a/modules/iot-extensions/features/mb-extensions-feature/org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature/src/main/resources/p2.inf +++ /dev/null @@ -1 +0,0 @@ -instructions.configure = \ \ No newline at end of file diff --git a/modules/iot-extensions/features/mb-extensions-feature/pom.xml b/modules/iot-extensions/features/mb-extensions-feature/pom.xml deleted file mode 100644 index d4e4f32e..00000000 --- a/modules/iot-extensions/features/mb-extensions-feature/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - org.wso2.iot - iot-extensions - 1.0.0-SNAPSHOT - ../../pom.xml - - - 4.0.0 - mb-extensions-feature - 1.0.0-SNAPSHOT - pom - WSO2 Carbon - Device Management, MB Extensions Feature - http://wso2.org - - - org.wso2.carbon.andes.extensions.device.mgt.mqtt.authorization.feature - - - diff --git a/modules/iot-extensions/pom.xml b/modules/iot-extensions/pom.xml deleted file mode 100644 index 1bb473cb..00000000 --- a/modules/iot-extensions/pom.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - org.wso2.iot - wso2iot-parent - 1.0.0-SNAPSHOT - ../../pom.xml - - - 4.0.0 - iot-extensions - pom - WSO2 Carbon - IoT Extensions - http://wso2.org - - - components/mb-extensions - features/mb-extensions-feature - - - diff --git a/pom.xml b/pom.xml index 21330d62..52949108 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,6 @@ modules/tools modules/iotserver-ui - modules/features modules/p2-profile-gen modules/distribution