@ -1,17 +1,17 @@
/ *
/ *
* Copyright ( c ) 201 6 , WSO2 Inc . ( http : //www.wso2.org) All Rights Reserved.
* Copyright ( c ) 201 5 , WSO2 Inc . ( http : //www.wso2.org) All Rights Reserved.
*
*
* WSO2 Inc . licenses this file to you under the Apache License ,
* WSO2 Inc . licenses this file to you under the Apache License ,
* Version 2.0 ( the "License" ) ; you may not use this file except
* Version 2.0 ( the "License" ) ; you may not use this file except
* in compliance with the License .
* in compliance with the License .
* You may obtain a copy of the License at
* You may obtain a copy of the License at
*
*
* http : //www.apache.org/licenses/LICENSE-2.0
* http : //www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing ,
* Unless required by applicable law or agreed to in writing ,
* software distributed under the License is distributed on an
* software distributed under the License is distributed on an
* "AS IS" BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY
* "AS IS" BASIS , WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND ,
* KIND, either express or implied . See the License for the
* either express or implied . See the License for the
* specific language governing permissions and limitations
* specific language governing permissions and limitations
* under the License .
* under the License .
* /
* /
@ -25,32 +25,30 @@ var userModule = function () {
var constants = require ( "/app/modules/constants.js" ) ;
var constants = require ( "/app/modules/constants.js" ) ;
var utility = require ( "/app/modules/utility.js" ) [ "utility" ] ;
var utility = require ( "/app/modules/utility.js" ) [ "utility" ] ;
var devicemgtProps = require ( "/app/conf/devicemgt-props.js" ) . config ( ) ;
var devicemgtProps = require ( "/app/conf/devicemgt-props.js" ) . config ( ) ;
var serviceInvokers = require ( "/app/modules/backend-service-invoker.js" ) .backendServiceInvoker ;
var serviceInvokers = require ( "/app/modules/backend-service-invoker.js" ) ["backendServiceInvoker" ] ;
/* Initializing user manager */
/* Initializing user manager */
var carbon = require ( 'carbon' ) ;
var carbon = require ( "carbon" ) ;
var tenantId = carbon . server . tenantId ( ) ;
var url = carbon . server . address ( "https" ) + "/admin/services" ;
var url = carbon . server . address ( 'https' ) + "/admin/services" ;
var server = new carbon . server . Server ( url ) ;
var server = new carbon . server . Server ( url ) ;
var userManager = new carbon . user . UserManager ( server , tenantId ) ;
var deviceManagementService = utility . getDeviceManagementService ( ) ;
//var deviceManagementService = utility.getDeviceManagementService();
var EmailMessageProperties = Packages . org . wso2 . carbon . device . mgt . common . EmailMessageProperties ;
//var EmailMessageProperties = Packages.org.wso2.carbon.device.mgt.common.EmailMessageProperties;
var publicMethods = { } ;
var publicMethods = { } ;
var privateMethods = { } ;
var privateMethods = { } ;
/ * *
/ * *
* Get the carbon user object from the session . If not found - it will throw a user not found error .
* Get the carbon user object from the session . If not found - it will throw a user not found error .
* @ returns { carbon user object }
* @ returns { object} carbon user object
* /
* /
privateMethods . getCarbonUser = function ( ) {
privateMethods . getCarbonUser = function ( ) {
var carbon = require ( 'carbon' ) ;
var carbon = require ( "carbon" ) ;
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 ( "/modules/utility.js" ) [ "utility" ] ;
if ( ! carbonUser ) {
if ( ! carbonUser ) {
log . error ( "User object was not found in the session" ) ;
log . error ( "User object was not found in the session" ) ;
throw constants .ERRORS . USER _NOT _FOUND ;
throw constants ["ERRORS" ] [ "USER_NOT_FOUND" ] ;
}
}
return carbonUser ;
return carbonUser ;
} ;
} ;
@ -59,31 +57,25 @@ var userModule = function () {
* Only GET method is implemented for now since there are no other type of methods used this method .
* Only GET method is implemented for now since there are no other type of methods used this method .
* @ param url - URL to call the backend without the host
* @ param url - URL to call the backend without the host
* @ param method - HTTP Method ( GET , POST )
* @ param method - HTTP Method ( GET , POST )
* @ returns {
* @ returns An object with 'status' : 'success' | 'error' , 'content' : { }
* 'status' : 'success' | 'error' ,
* 'content' : { }
* }
* /
* /
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 if ( backendResponse . status == 400 || backendResponse . status == 401 ||
backendResponse . status == 404 || backendResponse . status == 500 ) {
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 ( "Runtime error : This method only support HTTP GET requests." ) ;
}
}
} ;
} ;
@ -101,43 +93,43 @@ var userModule = function () {
*
*
* @ returns { number } HTTP Status code 201 if succeeded , 409 if user already exists
* @ returns { number } HTTP Status code 201 if succeeded , 409 if user already exists
* /
* /
publicMethods . addUser = function ( username , firstname , lastname , emailAddress , userRoles ) {
// publicMethods.addUser = function (username, firstname, lastname, emailAddress, userRoles) {
var statusCode , carbon = require ( 'carbon' ) ;
// var statusCode, carbon = require("carbon");
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) {
log . error ( "User object was not found in the session" ) ;
// log.error("User object was not found in the session");
throw constants . ERRORS . USER _NOT _FOUND ;
// throw constants["ERRORS"]["USER_NOT_FOUND"];
}
// }
try {
// try {
utility . startTenantFlow ( carbonUser ) ;
// utility.startTenantFlow(carbonUser);
var tenantId = carbon . server . tenantId ( ) ;
// var tenantId = carbon.server.tenantId();
var userManager = new carbon . user . UserManager ( server , tenantId ) ;
// var userManager = new carbon.user.UserManager(server, tenantId);
if ( userManager . userExists ( username ) ) {
// if (userManager.userExists(username)) {
if ( log . isDebugEnabled ( ) ) {
// if (log.isDebugEnabled()) {
log . debug ( "A user with name '" + username + "' already exists." ) ;
// log.debug("A user with name '" + username + "' already exists.");
}
// }
// http status code 409 refers to - conflict.
// // http status code 409 refers to - conflict.
statusCode = 409 ;
// statusCode = 409;
} else {
// } else {
var initialUserPassword = privateMethods . generateInitialUserPassword ( ) ;
// var initialUserPassword = privateMethods.generateInitialUserPassword();
var defaultUserClaims = privateMethods . buildDefaultUserClaims ( firstname , lastname , emailAddress ) ;
// var defaultUserClaims = privateMethods.buildDefaultUserClaims(firstname, lastname, emailAddress);
//
userManager . addUser ( username , initialUserPassword , userRoles , defaultUserClaims , "default" ) ;
// userManager.addUser(username, initialUserPassword, userRoles, defaultUserClaims, "default");
privateMethods . inviteUserToEnroll ( username , initialUserPassword ) ;
// privateMethods.inviteUserToEnroll(username, initialUserPassword);
if ( log . isDebugEnabled ( ) ) {
// if (log.isDebugEnabled()) {
log . debug ( "A new user with name '" + username + "' was created." ) ;
// log.debug("A new user with name '" + username + "' was created.");
}
// }
// http status code 201 refers to - created.
// // http status code 201 refers to - created.
statusCode = 201 ;
// statusCode = 201;
}
// }
return statusCode ;
// return statusCode;
} catch ( e ) {
// } catch (e) {
throw e ;
// throw e;
} finally {
// } finally {
utility . endTenantFlow ( ) ;
// utility.endTenantFlow();
}
// }
} ;
// };
/ * *
/ * *
* Register user to dc - user - store .
* Register user to dc - user - store .
@ -188,39 +180,39 @@ var userModule = function () {
* @ param username Username of the user
* @ param username Username of the user
* @ returns { number } HTTP Status code 200 if succeeded , 409 if the user does not exist
* @ returns { number } HTTP Status code 200 if succeeded , 409 if the user does not exist
* /
* /
publicMethods . removeUser = function ( username ) {
// publicMethods.removeUser = function (username) {
var statusCode , carbon = require ( 'carbon' ) ;
// var statusCode, carbon = require('carbon');
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) {
log . error ( "User object was not found in the session" ) ;
// log.error("User object was not found in the session");
throw constants . ERRORS . USER _NOT _FOUND ;
// throw constants.ERRORS.USER_NOT_FOUND;
}
// }
try {
// try {
utility . startTenantFlow ( carbonUser ) ;
// utility.startTenantFlow(carbonUser);
var tenantId = carbon . server . tenantId ( ) ;
// var tenantId = carbon.server.tenantId();
var userManager = new carbon . user . UserManager ( server , tenantId ) ;
// var userManager = new carbon.user.UserManager(server, tenantId);
if ( userManager . userExists ( username ) ) {
// if (userManager.userExists(username)) {
userManager . removeUser ( username ) ;
// userManager.removeUser(username);
if ( log . isDebugEnabled ( ) ) {
// if (log.isDebugEnabled()) {
log . debug ( "An existing user with name '" + username + "' was removed." ) ;
// log.debug("An existing user with name '" + username + "' was removed.");
}
// }
// http status code 200 refers to - success.
// // http status code 200 refers to - success.
statusCode = 200 ;
// statusCode = 200;
} else {
// } else {
if ( log . isDebugEnabled ( ) ) {
// if (log.isDebugEnabled()) {
log . debug ( "A user with name '" + username + "' does not exist to remove." ) ;
// log.debug("A user with name '" + username + "' does not exist to remove.");
}
// }
// http status code 409 refers to - conflict.
// // http status code 409 refers to - conflict.
statusCode = 409 ;
// statusCode = 409;
}
// }
return statusCode ;
// return statusCode;
} catch ( e ) {
// } catch (e) {
throw e ;
// throw e;
} finally {
// } finally {
utility . endTenantFlow ( ) ;
// utility.endTenantFlow();
}
// }
} ;
// };
/ *
/ *
@ Deprecated
@ Deprecated
@ -232,25 +224,25 @@ var userModule = function () {
*
*
* @ returns { string } Initial User Password
* @ returns { string } Initial User Password
* /
* /
privateMethods . generateInitialUserPassword = function ( ) {
// privateMethods.generateInitialUserPassword = function () {
var passwordLength = 6 ;
// var passwordLength = 6;
//defining the pool of characters to be used for initial password generation
// //defining the pool of characters to be used for initial password generation
var lowerCaseCharset = "abcdefghijklmnopqrstuvwxyz" ;
// var lowerCaseCharset = "abcdefghijklmnopqrstuvwxyz";
var upperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
// var upperCaseCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var numericCharset = "0123456789" ;
// var numericCharset = "0123456789";
//
var totalCharset = lowerCaseCharset + upperCaseCharset + numericCharset ;
// var totalCharset = lowerCaseCharset + upperCaseCharset + numericCharset;
var totalCharsetLength = totalCharset . length ;
// var totalCharsetLength = totalCharset.length;
//
var initialUserPassword = "" ;
// var initialUserPassword = "";
for ( var i = 0 ; i < passwordLength ; ++ i ) {
// for (var i = 0; i < passwordLength; ++i) {
initialUserPassword += totalCharset . charAt ( Math . floor ( Math . random ( ) * totalCharsetLength ) ) ;
// initialUserPassword += totalCharset.charAt(Math.floor(Math.random() * totalCharsetLength));
}
// }
if ( log . isDebugEnabled ( ) ) {
// if (log.isDebugEnabled()) {
log . debug ( "Initial password created for new user : " + initialUserPassword ) ;
// log.debug("Initial password created for new user : " + initialUserPassword);
}
// }
return String ( initialUserPassword ) ;
// return String(initialUserPassword);
} ;
// };
/ *
/ *
@ Deprecated
@ Deprecated
@ -264,17 +256,17 @@ var userModule = function () {
*
*
* @ returns { Object } Default user claims to be provided
* @ returns { Object } Default user claims to be provided
* /
* /
privateMethods . buildDefaultUserClaims = function ( firstname , lastname , emailAddress ) {
// privateMethods.buildDefaultUserClaims = function (firstname, lastname, emailAddress) {
var defaultUserClaims = {
// var defaultUserClaims = {
"http://wso2.org/claims/givenname" : firstname ,
// "http://wso2.org/claims/givenname": firstname,
"http://wso2.org/claims/lastname" : lastname ,
// "http://wso2.org/claims/lastname": lastname,
"http://wso2.org/claims/emailaddress" : emailAddress
// "http://wso2.org/claims/emailaddress": emailAddress
} ;
// };
if ( log . isDebugEnabled ( ) ) {
// if (log.isDebugEnabled()) {
log . debug ( "ClaimMap created for new user : " + stringify ( defaultUserClaims ) ) ;
// log.debug("ClaimMap created for new user : " + stringify(defaultUserClaims));
}
// }
return defaultUserClaims ;
// return defaultUserClaims;
} ;
// };
/ *
/ *
@ Deprecated
@ Deprecated
@ -286,89 +278,89 @@ var userModule = function () {
* @ param username Username of the user
* @ param username Username of the user
* @ param password Password of the user
* @ param password Password of the user
* /
* /
privateMethods . inviteUserToEnroll = function ( username , password ) {
// privateMethods.inviteUserToEnroll = function (username, password) {
var carbon = require ( 'carbon' ) ;
// var carbon = require('carbon');
var enrollmentURL = devicemgtProps . generalConfig . host + devicemgtProps . webAgentContext + "download-agent" ;
// var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent";
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) {
log . error ( "User object was not found in the session" ) ;
// log.error("User object was not found in the session");
throw constants . ERRORS . USER _NOT _FOUND ;
// throw constants.ERRORS.USER_NOT_FOUND;
}
// }
//var user = userManagementService.getUser(username, carbonUser.tenantId);
// //var user = userManagementService.getUser(username, carbonUser.tenantId);
try {
// try {
utility . startTenantFlow ( carbonUser ) ;
// utility.startTenantFlow(carbonUser);
var tenantId = carbon . server . tenantId ( ) ;
// var tenantId = carbon.server.tenantId();
var userManager = new carbon . user . UserManager ( server , tenantId ) ;
// var userManager = new carbon.user.UserManager(server, tenantId);
var emailTo = [ ] ;
// var emailTo = [];
var user = userManager . getUser ( username ) ;
// var user = userManager.getUser(username);
emailTo [ 0 ] = privateMethods . getEmail ( username , userManager ) ;
// emailTo[0] = privateMethods.getEmail(username, userManager);
var emailMessageProperties = new EmailMessageProperties ( ) ;
// var emailMessageProperties = new EmailMessageProperties();
emailMessageProperties . setMailTo ( emailTo ) ;
// emailMessageProperties.setMailTo(emailTo);
emailMessageProperties . setFirstName ( privateMethods . getFirstName ( username , userManager ) ) ;
// emailMessageProperties.setFirstName(privateMethods.getFirstName(username, userManager));
emailMessageProperties . setUserName ( username ) ;
// emailMessageProperties.setUserName(username);
emailMessageProperties . setPassword ( password ) ;
// emailMessageProperties.setPassword(password);
emailMessageProperties . setEnrolmentUrl ( enrollmentURL ) ;
// emailMessageProperties.setEnrolmentUrl(enrollmentURL);
deviceManagementService . sendRegistrationEmail ( emailMessageProperties ) ;
// deviceManagementService.sendRegistrationEmail(emailMessageProperties);
} catch ( e ) {
// } catch (e) {
throw e ;
// throw e;
} finally {
// } finally {
utility . endTenantFlow ( ) ;
// utility.endTenantFlow();
}
// }
} ;
// };
/ *
/ *
@ Deprecated
@ Deprecated
* /
* /
privateMethods . getEmail = function ( username , userManager ) {
// privateMethods.getEmail = function (username, userManager) {
return userManager . getClaim ( username , "http://wso2.org/claims/emailaddress" , null )
// return userManager.getClaim(username, "http://wso2.org/claims/emailaddress", null)
} ;
// };
/ *
/ *
@ Deprecated
@ Deprecated
* /
* /
privateMethods . getFirstName = function ( username , userManager ) {
// privateMethods.getFirstName = function (username, userManager) {
return userManager . getClaim ( username , "http://wso2.org/claims/givenname" , null )
// return userManager.getClaim(username, "http://wso2.org/claims/givenname", null)
} ;
// };
/ *
/ *
@ Deprecated
@ Deprecated
* /
* /
privateMethods . getLastName = function ( username , userManager ) {
// privateMethods.getLastName = function (username, userManager) {
return userManager . getClaim ( username , "http://wso2.org/claims/lastname" , null )
// return userManager.getClaim(username, "http://wso2.org/claims/lastname", null)
} ;
// };
/ *
/ *
@ Deprecated
@ Deprecated
* /
* /
publicMethods . inviteUser = function ( username ) {
// publicMethods.inviteUser = function (username) {
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) {
log . error ( "User object was not found in the session" ) ;
// log.error("User object was not found in the session");
throw constants . ERRORS . USER _NOT _FOUND ;
// throw constants.ERRORS.USER_NOT_FOUND;
}
// }
var enrollmentURL = devicemgtProps . generalConfig . host + devicemgtProps . webAgentContext + "download-agent" ;
// var enrollmentURL = devicemgtProps.generalConfig.host + devicemgtProps.webAgentContext + "download-agent";
//
try {
// try {
utility . startTenantFlow ( carbonUser ) ;
// utility.startTenantFlow(carbonUser);
var tenantId = carbon . server . tenantId ( ) ;
// var tenantId = carbon.server.tenantId();
var userManager = new carbon . user . UserManager ( server , tenantId ) ;
// var userManager = new carbon.user.UserManager(server, tenantId);
var user = userManager . getUser ( username ) ;
// var user = userManager.getUser(username);
var emailProperties = new EmailMessageProperties ( ) ;
// var emailProperties = new EmailMessageProperties();
var emailTo = [ ] ;
// var emailTo = [];
emailTo [ 0 ] = privateMethods . getEmail ( username , userManager ) ;
// emailTo[0] = privateMethods.getEmail(username, userManager);
emailProperties . setMailTo ( emailTo ) ;
// emailProperties.setMailTo(emailTo);
//emailProperties.setFirstName(user.getFirstName());
// //emailProperties.setFirstName(user.getFirstName());
emailProperties . setFirstName ( privateMethods . getFirstName ( username , userManager ) ) ;
// emailProperties.setFirstName(privateMethods.getFirstName(username, userManager));
emailProperties . setEnrolmentUrl ( enrollmentURL ) ;
// emailProperties.setEnrolmentUrl(enrollmentURL);
deviceManagementService . sendEnrolmentInvitation ( emailProperties ) ;
// deviceManagementService.sendEnrolmentInvitation(emailProperties);
} catch ( e ) {
// } catch (e) {
throw e ;
// throw e;
} finally {
// } finally {
utility . endTenantFlow ( ) ;
// utility.endTenantFlow();
}
// }
} ;
// };
/ *
/ *
@ Updated
@ Updated
@ -382,9 +374,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" ] + devicemgtProps [ "backendRestEndpoints" ] [ "deviceMgt" ] + "/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 {
@ -395,22 +390,16 @@ var userModule = function () {
/ * *
/ * *
* Return a User object from the backend by calling the JAX - RS
* Return a User object from the backend by calling the JAX - RS
* @ param username
* @ param username
* @ returns {
* @ returns { object } a response object with status and content on success .
* 'status' : 'success' | 'error' ,
* 'content' : {
"username" : "abc" ,
"firstname" : "abc" ,
"lastname" : "efj" ,
"emailAddress" : "abc@abc.com"
}
* }
* /
* /
publicMethods . getUser = function ( username ) {
publicMethods . getUser = 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/view?username=" + username ;
var url = devicemgtProps [ "httpsURL" ] + devicemgtProps [ "backendRestEndpoints" ] [ "deviceMgt" ] + "/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 ) {
@ -419,18 +408,19 @@ var userModule = function () {
utility . endTenantFlow ( ) ;
utility . endTenantFlow ( ) ;
}
}
} ;
} ;
/ * *
/ * *
* 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" ] + devicemgtProps[ "backendRestEndpoints" ] [ "deviceMgt" ] + "/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 {
@ -450,8 +440,8 @@ var userModule = function () {
}
}
try {
try {
utility . startTenantFlow ( carbonUser ) ;
utility . startTenantFlow ( carbonUser ) ;
var url = devicemgtProps [ "httpsURL" ] + constants . ADMIN _SERVICE _CONTEXT + " /users/users-by-username";
var url = devicemgtProps [ "httpsURL" ] + " /mdm-admin /users/users-by-username";
return privateMethods . callBackend ( url , constants .HTTP _GET )
return privateMethods . callBackend ( url , constants ["HTTP_GET" ] ) ;
} catch ( e ) {
} catch ( e ) {
throw e ;
throw e ;
} finally {
} finally {
@ -467,15 +457,19 @@ var userModule = function () {
* /
* /
publicMethods . getRoles = function ( ) {
publicMethods . getRoles = function ( ) {
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 ) {
log . error ( "User object was not found in the session" ) ;
log . error ( "User object was not found in the session" ) ;
throw constants [ "ERRORS" ] [ "USER_NOT_FOUND" ] ;
throw constants [ "ERRORS" ] [ "USER_NOT_FOUND" ] ;
}
}
try {
try {
utility . startTenantFlow ( carbonUser ) ;
utility . startTenantFlow ( carbonUser ) ;
var url = devicemgtProps [ "httpsURL" ] + constants . ADMIN _SERVICE _CONTEXT + "/roles" ;
var url = devicemgtProps [ "httpsURL" ] + devicemgtProps [ "backendRestEndpoints" ] [ "deviceMgt" ] + "/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,18 +482,24 @@ 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 ) {
log . error ( "User object was not found in the session" ) ;
log . error ( "User object was not found in the session" ) ;
throw constants [ "ERRORS" ] [ "USER_NOT_FOUND" ] ;
throw constants [ "ERRORS" ] [ "USER_NOT_FOUND" ] ;
}
}
try {
try {
utility . startTenantFlow ( carbonUser ) ;
utility . startTenantFlow ( carbonUser ) ;
var url = devicemgtProps [ "httpsURL" ] + constants . ADMIN _SERVICE _CONTEXT + "/roles/" + encodeURIComponent ( userStore ) ;
var url = devicemgtProps [ "httpsURL" ] + devicemgtProps [ "backendRestEndpoints" ] [ "deviceMgt" ] + "/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 {
@ -510,17 +510,22 @@ var userModule = function () {
/ * *
/ * *
* Get Platforms .
* Get Platforms .
* /
* /
//TODO Move this piece of logic out of user.js to somewhere else appropriate.
publicMethods . getPlatforms = function ( ) {
publicMethods . getPlatforms = function ( ) {
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 ) {
log . error ( "User object was not found in the session" ) ;
log . error ( "User object was not found in the session" ) ;
throw constants [ "ERRORS" ] [ "USER_NOT_FOUND" ] ;
throw constants [ "ERRORS" ] [ "USER_NOT_FOUND" ] ;
}
}
try {
try {
utility . startTenantFlow ( carbonUser ) ;
utility . startTenantFlow ( carbonUser ) ;
var url = devicemgtProps [ "httpsURL" ] + constants . ADMIN _SERVICE _CONTEXT + "/devices/types" ;
var url = devicemgtProps [ "httpsURL" ] + devicemgtProps [ "backendRestEndpoints" ] [ "deviceMgt" ] + "/admin/device-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 {
@ -535,15 +540,17 @@ var userModule = function () {
* /
* /
publicMethods . getRole = function ( roleName ) {
publicMethods . getRole = function ( roleName ) {
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 ) {
log . error ( "User object was not found in the session" ) ;
log . error ( "User object was not found in the session" ) ;
throw constants [ "ERRORS" ] [ "USER_NOT_FOUND" ] ;
throw constants [ "ERRORS" ] [ "USER_NOT_FOUND" ] ;
}
}
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" ] + devicemgtProps [ "backendRestEndpoints" ] [ "deviceMgt" ] +
var response = privateMethods . callBackend ( url , constants . HTTP _GET ) ;
"/roles/" + encodeURIComponent ( roleName ) ;
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 ;
@ -776,24 +783,29 @@ var userModule = function () {
* retrieve secondary user stores .
* retrieve secondary user stores .
* This needs Authentication since the method access admin services .
* This needs Authentication since the method access admin services .
*
*
* @ returns { string array } Array of secondary user stores .
* @ returns Array of secondary user stores .
* /
* /
publicMethods . getSecondaryUserStores = function ( ) {
publicMethods . getSecondaryUserStores = function ( ) {
var returnVal = [ ] ;
var returnVal = [ ] ;
var endpoint = devicemgtProps .adminService + constants . USER _STORE _CONFIG _ADMIN _SERVICE _END _POINT ;
var endpoint = devicemgtProps ["adminService" ] + constants [ "USER_STORE_CONFIG_ADMIN_SERVICE_END_POINT" ] ;
var wsPayload = "<xsd:getSecondaryRealmConfigurations xmlns:xsd='http://org.apache.axis2/xsd'/>" ;
var wsPayload = "<xsd:getSecondaryRealmConfigurations xmlns:xsd='http://org.apache.axis2/xsd'/>" ;
serviceInvokers . WS . soapRequest (
serviceInvokers . WS . soapRequest (
"urn:getSecondaryRealmConfigurations" , endpoint , wsPayload , function ( wsResponse ) {
"urn:getSecondaryRealmConfigurations" ,
wsPayload ,
endpoint ,
function ( wsResponse ) {
var domainIDs = stringify ( wsResponse . * : : [ 'return' ] . * : : domainId . text ( ) ) ;
var domainIDs = stringify ( wsResponse . * : : [ 'return' ] . * : : domainId . text ( ) ) ;
if ( domainIDs != "\"\"" ) {
if ( domainIDs != "\"\"" ) {
var regExpForSearch = new RegExp ( constants . USER _STORES _NOISY _CHAR , "g" ) ;
var regExpForSearch = new RegExp ( constants ["USER_STORES_NOISY_CHAR" ] , "g" ) ;
domainIDs = domainIDs . replace ( regExpForSearch , "" ) ;
domainIDs = domainIDs . replace ( regExpForSearch , "" ) ;
returnVal = domainIDs . split ( constants .USER _STORES _SPLITTING _CHAR ) ;
returnVal = domainIDs . split ( constants ["USER_STORES_SPLITTING_CHAR" ] ) ;
}
}
} , function ( e ) {
} , function ( e ) {
log . error ( "Error retrieving secondary user stores" , e ) ;
log . error ( "Error retrieving secondary user stores" , e ) ;
} , constants . SOAP _VERSION ) ;
} ,
constants [ "SOAP_VERSION" ] ) ;
return returnVal ;
return returnVal ;
} ;
} ;
return publicMethods ;
return publicMethods ;
} ( ) ;
} ( ) ;