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 d0fe4e516da..a69ae339f22 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 @@ -65,7 +65,8 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( applicationName, APIUtil.getAllowedApisTags().toArray(new String[APIUtil.getAllowedApisTags().size()]), - ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username, false); + ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username, false, + ApiApplicationConstants.DEFAULT_VALIDITY_PERIOD); return Response.status(Response.Status.CREATED).entity(apiApplicationKey.toString()).build(); } catch (APIManagerException e) { String msg = "Error occurred while registering an application '" + applicationName + "'"; @@ -97,6 +98,12 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi } String username = APIUtil.getAuthenticatedUser() + "@" + APIUtil.getTenantDomainOftheUser(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); + String validityPeriod; + if (registrationProfile.getValidityPeriod() == null) { + validityPeriod = ApiApplicationConstants.DEFAULT_VALIDITY_PERIOD; + } else { + validityPeriod = registrationProfile.getValidityPeriod(); + } if (registrationProfile.isMappingAnExistingOAuthApp()) { JSONObject jsonStringObject = new JSONObject(); jsonStringObject.put(ApiApplicationConstants.JSONSTRING_USERNAME_TAG, username); @@ -105,13 +112,7 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi jsonStringObject.put(ApiApplicationConstants.OAUTH_CLIENT_ID, registrationProfile.getConsumerKey()); jsonStringObject.put(ApiApplicationConstants.OAUTH_CLIENT_SECRET, registrationProfile.getConsumerSecret()); - if (registrationProfile.getValidityPeriod() == 0) { - jsonStringObject.put(ApiApplicationConstants.JSONSTRING_VALIDITY_PERIOD_TAG, - ApiApplicationConstants.DEFAULT_VALIDITY_PERIOD); - } else { - jsonStringObject.put(ApiApplicationConstants.JSONSTRING_VALIDITY_PERIOD_TAG, - registrationProfile.getValidityPeriod()); - } + jsonStringObject.put(ApiApplicationConstants.JSONSTRING_VALIDITY_PERIOD_TAG, validityPeriod); apiManagementProviderService.registerExistingOAuthApplicationToAPIApplication( jsonStringObject.toJSONString(), registrationProfile.getApplicationName(), registrationProfile.getConsumerKey(), username, registrationProfile.isAllowedToAllDomains(), @@ -120,7 +121,8 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi } else { ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( registrationProfile.getApplicationName(), registrationProfile.getTags(), - ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username, false); + ApiApplicationConstants.DEFAULT_TOKEN_TYPE, username, + registrationProfile.isAllowedToAllDomains(), validityPeriod); return Response.status(Response.Status.CREATED).entity(apiApplicationKey.toString()).build(); } } catch (APIManagerException e) { 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 3efd856cd4b..b1634923f35 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 @@ -42,7 +42,7 @@ public class RegistrationProfile { private String consumerKey; private String consumerSecret; @XmlElement(required = false) - private int validityPeriod; + private String validityPeriod; public String getApplicationName() { return applicationName; @@ -92,11 +92,11 @@ public class RegistrationProfile { this.consumerSecret = consumerSecret; } - public int getValidityPeriod() { + public String getValidityPeriod() { return validityPeriod; } - public void setValidityPeriod(int validityPeriod) { + public void setValidityPeriod(String validityPeriod) { this.validityPeriod = validityPeriod; } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderService.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderService.java index e931c28358d..7e04924dc4c 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderService.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderService.java @@ -34,11 +34,14 @@ public interface APIManagementProviderService { * @param tags tags of the apis that application needs to be subscribed. * @param keyType of the application. * @param username to whom the application is created + * @param isAllowedAllDomains application is allowed to all the tenants + * @param validityTime validity period of the application * @return consumerkey and secrete of the created application. * @throws APIManagerException */ ApiApplicationKey generateAndRetrieveApplicationKeys(String apiApplicationName, String tags[], - String keyType, String username, boolean isAllowedAllDomains) + String keyType, String username, boolean isAllowedAllDomains, + String validityTime) throws APIManagerException; /** diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java index ce92eba32a0..913541e5334 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/src/main/java/org/wso2/carbon/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -133,7 +133,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe @Override public ApiApplicationKey generateAndRetrieveApplicationKeys(String apiApplicationName, String tags[], String keyType, String username, - boolean isAllowedAllDomains) + boolean isAllowedAllDomains, String validityTime) throws APIManagerException { try { APIManagerUtil.loadTenantRegistry(); @@ -172,7 +172,6 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe } else { allowedDomains[0] = APIManagerUtil.getTenantDomain(); } - String validityTime = "3600"; String ownerJsonString = "{\"username\":\"" + username + "\"}"; Map keyDetails = apiConsumer.requestApprovalForApplicationRegistration(username, apiApplicationName, diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js index 50cdb7f76fc..81cdc1729be 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/oauth/token-handler-utils.js @@ -167,14 +167,14 @@ var utils = function () { // register a tenant based app at API Manager var applicationName = "websocket_webapp_" + tenantDomain; - var requestURL = deviceMgtProps["oauthProvider"]["appRegistration"] - ["apiManagerClientAppRegistrationServiceURL"] + - "?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName; + var requestURL = (deviceMgtProps["oauthProvider"]["appRegistration"] + ["apiManagerClientAppRegistrationServiceURL"]).replace("/tenants",""); var xhr = new XMLHttpRequest(); xhr.open("POST", requestURL, false); xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("X-JWT-Assertion", "" + jwtToken); - xhr.send(); + xhr.send(stringify({applicationName:applicationName, tags:["device_management"], + isAllowedToAllDomains:false, isMappingAnExistingOAuthApp:false, validityPeriod: 3600})); if (xhr["status"] == 201 && xhr["responseText"]) { var responsePayload = parse(xhr["responseText"]); var tenantTenantBasedWebsocketClientAppCredentials = {};