From c088a9bc9389e3df3ae3d90a19c1722a974ae255 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Wed, 1 Mar 2017 23:26:17 +0530 Subject: [PATCH] fixed api subscribe issue for device specific app creation --- .../ApiApplicationRegistrationService.java | 8 ------ ...ApiApplicationRegistrationServiceImpl.java | 27 ++++++++----------- .../api/util/RegistrationProfile.java | 11 -------- .../src/main/webapp/META-INF/permissions.xml | 9 +------ .../jaggeryapps/devicemgt/app/modules/init.js | 5 ++-- 5 files changed, 15 insertions(+), 45 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationService.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationService.java index 5f122b593a..3515a2e893 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationService.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationService.java @@ -51,12 +51,4 @@ public interface ApiApplicationRegistrationService { @Path("register") Response register(RegistrationProfile registrationProfile); - /** - * This method is used to unregister an API application. - * @param applicationName name of the application that needs to be unregistered. - * @return the response status of request. - */ - @DELETE - @Path("unregister") - Response unregister(@QueryParam("applicationName") String applicationName); } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java index b2f46dc09e..65392645ea 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/ApiApplicationRegistrationServiceImpl.java @@ -18,6 +18,7 @@ package org.wso2.carbon.apimgt.application.extension.api; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.simple.JSONObject; @@ -95,6 +96,8 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi return Response.status(Response.Status.NOT_ACCEPTABLE).entity("APIs(Tags) are not allowed to this user." ).build(); } + PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(PrivilegedCarbonContext. + getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration().getAdminUserName()); String username = APIUtil.getAuthenticatedUser(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); String validityPeriod; @@ -103,35 +106,27 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi } else { validityPeriod = registrationProfile.getValidityPeriod(); } + + String applicationName = "devicetype_app_" + StringUtils.join(registrationProfile.getTags(), "_"); ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( - registrationProfile.getApplicationName(), registrationProfile.getTags(), + applicationName, registrationProfile.getTags(), ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username, registrationProfile.isAllowedToAllDomains(), validityPeriod); return Response.status(Response.Status.CREATED).entity(apiApplicationKey.toString()).build(); } catch (APIManagerException e) { - String msg = "Error occurred while registering an application '" - + registrationProfile.getApplicationName() + "'"; + String msg = "Error occurred while registering an application with apis '" + + StringUtils.join(registrationProfile.getTags(), ",") + "'"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("false").build(); } catch (DeviceManagementException e) { String msg = "Failed to retrieve the device service"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - } - - @Path("unregister") - @DELETE - public Response unregister(@QueryParam("applicationName") String applicationName) { - try { - String username = APIUtil.getAuthenticatedUser() + "@" + APIUtil.getTenantDomainOftheUser(); - APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); - apiManagementProviderService.removeAPIApplication(applicationName, username); - return Response.status(Response.Status.ACCEPTED).build(); - } catch (APIManagerException e) { - String msg = "Error occurred while removing the application '" + applicationName; + } catch (UserStoreException e) { + String msg = "Failed to access user space."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } + } \ No newline at end of file diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java index ef63946fd3..2111753efe 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/RegistrationProfile.java @@ -30,9 +30,6 @@ import javax.xml.bind.annotation.XmlRootElement; @JsonIgnoreProperties(ignoreUnknown = true) public class RegistrationProfile { - - @XmlElement(required = true) - private String applicationName; @XmlElement(required = true) private String tags[]; @XmlElement(required = true) @@ -40,14 +37,6 @@ public class RegistrationProfile { @XmlElement(required = false) private String validityPeriod; - public String getApplicationName() { - return applicationName; - } - - public void setApiApplicationName(String apiApplicationName) { - this.applicationName = apiApplicationName; - } - public String[] getTags() { return tags; } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/webapp/META-INF/permissions.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/webapp/META-INF/permissions.xml index 9c41774ce5..2d907f170e 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/webapp/META-INF/permissions.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/webapp/META-INF/permissions.xml @@ -37,16 +37,9 @@ Register application - /manage/api/subscribe + /device-mgt/device/api/subscribe /register POST application_user - - Delete application - /manage/api/subscribe - /unregister - DELETE - application_user - \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js index 50cbba4dca..457e4e1b08 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/init.js @@ -30,11 +30,12 @@ application.put("carbonServer", carbonServer); var permissions = { "/permission/admin/Login": ["ui.execute"], - "/permission/admin/manage/api/subscribe": ["ui.execute"] + "/permission/admin/device-mgt/device/api/subscribe": ["ui.execute"] }; var adminPermissions = { - "/permission/admin": ["ui.execute"] + "/permission/admin/device-mgt": ["ui.execute"], + "/permission/admin/manage/api": ["ui.execute"] }; //On Startup, admin user will get both roles: devicemgt-admin and devicemgt-user