mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merging emm module changes to devicemgt iot app
This commit is contained in:
parent
624e7df688
commit
cf887a2e93
@ -46,25 +46,25 @@ var backendServiceInvoker = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled.
|
* ---------------------------------------------------------------------------
|
||||||
* @param method HTTP request type.
|
* Start of XML-HTTP-REQUEST based Interceptor implementations
|
||||||
* @param url target url.
|
* ---------------------------------------------------------------------------
|
||||||
* @param payload payload/data which need to be send.
|
*/
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
/**
|
||||||
|
* This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled.
|
||||||
|
* @param httpMethod HTTP request type.
|
||||||
|
* @param requestPayload payload/data if exists which is needed to be send.
|
||||||
|
* @param endpoint Backend REST API url.
|
||||||
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
* @param count a counter which hold the number of recursive execution
|
* @param count a counter which hold the number of recursive execution
|
||||||
*/
|
*/
|
||||||
privateMethods.execute = function (method, url, successCallback, errorCallback, payload, count, contentType, acceptType) {
|
privateMethods.execute = function (httpMethod, requestPayload, endpoint, responseCallback, count) {
|
||||||
var xmlHttpRequest = new XMLHttpRequest();
|
var xmlHttpRequest = new XMLHttpRequest();
|
||||||
xmlHttpRequest.open(method, url);
|
|
||||||
if(!contentType){
|
xmlHttpRequest.open(httpMethod, endpoint);
|
||||||
contentType = constants.APPLICATION_JSON;
|
xmlHttpRequest.setRequestHeader(constants["CONTENT_TYPE_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
||||||
}
|
xmlHttpRequest.setRequestHeader(constants["ACCEPT_IDENTIFIER"], constants["APPLICATION_JSON"]);
|
||||||
if(!acceptType){
|
|
||||||
acceptType = constants.APPLICATION_JSON;
|
|
||||||
}
|
|
||||||
xmlHttpRequest.setRequestHeader(constants.CONTENT_TYPE_IDENTIFIER, contentType);
|
|
||||||
xmlHttpRequest.setRequestHeader(constants.ACCEPT_IDENTIFIER, acceptType);
|
|
||||||
if (IS_OAUTH_ENABLED) {
|
if (IS_OAUTH_ENABLED) {
|
||||||
var accessToken = privateMethods.getAccessToken();
|
var accessToken = privateMethods.getAccessToken();
|
||||||
if (!accessToken) {
|
if (!accessToken) {
|
||||||
@ -73,120 +73,80 @@ var backendServiceInvoker = function () {
|
|||||||
xmlHttpRequest.setRequestHeader(constants.AUTHORIZATION_HEADER, constants.BEARER_PREFIX + accessToken);
|
xmlHttpRequest.setRequestHeader(constants.AUTHORIZATION_HEADER, constants.BEARER_PREFIX + accessToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (payload) {
|
|
||||||
xmlHttpRequest.send(payload);
|
if (requestPayload) {
|
||||||
|
xmlHttpRequest.send(requestPayload);
|
||||||
} else {
|
} else {
|
||||||
xmlHttpRequest.send();
|
xmlHttpRequest.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((xmlHttpRequest.status >= 200 && xmlHttpRequest.status < 300) || xmlHttpRequest.status == 302) {
|
|
||||||
if (xmlHttpRequest.responseText != null) {
|
if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED ||
|
||||||
return successCallback(parse(xmlHttpRequest.responseText));
|
xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) {
|
||||||
} else {
|
|
||||||
return successCallback({"status": xmlHttpRequest.status, "messageFromServer": "Operation Completed"});
|
|
||||||
}
|
|
||||||
} else if (xmlHttpRequest.status == 401 && (xmlHttpRequest.responseText == TOKEN_EXPIRED ||
|
|
||||||
xmlHttpRequest.responseText == TOKEN_INVALID ) && count < 5) {
|
|
||||||
tokenUtil.refreshToken();
|
tokenUtil.refreshToken();
|
||||||
return privateMethods.execute(method, url, successCallback, errorCallback, payload, (count + 1));
|
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, ++count);
|
||||||
} else if (xmlHttpRequest.status == 500) {
|
|
||||||
return errorCallback(xmlHttpRequest);
|
|
||||||
} else {
|
} else {
|
||||||
return errorCallback(xmlHttpRequest);
|
return responseCallback(xmlHttpRequest);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method add Oauth authentication header to outgoing XMLHTTP Requests if Oauth authentication is enabled.
|
* This method add Oauth authentication header to outgoing XML-HTTP Requests if Oauth authentication is enabled.
|
||||||
* @param method HTTP request type.
|
* @param httpMethod HTTP request type.
|
||||||
* @param url target url.
|
* @param requestPayload payload/data if exists which is needed to be send.
|
||||||
* @param payload payload/data which need to be send.
|
* @param endpoint Backend REST API url.
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
*/
|
||||||
privateMethods.initiateXMLHTTPRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) {
|
privateMethods.initiateXMLHTTPRequest = function (httpMethod, requestPayload, endpoint, responseCallback) {
|
||||||
if (privateMethods.getAccessToken()) {
|
return privateMethods.execute(httpMethod, requestPayload, endpoint, responseCallback, 0);
|
||||||
return privateMethods.execute(method, url, successCallback, errorCallback, payload, 0, contentType, acceptType);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method add Oauth authentication header to outgoing HTTPClient Requests if Oauth authentication is enabled.
|
* This method invokes return initiateXMLHttpRequest for get calls
|
||||||
* @param method HTTP request type.
|
* @param endpoint Backend REST API url.
|
||||||
* @param url target url.
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
* @param payload payload/data which need to be send.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
*/
|
||||||
privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload, contentType, acceptType) {
|
publicXMLHTTPInvokers.get = function (endpoint, responseCallback) {
|
||||||
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
var requestPayload = null;
|
||||||
var httpMethodObject;
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_GET"], requestPayload, endpoint, responseCallback);
|
||||||
switch (method) {
|
|
||||||
case constants.HTTP_POST:
|
|
||||||
var PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod;
|
|
||||||
httpMethodObject = new PostMethod(url);
|
|
||||||
break;
|
|
||||||
case constants.HTTP_PUT:
|
|
||||||
var PutMethod = Packages.org.apache.commons.httpclient.methods.PutMethod;
|
|
||||||
httpMethodObject = new PutMethod(url);
|
|
||||||
break;
|
|
||||||
case constants.HTTP_GET:
|
|
||||||
var GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod;
|
|
||||||
httpMethodObject = new GetMethod(url);
|
|
||||||
break;
|
|
||||||
case constants.HTTP_DELETE:
|
|
||||||
var DeleteMethod = Packages.org.apache.commons.httpclient.methods.DeleteMethod;
|
|
||||||
httpMethodObject = new DeleteMethod(url);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Invalid HTTP request type: " + method);
|
|
||||||
}
|
|
||||||
var Header = Packages.org.apache.commons.httpclient.Header;
|
|
||||||
var header = new Header();
|
|
||||||
header.setName(constants.CONTENT_TYPE_IDENTIFIER);
|
|
||||||
header.setValue(contentType);
|
|
||||||
httpMethodObject.addRequestHeader(header);
|
|
||||||
header = new Header();
|
|
||||||
header.setName(constants.ACCEPT_IDENTIFIER);
|
|
||||||
header.setValue(acceptType);
|
|
||||||
httpMethodObject.addRequestHeader(header);
|
|
||||||
if (IS_OAUTH_ENABLED) {
|
|
||||||
var accessToken = privateMethods.getAccessToken();
|
|
||||||
if (accessToken) {
|
|
||||||
header = new Header();
|
|
||||||
header.setName(constants.AUTHORIZATION_HEADER);
|
|
||||||
header.setValue(constants.BEARER_PREFIX + accessToken);
|
|
||||||
httpMethodObject.addRequestHeader(header);
|
|
||||||
} else {
|
|
||||||
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
if (payload) {
|
|
||||||
var stringRequestEntity = new StringRequestEntity(stringify(payload));
|
|
||||||
httpMethodObject.setRequestEntity(stringRequestEntity);
|
|
||||||
}
|
|
||||||
var client = new HttpClient();
|
|
||||||
try {
|
|
||||||
client.executeMethod(httpMethodObject);
|
|
||||||
var status = httpMethodObject.getStatusCode();
|
|
||||||
if (status == 200) {
|
|
||||||
var responseContentTypeHeader = httpMethodObject.getResponseHeader(constants.CONTENT_TYPE_IDENTIFIER);
|
|
||||||
if (responseContentTypeHeader && responseContentTypeHeader.getValue() == constants.APPLICATION_ZIP) {
|
|
||||||
return successCallback(httpMethodObject.getResponseBodyAsStream(), httpMethodObject.getResponseHeaders());
|
|
||||||
} else {
|
|
||||||
return successCallback(httpMethodObject.getResponseBody());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return errorCallback(httpMethodObject.getResponseBody());
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
return errorCallback(response);
|
|
||||||
} finally {
|
|
||||||
httpMethodObject.releaseConnection();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for post calls
|
||||||
|
* @param endpoint Backend REST API url.
|
||||||
|
* @param requestPayload payload/data if exists which is needed to be send.
|
||||||
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.post = function (endpoint, requestPayload, responseCallback) {
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_POST"], requestPayload, endpoint, responseCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for put calls
|
||||||
|
* @param endpoint Backend REST API url.
|
||||||
|
* @param requestPayload payload/data if exists which is needed to be send.
|
||||||
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.put = function (endpoint, requestPayload, responseCallback) {
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_PUT"], requestPayload, endpoint, responseCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method invokes return initiateXMLHttpRequest for delete calls
|
||||||
|
* @param endpoint Backend REST API url.
|
||||||
|
* @param responseCallback a function to be called with response retrieved.
|
||||||
|
*/
|
||||||
|
publicXMLHTTPInvokers.delete = function (endpoint, responseCallback) {
|
||||||
|
var requestPayload = null;
|
||||||
|
return privateMethods.initiateXMLHTTPRequest(constants["HTTP_DELETE"], requestPayload, endpoint, responseCallback);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
* Start of WS-REQUEST based Interceptor implementations
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method add Oauth authentication header to outgoing WS Requests if Oauth authentication is enabled.
|
* This method add Oauth authentication header to outgoing WS Requests if Oauth authentication is enabled.
|
||||||
* @param action
|
* @param action
|
||||||
@ -233,52 +193,11 @@ var backendServiceInvoker = function () {
|
|||||||
return successCallback(wsResponse);
|
return successCallback(wsResponse);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* This method invokes return initiateXMLHttpRequest for get calls
|
|
||||||
* @param url target url.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
|
||||||
publicXMLHTTPInvokers.get = function (url, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_GET, url, successCallback, errorCallback, contentType, acceptType);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method invokes return initiateXMLHttpRequest for post calls
|
|
||||||
* @param url target url.
|
|
||||||
* @param payload payload/data which need to be send.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
|
||||||
publicXMLHTTPInvokers.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method invokes return initiateXMLHttpRequest for put calls
|
|
||||||
* @param url target url.
|
|
||||||
* @param payload payload/data which need to be send.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
|
||||||
publicXMLHTTPInvokers.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method invokes return initiateXMLHttpRequest for delete calls
|
|
||||||
* @param url target url.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
|
||||||
*/
|
|
||||||
publicXMLHTTPInvokers.delete = function (url, successCallback, errorCallback, contentType, acceptType) {
|
|
||||||
return privateMethods.initiateXMLHTTPRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method invokes return initiateWSRequest for soap calls
|
* This method invokes return initiateWSRequest for soap calls
|
||||||
|
* @param action describes particular soap action.
|
||||||
|
* @param requestPayload SOAP request payload which is needed to be send.
|
||||||
* @param endpoint service end point to be triggered.
|
* @param endpoint service end point to be triggered.
|
||||||
* @param payload soap payload which need to be send.
|
|
||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
* @param soapVersion soapVersion which need to used.
|
* @param soapVersion soapVersion which need to used.
|
||||||
@ -287,6 +206,85 @@ var backendServiceInvoker = function () {
|
|||||||
return privateMethods.initiateWSRequest(action, endpoint, successCallback, errorCallback, soapVersion, payload);
|
return privateMethods.initiateWSRequest(action, endpoint, successCallback, errorCallback, soapVersion, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
* Start of HTTP-CLIENT-REQUEST based Interceptor implementations
|
||||||
|
* ---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method add Oauth authentication header to outgoing HTTPClient Requests if Oauth authentication is enabled.
|
||||||
|
* @param method HTTP request type.
|
||||||
|
* @param url target url.
|
||||||
|
* @param payload payload/data which need to be send.
|
||||||
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
|
*/
|
||||||
|
privateMethods.initiateHTTPClientRequest = function (method, url, successCallback, errorCallback, payload) {
|
||||||
|
var HttpClient = Packages.org.apache.commons.httpclient.HttpClient;
|
||||||
|
var httpMethodObject;
|
||||||
|
switch (method) {
|
||||||
|
case constants.HTTP_POST:
|
||||||
|
var PostMethod = Packages.org.apache.commons.httpclient.methods.PostMethod;
|
||||||
|
httpMethodObject = new PostMethod(url);
|
||||||
|
break;
|
||||||
|
case constants.HTTP_PUT:
|
||||||
|
var PutMethod = Packages.org.apache.commons.httpclient.methods.PutMethod;
|
||||||
|
httpMethodObject = new PutMethod(url);
|
||||||
|
break;
|
||||||
|
case constants.HTTP_GET:
|
||||||
|
var GetMethod = Packages.org.apache.commons.httpclient.methods.GetMethod;
|
||||||
|
httpMethodObject = new GetMethod(url);
|
||||||
|
break;
|
||||||
|
case constants.HTTP_DELETE:
|
||||||
|
var DeleteMethod = Packages.org.apache.commons.httpclient.methods.DeleteMethod;
|
||||||
|
httpMethodObject = new DeleteMethod(url);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid HTTP request type: " + method);
|
||||||
|
}
|
||||||
|
var Header = Packages.org.apache.commons.httpclient.Header;
|
||||||
|
var header = new Header();
|
||||||
|
header.setName(constants.CONTENT_TYPE_IDENTIFIER);
|
||||||
|
httpMethodObject.addRequestHeader(header);
|
||||||
|
header = new Header();
|
||||||
|
header.setName(constants.ACCEPT_IDENTIFIER);
|
||||||
|
httpMethodObject.addRequestHeader(header);
|
||||||
|
if (IS_OAUTH_ENABLED) {
|
||||||
|
var accessToken = privateMethods.getAccessToken();
|
||||||
|
if (accessToken) {
|
||||||
|
header = new Header();
|
||||||
|
header.setName(constants.AUTHORIZATION_HEADER);
|
||||||
|
header.setValue(constants.BEARER_PREFIX + accessToken);
|
||||||
|
httpMethodObject.addRequestHeader(header);
|
||||||
|
} else {
|
||||||
|
response.sendRedirect(devicemgtProps["httpsURL"] + "/devicemgt/login");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (payload) {
|
||||||
|
var stringRequestEntity = new StringRequestEntity(stringify(payload));
|
||||||
|
httpMethodObject.setRequestEntity(stringRequestEntity);
|
||||||
|
}
|
||||||
|
var client = new HttpClient();
|
||||||
|
try {
|
||||||
|
client.executeMethod(httpMethodObject);
|
||||||
|
var status = httpMethodObject.getStatusCode();
|
||||||
|
if (status == 200) {
|
||||||
|
var responseContentTypeHeader = httpMethodObject.getResponseHeader(constants.CONTENT_TYPE_IDENTIFIER);
|
||||||
|
if (responseContentTypeHeader && responseContentTypeHeader.getValue() == constants.APPLICATION_ZIP) {
|
||||||
|
return successCallback(httpMethodObject.getResponseBodyAsStream(), httpMethodObject.getResponseHeaders());
|
||||||
|
} else {
|
||||||
|
return successCallback(httpMethodObject.getResponseBody());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return errorCallback(httpMethodObject.getResponseBody());
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return errorCallback(response);
|
||||||
|
} finally {
|
||||||
|
httpMethodObject.releaseConnection();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method invokes return initiateHTTPClientRequest for get calls
|
* This method invokes return initiateHTTPClientRequest for get calls
|
||||||
@ -294,8 +292,10 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.get = function (url, successCallback, errorCallback, contentType, acceptType) {
|
publicHTTPClientInvokers.get = function (url, successCallback, errorCallback) {
|
||||||
return privateMethods.initiateHTTPClientRequest(constants.HTTP_GET, url, successCallback, errorCallback, contentType, acceptType);
|
var requestPayload = null;
|
||||||
|
return privateMethods.
|
||||||
|
initiateHTTPClientRequest(constants["HTTP_GET"], url, successCallback, errorCallback, requestPayload);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -305,9 +305,9 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
publicHTTPClientInvokers.post = function (url, payload, successCallback, errorCallback) {
|
||||||
return privateMethods.
|
return privateMethods.
|
||||||
initiateHTTPClientRequest(constants.HTTP_POST, url, successCallback, errorCallback, payload, contentType, acceptType);
|
initiateHTTPClientRequest(constants["HTTP_POST"], url, successCallback, errorCallback, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -317,8 +317,9 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback, contentType, acceptType) {
|
publicHTTPClientInvokers.put = function (url, payload, successCallback, errorCallback) {
|
||||||
return privateMethods.initiateHTTPClientRequest(constants.HTTP_PUT, url, successCallback, errorCallback, payload, contentType, acceptType);
|
return privateMethods.
|
||||||
|
initiateHTTPClientRequest(constants["HTTP_PUT"], url, successCallback, errorCallback, payload);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -327,13 +328,16 @@ var backendServiceInvoker = function () {
|
|||||||
* @param successCallback a function to be called if the respond if successful.
|
* @param successCallback a function to be called if the respond if successful.
|
||||||
* @param errorCallback a function to be called if en error is reserved.
|
* @param errorCallback a function to be called if en error is reserved.
|
||||||
*/
|
*/
|
||||||
publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback, contentType, acceptType) {
|
publicHTTPClientInvokers.delete = function (url, successCallback, errorCallback) {
|
||||||
return privateMethods.initiateHTTPClientRequest(constants.HTTP_DELETE, url, successCallback, errorCallback, contentType, acceptType);
|
var requestPayload = null;
|
||||||
|
return privateMethods.
|
||||||
|
initiateHTTPClientRequest(constants["HTTP_DELETE"], url, successCallback, errorCallback, requestPayload);
|
||||||
};
|
};
|
||||||
|
|
||||||
var publicInvokers = {};
|
var publicMethods = {};
|
||||||
publicInvokers.XMLHttp = publicXMLHTTPInvokers;
|
publicMethods.XMLHttp = publicXMLHTTPInvokers;
|
||||||
publicInvokers.WS = publicWSInvokers;
|
publicMethods.WS = publicWSInvokers;
|
||||||
publicInvokers.HttpClient = publicHTTPClientInvokers;
|
publicMethods.HttpClient = publicHTTPClientInvokers;
|
||||||
return publicInvokers;
|
|
||||||
}();
|
return publicMethods;
|
||||||
|
}();
|
||||||
|
|||||||
@ -36,7 +36,8 @@ deviceModule = function () {
|
|||||||
var publicMethods = {};
|
var publicMethods = {};
|
||||||
var privateMethods = {};
|
var privateMethods = {};
|
||||||
|
|
||||||
var deviceCloudService = devicemgtProps["httpsURL"] + "/common/device_manager";
|
//var deviceCloudService = devicemgtProps["httpsURL"] + "/common/device_manager";
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
|
||||||
privateMethods.validateAndReturn = function (value) {
|
privateMethods.validateAndReturn = function (value) {
|
||||||
return (value == undefined || value == null) ? constants.UNSPECIFIED : value;
|
return (value == undefined || value == null) ? constants.UNSPECIFIED : value;
|
||||||
@ -97,6 +98,61 @@ deviceModule = function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
@Deprecated
|
||||||
|
*/
|
||||||
|
publicMethods.listDevicesForUser = function (username) {
|
||||||
|
var carbonUser = session.get(constants.USER_SESSION_KEY);
|
||||||
|
var utility = require('/modules/utility.js').utility;
|
||||||
|
if (!carbonUser) {
|
||||||
|
log.error("User object was not found in the session");
|
||||||
|
throw constants.ERRORS.USER_NOT_FOUND;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
utility.startTenantFlow(carbonUser);
|
||||||
|
var deviceManagementService = utility.getDeviceManagementService();
|
||||||
|
var devices = deviceManagementService.getDeviceListOfUser(username);
|
||||||
|
var deviceList = [];
|
||||||
|
var i, device, propertiesList, deviceObject;
|
||||||
|
for (i = 0; i < devices.size(); i++) {
|
||||||
|
device = devices.get(i);
|
||||||
|
propertiesList = DeviceManagerUtil.convertDevicePropertiesToMap(device.getProperties());
|
||||||
|
|
||||||
|
deviceObject = {};
|
||||||
|
deviceObject[constants.DEVICE_IDENTIFIER] =
|
||||||
|
privateMethods.validateAndReturn(device.getDeviceIdentifier());
|
||||||
|
deviceObject[constants.DEVICE_NAME] =
|
||||||
|
privateMethods.validateAndReturn(device.getName());
|
||||||
|
deviceObject[constants.DEVICE_OWNERSHIP] =
|
||||||
|
privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwnership());
|
||||||
|
deviceObject[constants.DEVICE_OWNER] =
|
||||||
|
privateMethods.validateAndReturn(device.getEnrolmentInfo().getOwner());
|
||||||
|
deviceObject[constants.DEVICE_TYPE] =
|
||||||
|
privateMethods.validateAndReturn(device.getType());
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES] = {};
|
||||||
|
if (device.getType() == constants.PLATFORM_IOS) {
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_PRODUCT));
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] = constants.VENDOR_APPLE;
|
||||||
|
} else {
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_MODEL] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_MODEL));
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_VENDOR] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_VENDOR));
|
||||||
|
}
|
||||||
|
deviceObject[constants.DEVICE_PROPERTIES][constants.DEVICE_OS_VERSION] =
|
||||||
|
privateMethods.validateAndReturn(propertiesList.get(constants.DEVICE_OS_VERSION));
|
||||||
|
|
||||||
|
deviceList.push(deviceObject);
|
||||||
|
}
|
||||||
|
return deviceList;
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
utility.endTenantFlow();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@Deprecated
|
@Deprecated
|
||||||
*/
|
*/
|
||||||
@ -216,36 +272,36 @@ deviceModule = function () {
|
|||||||
try {
|
try {
|
||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
|
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/view?type=" + deviceType + "&id=" + deviceId;
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId;
|
||||||
return serviceInvokers.XMLHttp.get(
|
return serviceInvokers.XMLHttp.get(
|
||||||
url, function (responsePayload) {
|
url,
|
||||||
var device = responsePayload.responseContent;
|
function (backendResponse) {
|
||||||
if (device) {
|
var response = {};
|
||||||
var propertiesList = device["properties"];
|
if (backendResponse.status == 200 && backendResponse.responseText) {
|
||||||
var properties = {};
|
response["status"] = "success";
|
||||||
if (propertiesList){
|
var device = parse(backendResponse.responseText);
|
||||||
for (var i = 0; i < propertiesList.length; i++) {
|
var propertiesList = device["properties"];
|
||||||
properties[propertiesList[i]["name"]] = propertiesList[i]["value"];
|
var properties = {};
|
||||||
}
|
for (var i = 0; i < propertiesList.length; i++) {
|
||||||
}
|
properties[propertiesList[i]["name"]] =
|
||||||
var deviceObject = {};
|
propertiesList[i]["value"];
|
||||||
deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];
|
|
||||||
deviceObject[constants["DEVICE_NAME"]] = device["name"];
|
|
||||||
deviceObject[constants["DEVICE_OWNERSHIP"]] = device["enrolmentInfo"]["ownership"];
|
|
||||||
deviceObject[constants["DEVICE_OWNER"]] = device["enrolmentInfo"]["owner"];
|
|
||||||
deviceObject[constants["DEVICE_STATUS"]] = device["enrolmentInfo"]["status"];
|
|
||||||
deviceObject[constants["DEVICE_TYPE"]] = device["type"];
|
|
||||||
if (device["type"] == constants["PLATFORM_IOS"]) {
|
|
||||||
properties[constants["DEVICE_MODEL"]] = properties[constants["DEVICE_PRODUCT"]];
|
|
||||||
delete properties[constants["DEVICE_PRODUCT"]];
|
|
||||||
properties[constants["DEVICE_VENDOR"]] = constants["VENDOR_APPLE"];
|
|
||||||
}
|
|
||||||
deviceObject[constants["DEVICE_PROPERTIES"]] = properties;
|
|
||||||
return deviceObject;
|
|
||||||
}
|
}
|
||||||
},
|
var deviceObject = {};
|
||||||
function (responsePayload) {
|
deviceObject[constants["DEVICE_IDENTIFIER"]] = device["deviceIdentifier"];
|
||||||
var response = {};
|
deviceObject[constants["DEVICE_NAME"]] = device["name"];
|
||||||
|
deviceObject[constants["DEVICE_OWNERSHIP"]] = device["enrolmentInfo"]["ownership"];
|
||||||
|
deviceObject[constants["DEVICE_OWNER"]] = device["enrolmentInfo"]["owner"];
|
||||||
|
deviceObject[constants["DEVICE_STATUS"]] = device["enrolmentInfo"]["status"];
|
||||||
|
deviceObject[constants["DEVICE_TYPE"]] = device["type"];
|
||||||
|
if (device["type"] == constants["PLATFORM_IOS"]) {
|
||||||
|
properties[constants["DEVICE_MODEL"]] = properties[constants["DEVICE_PRODUCT"]];
|
||||||
|
delete properties[constants["DEVICE_PRODUCT"]];
|
||||||
|
properties[constants["DEVICE_VENDOR"]] = constants["VENDOR_APPLE"];
|
||||||
|
}
|
||||||
|
deviceObject[constants["DEVICE_PROPERTIES"]] = properties;
|
||||||
|
response["content"] = deviceObject;
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
response["status"] = "error";
|
response["status"] = "error";
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,13 +32,11 @@ var invokerRequestWrapper = function () {
|
|||||||
var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
||||||
var response = {};
|
var response = {};
|
||||||
response.content = responsePayload["responseContent"];
|
response.content = responsePayload["responseContent"];
|
||||||
response.status = "success";
|
if (responsePayload.status == 200) {
|
||||||
return response;
|
response.status = "success";
|
||||||
},
|
} else {
|
||||||
function (responsePayload) {
|
response.status = "error";
|
||||||
var response = {};
|
}
|
||||||
response.content = responsePayload;
|
|
||||||
response.status = "error";
|
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
return response;
|
return response;
|
||||||
|
|||||||
@ -31,73 +31,91 @@ policyModule = function () {
|
|||||||
var publicMethods = {};
|
var publicMethods = {};
|
||||||
var privateMethods = {};
|
var privateMethods = {};
|
||||||
|
|
||||||
privateMethods.handleGetAllPoliciesError = function (responsePayload) {
|
privateMethods.handleGetAllPoliciesResponse = function (backendResponse) {
|
||||||
var response = {};
|
var response = {};
|
||||||
response.status = "error";
|
if (backendResponse.status = 200) {
|
||||||
/* responsePayload == "Scope validation failed"
|
var isUpdated = false;
|
||||||
Here the response.context("Scope validation failed") is used other then response.status(401).
|
var policyListFromRestEndpoint = parse(backendResponse.responseText)["policies"];
|
||||||
Reason for this is IDP return 401 as the status in 4 different situations such as,
|
var policyListToView = [];
|
||||||
1. UnAuthorized.
|
var i, policyObjectFromRestEndpoint, policyObjectToView;
|
||||||
2. Scope Validation Failed.
|
for (i = 0; i < policyListFromRestEndpoint.length; i++) {
|
||||||
3. Permission Denied.
|
// get list object
|
||||||
4. Access Token Expired.
|
policyObjectFromRestEndpoint = policyListFromRestEndpoint[i];
|
||||||
5. Access Token Invalid.
|
// populate list object values to view-object
|
||||||
In these cases in order to identify the correct situation we have to compare the unique value from status and
|
policyObjectToView = {};
|
||||||
context which is context.
|
policyObjectToView["id"] = policyObjectFromRestEndpoint["id"];
|
||||||
*/
|
policyObjectToView["priorityId"] = policyObjectFromRestEndpoint["priorityId"];
|
||||||
if (responsePayload == "Scope validation failed") {
|
policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"];
|
||||||
response.content = "Permission Denied";
|
policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]["name"];
|
||||||
} else {
|
policyObjectToView["ownershipType"] = policyObjectFromRestEndpoint["ownershipType"];
|
||||||
response.content = responsePayload;
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
};
|
|
||||||
|
|
||||||
privateMethods.handleGetAllPoliciesSuccess = function (responsePayload) {
|
var assignedRoleCount = policyObjectFromRestEndpoint["roles"].length;
|
||||||
var isUpdated = false;
|
var assignedUserCount = policyObjectFromRestEndpoint["users"].length;
|
||||||
var policyListFromRestEndpoint = responsePayload["responseContent"];
|
|
||||||
var policyListToView = [];
|
|
||||||
var i, policyObjectFromRestEndpoint, policyObjectToView;
|
|
||||||
for (i = 0; i < policyListFromRestEndpoint.length; i++) {
|
|
||||||
// get list object
|
|
||||||
policyObjectFromRestEndpoint = policyListFromRestEndpoint[i];
|
|
||||||
// populate list object values to view-object
|
|
||||||
policyObjectToView = {};
|
|
||||||
policyObjectToView["id"] = policyObjectFromRestEndpoint["id"];
|
|
||||||
policyObjectToView["priorityId"] = policyObjectFromRestEndpoint["priorityId"];
|
|
||||||
policyObjectToView["name"] = policyObjectFromRestEndpoint["policyName"];
|
|
||||||
policyObjectToView["platform"] = policyObjectFromRestEndpoint["profile"]["deviceType"]["name"];
|
|
||||||
policyObjectToView["icon"] = utility.getDeviceThumb(policyObjectToView["platform"]);
|
|
||||||
policyObjectToView["ownershipType"] = policyObjectFromRestEndpoint["ownershipType"];
|
|
||||||
policyObjectToView["roles"] = privateMethods.
|
|
||||||
getElementsInAString(policyObjectFromRestEndpoint["roles"]);
|
|
||||||
policyObjectToView["users"] = privateMethods.
|
|
||||||
getElementsInAString(policyObjectFromRestEndpoint["users"]);
|
|
||||||
policyObjectToView["compliance"] = policyObjectFromRestEndpoint["compliance"];
|
|
||||||
|
|
||||||
if (policyObjectFromRestEndpoint["active"] == true && policyObjectFromRestEndpoint["updated"] == true) {
|
if (assignedRoleCount == 0) {
|
||||||
policyObjectToView["status"] = "Active/Updated";
|
policyObjectToView["roles"] = "None";
|
||||||
isUpdated = true;
|
} else if (assignedRoleCount == 1) {
|
||||||
} else if (policyObjectFromRestEndpoint["active"] == true &&
|
policyObjectToView["roles"] = policyObjectFromRestEndpoint["roles"][0];
|
||||||
policyObjectFromRestEndpoint["updated"] == false) {
|
} else if (assignedRoleCount > 1) {
|
||||||
policyObjectToView["status"] = "Active";
|
policyObjectToView["roles"] = policyObjectFromRestEndpoint["roles"][0] + ", ...";
|
||||||
} else if (policyObjectFromRestEndpoint["active"] == false &&
|
}
|
||||||
policyObjectFromRestEndpoint["updated"] == true) {
|
|
||||||
policyObjectToView["status"] = "Inactive/Updated";
|
if (assignedUserCount == 0) {
|
||||||
isUpdated = true;
|
policyObjectToView["users"] = "None";
|
||||||
} else if (policyObjectFromRestEndpoint["active"] == false &&
|
} else if (assignedUserCount == 1) {
|
||||||
policyObjectFromRestEndpoint["updated"] == false) {
|
policyObjectToView["users"] = policyObjectFromRestEndpoint["users"][0];
|
||||||
policyObjectToView["status"] = "Inactive";
|
} else if (assignedUserCount > 1) {
|
||||||
|
policyObjectToView["users"] = policyObjectFromRestEndpoint["users"][0] + ", ...";
|
||||||
|
}
|
||||||
|
|
||||||
|
policyObjectToView["compliance"] = policyObjectFromRestEndpoint["compliance"];
|
||||||
|
|
||||||
|
if (policyObjectFromRestEndpoint["active"] == true &&
|
||||||
|
policyObjectFromRestEndpoint["updated"] == true) {
|
||||||
|
policyObjectToView["status"] = "Active/Updated";
|
||||||
|
isUpdated = true;
|
||||||
|
} else if (policyObjectFromRestEndpoint["active"] == true &&
|
||||||
|
policyObjectFromRestEndpoint["updated"] == false) {
|
||||||
|
policyObjectToView["status"] = "Active";
|
||||||
|
} else if (policyObjectFromRestEndpoint["active"] == false &&
|
||||||
|
policyObjectFromRestEndpoint["updated"] == true) {
|
||||||
|
policyObjectToView["status"] = "Inactive/Updated";
|
||||||
|
isUpdated = true;
|
||||||
|
} else if (policyObjectFromRestEndpoint["active"] == false &&
|
||||||
|
policyObjectFromRestEndpoint["updated"] == false) {
|
||||||
|
policyObjectToView["status"] = "Inactive";
|
||||||
|
}
|
||||||
|
// push view-objects to list
|
||||||
|
policyListToView.push(policyObjectToView);
|
||||||
}
|
}
|
||||||
// push view-objects to list
|
// generate response
|
||||||
policyListToView.push(policyObjectToView);
|
response.updated = isUpdated;
|
||||||
|
response.status = "success";
|
||||||
|
response.content = policyListToView;
|
||||||
|
|
||||||
|
log.info(stringify(policyListToView));
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} else {
|
||||||
|
response.status = "error";
|
||||||
|
/* backendResponse.responseText == "Scope validation failed"
|
||||||
|
Here the response.context("Scope validation failed") is used other then response.status(401).
|
||||||
|
Reason for this is IDP return 401 as the status in 4 different situations such as,
|
||||||
|
1. UnAuthorized.
|
||||||
|
2. Scope Validation Failed.
|
||||||
|
3. Permission Denied.
|
||||||
|
4. Access Token Expired.
|
||||||
|
5. Access Token Invalid.
|
||||||
|
In these cases in order to identify the correct situation we have to compare the unique value from status and
|
||||||
|
context which is context.
|
||||||
|
*/
|
||||||
|
if (backendResponse.responseText == "Scope validation failed") {
|
||||||
|
response.content = "Permission Denied";
|
||||||
|
} else {
|
||||||
|
response.content = backendResponse.responseText;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
// generate response
|
|
||||||
var response = {};
|
|
||||||
response.updated = isUpdated;
|
|
||||||
response.status = "success";
|
|
||||||
response.content = policyListToView;
|
|
||||||
return response;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription,
|
publicMethods.addPolicy = function (policyName, deviceType, policyDefinition, policyDescription,
|
||||||
@ -155,9 +173,8 @@ policyModule = function () {
|
|||||||
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
throw constants["ERRORS"]["USER_NOT_FOUND"];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/policies";
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/policies?offset=0&limit=100";
|
||||||
return serviceInvokers.XMLHttp.
|
return serviceInvokers.XMLHttp.get(url, privateMethods.handleGetAllPoliciesResponse);
|
||||||
get(url, privateMethods.handleGetAllPoliciesSuccess, privateMethods.handleGetAllPoliciesError);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -66,22 +66,18 @@ var userModule = function () {
|
|||||||
*/
|
*/
|
||||||
privateMethods.callBackend = function (url, method) {
|
privateMethods.callBackend = function (url, method) {
|
||||||
if (constants.HTTP_GET == method) {
|
if (constants.HTTP_GET == method) {
|
||||||
var response = serviceInvokers.XMLHttp.get(url, function (responsePayload) {
|
return serviceInvokers.XMLHttp.get(url,
|
||||||
var response = {};
|
function (backendResponse) {
|
||||||
response.content = responsePayload["responseContent"];
|
var response = {};
|
||||||
if (responsePayload["responseContent"] == null && responsePayload != null) {
|
response.content = backendResponse.responseText;
|
||||||
response.content = responsePayload;
|
if (backendResponse.status == 200) {
|
||||||
|
response.status = "success";
|
||||||
|
} else {
|
||||||
|
response.status = "error";
|
||||||
|
}
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
response.status = "success";
|
);
|
||||||
return response;
|
|
||||||
},
|
|
||||||
function (responsePayload) {
|
|
||||||
var response = {};
|
|
||||||
response.content = responsePayload;
|
|
||||||
response.status = "error";
|
|
||||||
return response;
|
|
||||||
});
|
|
||||||
return response;
|
|
||||||
} else {
|
} else {
|
||||||
log.error("Programming error : This method only support HTTP GET requests.");
|
log.error("Programming error : This method only support HTTP GET requests.");
|
||||||
}
|
}
|
||||||
@ -382,9 +378,12 @@ var userModule = function () {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users";
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users?offset=0&limit=100";
|
||||||
return privateMethods.callBackend(url, constants.HTTP_GET);
|
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||||
|
if (response.status == "success") {
|
||||||
|
response.content = parse(response.content).users;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
@ -409,8 +408,10 @@ var userModule = function () {
|
|||||||
var carbonUser = privateMethods.getCarbonUser();
|
var carbonUser = privateMethods.getCarbonUser();
|
||||||
try {
|
try {
|
||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/view?username=" + username;
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/" +
|
||||||
var response = privateMethods.callBackend(url, constants.HTTP_GET);
|
encodeURIComponent(username);
|
||||||
|
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||||
|
response["content"] = parse(response.content);
|
||||||
response["userDomain"] = carbonUser.domain;
|
response["userDomain"] = carbonUser.domain;
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -420,17 +421,17 @@ var userModule = function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* TODO: comment
|
* Returns a set of roles assigned to a particular user
|
||||||
* @param username
|
* @param username
|
||||||
* @returns {*}
|
* @returns {object} a response object with status and content on success.
|
||||||
*/
|
*/
|
||||||
publicMethods.getRolesByUsername = function (username) {
|
publicMethods.getRolesByUsername = function (username) {
|
||||||
var carbonUser = privateMethods.getCarbonUser();
|
var carbonUser = privateMethods.getCarbonUser();
|
||||||
try {
|
try {
|
||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/users/roles?username=" + username;
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + + "/users/" +
|
||||||
var response = privateMethods.callBackend(url, constants.HTTP_GET);
|
encodeURIComponent(username) + "/roles";
|
||||||
return response;
|
return privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
@ -464,6 +465,7 @@ var userModule = function () {
|
|||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Get User Roles from user store (Internal roles not included).
|
* Get User Roles from user store (Internal roles not included).
|
||||||
|
* @returns {object} a response object with status and content on success.
|
||||||
*/
|
*/
|
||||||
publicMethods.getRoles = function () {
|
publicMethods.getRoles = function () {
|
||||||
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
@ -475,7 +477,11 @@ var userModule = function () {
|
|||||||
try {
|
try {
|
||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles";
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles";
|
||||||
return privateMethods.callBackend(url, constants.HTTP_GET);
|
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||||
|
if (response.status == "success") {
|
||||||
|
response.content = parse(response.content).roles;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
@ -488,8 +494,10 @@ var userModule = function () {
|
|||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* Get User Roles from user store (Internal roles not included).
|
* Get User Roles from user store (Internal roles not included).
|
||||||
|
* @returns {object} a response object with status and content on success.
|
||||||
*/
|
*/
|
||||||
publicMethods.getRolesByUserStore = function (userStore) {
|
publicMethods.getRolesByUserStore = function () {
|
||||||
|
var ROLE_LIMIT = devicemgtProps.pageSize;
|
||||||
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
var carbonUser = session.get(constants["USER_SESSION_KEY"]);
|
||||||
var utility = require('/app/modules/utility.js')["utility"];
|
var utility = require('/app/modules/utility.js')["utility"];
|
||||||
if (!carbonUser) {
|
if (!carbonUser) {
|
||||||
@ -498,8 +506,12 @@ var userModule = function () {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles/" + encodeURIComponent(userStore);
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles?limit=" + ROLE_LIMIT;
|
||||||
return privateMethods.callBackend(url, constants.HTTP_GET);
|
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||||
|
if (response.status == "success") {
|
||||||
|
response.content = parse(response.content).roles;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
@ -520,7 +532,11 @@ var userModule = function () {
|
|||||||
try {
|
try {
|
||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/types";
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/devices/types";
|
||||||
return privateMethods.callBackend(url, constants.HTTP_GET);
|
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||||
|
if (response.status == "success") {
|
||||||
|
response.content = parse(response.content);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
@ -542,8 +558,9 @@ var userModule = function () {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
utility.startTenantFlow(carbonUser);
|
utility.startTenantFlow(carbonUser);
|
||||||
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles/role?rolename=" + encodeURIComponent(roleName);
|
var url = devicemgtProps["httpsURL"] + constants.ADMIN_SERVICE_CONTEXT + "/roles/" + encodeURIComponent(roleName);
|
||||||
var response = privateMethods.callBackend(url, constants.HTTP_GET);
|
var response = privateMethods.callBackend(url, constants["HTTP_GET"]);
|
||||||
|
response.content = parse(response.content);
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
@ -683,6 +700,9 @@ var userModule = function () {
|
|||||||
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/platform-configs/view")) {
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/platform-configs/view")) {
|
||||||
permissions["TENANT_CONFIGURATION"] = true;
|
permissions["TENANT_CONFIGURATION"] = true;
|
||||||
}
|
}
|
||||||
|
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/devices/list")) {
|
||||||
|
permissions["LIST_OWN_DEVICES"] = true;
|
||||||
|
}
|
||||||
|
|
||||||
return permissions;
|
return permissions;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user