Merge branch 'release-2.0.x' of https://github.com/wso2/carbon-device-mgt into release-2.0.x

4.x.x
Imesh Chandrasiri 8 years ago
commit f8d03e992e

@ -65,7 +65,8 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
applicationName, APIUtil.getAllowedApisTags().toArray(new String[APIUtil.getAllowedApisTags().size()]), 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(); return Response.status(Response.Status.CREATED).entity(apiApplicationKey.toString()).build();
} catch (APIManagerException e) { } catch (APIManagerException e) {
String msg = "Error occurred while registering an application '" + applicationName + "'"; String msg = "Error occurred while registering an application '" + applicationName + "'";
@ -97,6 +98,12 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
} }
String username = APIUtil.getAuthenticatedUser() + "@" + APIUtil.getTenantDomainOftheUser(); String username = APIUtil.getAuthenticatedUser() + "@" + APIUtil.getTenantDomainOftheUser();
APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService(); APIManagementProviderService apiManagementProviderService = APIUtil.getAPIManagementProviderService();
String validityPeriod;
if (registrationProfile.getValidityPeriod() == null) {
validityPeriod = ApiApplicationConstants.DEFAULT_VALIDITY_PERIOD;
} else {
validityPeriod = registrationProfile.getValidityPeriod();
}
if (registrationProfile.isMappingAnExistingOAuthApp()) { if (registrationProfile.isMappingAnExistingOAuthApp()) {
JSONObject jsonStringObject = new JSONObject(); JSONObject jsonStringObject = new JSONObject();
jsonStringObject.put(ApiApplicationConstants.JSONSTRING_USERNAME_TAG, username); 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_ID, registrationProfile.getConsumerKey());
jsonStringObject.put(ApiApplicationConstants.OAUTH_CLIENT_SECRET, jsonStringObject.put(ApiApplicationConstants.OAUTH_CLIENT_SECRET,
registrationProfile.getConsumerSecret()); registrationProfile.getConsumerSecret());
if (registrationProfile.getValidityPeriod() == 0) { jsonStringObject.put(ApiApplicationConstants.JSONSTRING_VALIDITY_PERIOD_TAG, validityPeriod);
jsonStringObject.put(ApiApplicationConstants.JSONSTRING_VALIDITY_PERIOD_TAG,
ApiApplicationConstants.DEFAULT_VALIDITY_PERIOD);
} else {
jsonStringObject.put(ApiApplicationConstants.JSONSTRING_VALIDITY_PERIOD_TAG,
registrationProfile.getValidityPeriod());
}
apiManagementProviderService.registerExistingOAuthApplicationToAPIApplication( apiManagementProviderService.registerExistingOAuthApplicationToAPIApplication(
jsonStringObject.toJSONString(), registrationProfile.getApplicationName(), jsonStringObject.toJSONString(), registrationProfile.getApplicationName(),
registrationProfile.getConsumerKey(), username, registrationProfile.isAllowedToAllDomains(), registrationProfile.getConsumerKey(), username, registrationProfile.isAllowedToAllDomains(),
@ -120,7 +121,8 @@ public class ApiApplicationRegistrationServiceImpl implements ApiApplicationRegi
} else { } else {
ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys( ApiApplicationKey apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(
registrationProfile.getApplicationName(), registrationProfile.getTags(), 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(); return Response.status(Response.Status.CREATED).entity(apiApplicationKey.toString()).build();
} }
} catch (APIManagerException e) { } catch (APIManagerException e) {

@ -42,7 +42,7 @@ public class RegistrationProfile {
private String consumerKey; private String consumerKey;
private String consumerSecret; private String consumerSecret;
@XmlElement(required = false) @XmlElement(required = false)
private int validityPeriod; private String validityPeriod;
public String getApplicationName() { public String getApplicationName() {
return applicationName; return applicationName;
@ -92,11 +92,11 @@ public class RegistrationProfile {
this.consumerSecret = consumerSecret; this.consumerSecret = consumerSecret;
} }
public int getValidityPeriod() { public String getValidityPeriod() {
return validityPeriod; return validityPeriod;
} }
public void setValidityPeriod(int validityPeriod) { public void setValidityPeriod(String validityPeriod) {
this.validityPeriod = validityPeriod; this.validityPeriod = validityPeriod;
} }
} }

@ -34,11 +34,14 @@ public interface APIManagementProviderService {
* @param tags tags of the apis that application needs to be subscribed. * @param tags tags of the apis that application needs to be subscribed.
* @param keyType of the application. * @param keyType of the application.
* @param username to whom the application is created * @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. * @return consumerkey and secrete of the created application.
* @throws APIManagerException * @throws APIManagerException
*/ */
ApiApplicationKey generateAndRetrieveApplicationKeys(String apiApplicationName, String tags[], ApiApplicationKey generateAndRetrieveApplicationKeys(String apiApplicationName, String tags[],
String keyType, String username, boolean isAllowedAllDomains) String keyType, String username, boolean isAllowedAllDomains,
String validityTime)
throws APIManagerException; throws APIManagerException;
/** /**

@ -133,7 +133,7 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
@Override @Override
public ApiApplicationKey generateAndRetrieveApplicationKeys(String apiApplicationName, String tags[], public ApiApplicationKey generateAndRetrieveApplicationKeys(String apiApplicationName, String tags[],
String keyType, String username, String keyType, String username,
boolean isAllowedAllDomains) boolean isAllowedAllDomains, String validityTime)
throws APIManagerException { throws APIManagerException {
try { try {
APIManagerUtil.loadTenantRegistry(); APIManagerUtil.loadTenantRegistry();
@ -172,7 +172,6 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe
} else { } else {
allowedDomains[0] = APIManagerUtil.getTenantDomain(); allowedDomains[0] = APIManagerUtil.getTenantDomain();
} }
String validityTime = "3600";
String ownerJsonString = "{\"username\":\"" + username + "\"}"; String ownerJsonString = "{\"username\":\"" + username + "\"}";
Map<String, Object> keyDetails = apiConsumer.requestApprovalForApplicationRegistration(username, Map<String, Object> keyDetails = apiConsumer.requestApprovalForApplicationRegistration(username,
apiApplicationName, apiApplicationName,

@ -167,14 +167,14 @@ var utils = function () {
// register a tenant based app at API Manager // register a tenant based app at API Manager
var applicationName = "websocket_webapp_" + tenantDomain; var applicationName = "websocket_webapp_" + tenantDomain;
var requestURL = deviceMgtProps["oauthProvider"]["appRegistration"] var requestURL = (deviceMgtProps["oauthProvider"]["appRegistration"]
["apiManagerClientAppRegistrationServiceURL"] + ["apiManagerClientAppRegistrationServiceURL"]).replace("/tenants","");
"?tenantDomain=" + tenantDomain + "&applicationName=" + applicationName;
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open("POST", requestURL, false); xhr.open("POST", requestURL, false);
xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("X-JWT-Assertion", "" + jwtToken); 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"]) { if (xhr["status"] == 201 && xhr["responseText"]) {
var responsePayload = parse(xhr["responseText"]); var responsePayload = parse(xhr["responseText"]);
var tenantTenantBasedWebsocketClientAppCredentials = {}; var tenantTenantBasedWebsocketClientAppCredentials = {};

@ -21,7 +21,7 @@
<span class="page-sub-title">Device Types</span> <span class="page-sub-title">Device Types</span>
</div> </div>
</div> </div>
<span id="device-listing-status-msg"></span>
<div class="container-fluid"> <div class="container-fluid">
<table class="table table-striped table-hover list-table no-operations display responsive nowrap data-table grid-view no-toolbar" <table class="table table-striped table-hover list-table no-operations display responsive nowrap data-table grid-view no-toolbar"
id="device-type-grid"> id="device-type-grid">

Loading…
Cancel
Save