From 52b4902aa5d0f4ed9a2b96fef27fc08feb86074c Mon Sep 17 00:00:00 2001 From: mharindu Date: Wed, 8 Jul 2015 22:27:24 +0530 Subject: [PATCH 1/4] Refactored dynamic-client-registration unregister function --- .../oauth/extension/RegistrationService.java | 5 +- .../extension/UnregistrationProfile.java | 51 ------------------- .../impl/ClientRegistrationServiceImpl.java | 9 ++-- 3 files changed, 8 insertions(+), 57 deletions(-) delete mode 100644 components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/UnregistrationProfile.java diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java index a8660aec90f..32893e3e1e4 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/RegistrationService.java @@ -22,6 +22,7 @@ import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.POST; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -33,6 +34,8 @@ public interface RegistrationService { Response register(RegistrationProfile profile); @DELETE - Response unregister(UnregistrationProfile profile); + public Response unregister(@QueryParam("applicationName") String applicationName, + @QueryParam("userId") String userId, + @QueryParam("consumerKey") String consumerKey); } \ No newline at end of file diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/UnregistrationProfile.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/UnregistrationProfile.java deleted file mode 100644 index ac3f4f317b2..00000000000 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/UnregistrationProfile.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* 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 org.wso2.carbon.identity.oauth.extension; - -/** - * This bean class represents the data that are required to unregister - * the oauth application. - */ -public class UnregistrationProfile { - - private String applicationName; - private String consumerKey; - private String userId; - - public String getApplicationName() { - return applicationName; - } - - public void setApplicationName(String applicationName) { - this.applicationName = applicationName; - } - - public String getConsumerKey() { - return consumerKey; - } - - public void setConsumerKey(String consumerKey) { - this.consumerKey = consumerKey; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } -} diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ClientRegistrationServiceImpl.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ClientRegistrationServiceImpl.java index dd277295647..f06767e3025 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ClientRegistrationServiceImpl.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/ClientRegistrationServiceImpl.java @@ -39,7 +39,6 @@ import org.wso2.carbon.identity.oauth.extension.ApplicationConstants; import org.wso2.carbon.identity.oauth.extension.OAuthApplicationInfo; import org.wso2.carbon.identity.oauth.extension.RegistrationProfile; import org.wso2.carbon.identity.oauth.extension.RegistrationService; -import org.wso2.carbon.identity.oauth.extension.UnregistrationProfile; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; @@ -47,6 +46,7 @@ import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.POST; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.Arrays; @@ -79,10 +79,9 @@ public class ClientRegistrationServiceImpl implements RegistrationService { @DELETE @Override - public Response unregister(UnregistrationProfile profile) { - String applicationName = profile.getApplicationName(); - String consumerKey = profile.getConsumerKey(); - String userId = profile.getUserId(); + public Response unregister(@QueryParam("applicationName") String applicationName, + @QueryParam("userId") String userId, + @QueryParam("consumerKey") String consumerKey) { try { this.unregisterApplication(userId, applicationName, consumerKey); return Response.status(Response.Status.ACCEPTED).build(); From 9d8c52958df21d91101f7991afab0135911cb71c Mon Sep 17 00:00:00 2001 From: mharindu Date: Mon, 13 Jul 2015 17:24:45 +0530 Subject: [PATCH 2/4] Refactored SQL queries and added null checks --- .../mgt/core/dao/impl/DeviceDAOImpl.java | 4 +-- .../DeviceManagementProviderServiceImpl.java | 36 ++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 5c9b25da887..55d19152ff3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -145,7 +145,7 @@ public class DeviceDAOImpl implements DeviceDAO { List devices = null; try { conn = this.getConnection(); - String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + + String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " + "e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME," + "d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " + "WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; @@ -175,7 +175,7 @@ public class DeviceDAOImpl implements DeviceDAO { List devices = null; try { conn = this.getConnection(); - String selectDBQueryForType = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + + String selectDBQueryForType = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION," + "e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " + "d.DEVICE_IDENTIFICATION, d.OWNER, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " + "WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ? AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 150287fdbda..0ff30129ad1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -229,8 +229,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Device dmsDevice = this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - device.setFeatures(dmsDevice.getFeatures()); - device.setProperties(dmsDevice.getProperties()); + if (dmsDevice != null) { + device.setFeatures(dmsDevice.getFeatures()); + device.setProperties(dmsDevice.getProperties()); + } devices.add(device); } return devices; @@ -259,8 +261,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Device dmsDevice = this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - device.setFeatures(dmsDevice.getFeatures()); - device.setProperties(dmsDevice.getProperties()); + if (dmsDevice != null) { + device.setFeatures(dmsDevice.getFeatures()); + device.setProperties(dmsDevice.getProperties()); + } devices.add(device); } return devices; @@ -409,8 +413,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (device != null) { DeviceManager dms = this.getPluginRepository().getDeviceManagementService(deviceId.getType()); Device pluginSpecificInfo = dms.getDevice(deviceId); - device.setProperties(pluginSpecificInfo.getProperties()); - device.setFeatures(pluginSpecificInfo.getFeatures()); + if (pluginSpecificInfo != null) { + device.setFeatures(pluginSpecificInfo.getFeatures()); + device.setProperties(pluginSpecificInfo.getProperties()); + } } return device; } @@ -554,8 +560,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Device dmsDevice = this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - device.setFeatures(dmsDevice.getFeatures()); - device.setProperties(dmsDevice.getProperties()); + if (dmsDevice != null) { + device.setFeatures(dmsDevice.getFeatures()); + device.setProperties(dmsDevice.getProperties()); + } devices.add(device); } return devices; @@ -596,8 +604,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Device dmsDevice = this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - device.setFeatures(dmsDevice.getFeatures()); - device.setProperties(dmsDevice.getProperties()); + if (dmsDevice != null) { + device.setFeatures(dmsDevice.getFeatures()); + device.setProperties(dmsDevice.getProperties()); + } devices.add(device); } } @@ -643,8 +653,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Device dmsDevice = this.getPluginRepository().getDeviceManagementService(device.getType()).getDevice( new DeviceIdentifier(device.getDeviceIdentifier(), device.getType())); - device.setFeatures(dmsDevice.getFeatures()); - device.setProperties(dmsDevice.getProperties()); + if (dmsDevice != null) { + device.setFeatures(dmsDevice.getFeatures()); + device.setProperties(dmsDevice.getProperties()); + } devices.add(device); } return devices; From 1d18c6de1ec7ef30254ec3686e90421df5dbb4c0 Mon Sep 17 00:00:00 2001 From: milanperera Date: Tue, 14 Jul 2015 14:43:01 +0530 Subject: [PATCH 3/4] Refactored DCA --- .../oauth/extension/DynamicClientRegistrationUtil.java | 9 ++------- .../oauth/extension/impl/RegistrationServiceImpl.java | 7 +++++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java index 3678284842a..9e9fe4db409 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java @@ -58,8 +58,7 @@ public class DynamicClientRegistrationUtil { private static final Log log = LogFactory.getLog(DynamicClientRegistrationUtil.class); - @POST - @Override + public Response register(RegistrationProfile profile) { try { PrivilegedCarbonContext.startTenantFlow(); @@ -78,11 +77,7 @@ public class DynamicClientRegistrationUtil { } } - @DELETE - @Override - public Response unregister(@QueryParam("applicationName") String applicationName, - @QueryParam("userId") String userId, - @QueryParam("consumerKey") String consumerKey) { + public Response unregister(String applicationName, String userId, String consumerKey) { try { this.unregisterApplication(userId, applicationName, consumerKey); return Response.status(Response.Status.ACCEPTED).build(); diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java index 0da5ec47ac8..0a9078b037d 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java @@ -35,9 +35,11 @@ import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.oauth.OAuthAdminService; import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO; -import org.wso2.carbon.identity.oauth.extension.*; +import org.wso2.carbon.identity.oauth.extension.DynamicClientRegistrationUtil; +import org.wso2.carbon.identity.oauth.extension.FaultResponse; +import org.wso2.carbon.identity.oauth.extension.OAuthApplicationInfo; +import org.wso2.carbon.identity.oauth.extension.RegistrationService; import org.wso2.carbon.identity.oauth.extension.profile.RegistrationProfile; -import org.wso2.carbon.identity.oauth.extension.profile.UnregistrationProfile; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; @@ -47,6 +49,7 @@ import javax.ws.rs.POST; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import javax.ws.rs.QueryParam; @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) From eeca0d4dedf45327f7f2720c26d7326b319f8062 Mon Sep 17 00:00:00 2001 From: milanperera Date: Tue, 14 Jul 2015 14:55:18 +0530 Subject: [PATCH 4/4] Refactored DCA --- .../DynamicClientRegistrationUtil.java | 44 ------------------- .../impl/RegistrationServiceImpl.java | 14 ------ 2 files changed, 58 deletions(-) diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java index 9e9fe4db409..4a64d6368d9 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/DynamicClientRegistrationUtil.java @@ -35,22 +35,9 @@ import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; import org.wso2.carbon.identity.base.IdentityException; import org.wso2.carbon.identity.oauth.OAuthAdminService; import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO; -import org.wso2.carbon.identity.oauth.extension.ApplicationConstants; -import org.wso2.carbon.identity.oauth.extension.OAuthApplicationInfo; -import org.wso2.carbon.identity.oauth.extension.RegistrationService; -import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.POST; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - import org.wso2.carbon.identity.oauth.extension.profile.RegistrationProfile; -import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.util.Arrays; @@ -58,37 +45,6 @@ public class DynamicClientRegistrationUtil { private static final Log log = LogFactory.getLog(DynamicClientRegistrationUtil.class); - - public Response register(RegistrationProfile profile) { - try { - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( - MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); - PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); - - OAuthApplicationInfo info = this.registerApplication(profile); - return Response.status(Response.Status.ACCEPTED).entity(info.toString()).build(); - } catch (APIManagementException e) { - String msg = "Error occurred while registering client '" + profile.getClientName() + "'"; - log.error(msg, e); - return Response.serverError().entity(msg).build(); - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - } - - public Response unregister(String applicationName, String userId, String consumerKey) { - try { - this.unregisterApplication(userId, applicationName, consumerKey); - return Response.status(Response.Status.ACCEPTED).build(); - } catch (APIManagementException e) { - String msg = "Error occurred while unregistering client '" + applicationName + "'"; - log.error(msg, e); - return Response.serverError().entity(msg).build(); - } - } - - public static OAuthApplicationInfo registerApplication(RegistrationProfile profile) throws APIManagementException { OAuthApplicationInfo oAuthApplicationInfo = new OAuthApplicationInfo(); diff --git a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java index 0a9078b037d..2fdb5399886 100644 --- a/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java +++ b/components/oauth-extensions/dynamic-client-manager/src/main/java/org/wso2/carbon/identity/oauth/extension/impl/RegistrationServiceImpl.java @@ -20,28 +20,14 @@ package org.wso2.carbon.identity.oauth.extension.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.json.JSONException; -import org.json.JSONObject; import org.wso2.carbon.apimgt.api.APIManagementException; -import org.wso2.carbon.apimgt.impl.utils.APIUtil; -import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException; -import org.wso2.carbon.identity.application.common.model.InboundAuthenticationConfig; -import org.wso2.carbon.identity.application.common.model.InboundAuthenticationRequestConfig; -import org.wso2.carbon.identity.application.common.model.Property; -import org.wso2.carbon.identity.application.common.model.ServiceProvider; -import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; -import org.wso2.carbon.identity.base.IdentityException; -import org.wso2.carbon.identity.oauth.OAuthAdminService; -import org.wso2.carbon.identity.oauth.dto.OAuthConsumerAppDTO; import org.wso2.carbon.identity.oauth.extension.DynamicClientRegistrationUtil; import org.wso2.carbon.identity.oauth.extension.FaultResponse; import org.wso2.carbon.identity.oauth.extension.OAuthApplicationInfo; import org.wso2.carbon.identity.oauth.extension.RegistrationService; import org.wso2.carbon.identity.oauth.extension.profile.RegistrationProfile; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE;