X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=sdnr%2Fwireless-transport%2Fcode-Carbon-SR1%2Fapps%2Fdlux%2Fdlux-web%2Fsrc%2Fapp%2FroutingConfig.js;fp=sdnr%2Fwireless-transport%2Fcode-Carbon-SR1%2Fapps%2Fdlux%2Fdlux-web%2Fsrc%2Fapp%2FroutingConfig.js;h=3e0ee90ab7dadefc676823f21937000fa4aeddc5;hb=27fb2d06608fbb070ae2c15a5580a4f5b2423d15;hp=0000000000000000000000000000000000000000;hpb=60315525ab5e7c12a9f47c409092e8dba6ad656d;p=ccsdk%2Fapps.git diff --git a/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/app/routingConfig.js b/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/app/routingConfig.js new file mode 100644 index 00000000..3e0ee90a --- /dev/null +++ b/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/app/routingConfig.js @@ -0,0 +1,103 @@ +(function(exports){ + + var config = { + + /* List all the roles you wish to use in the app + * You have a max of 31 before the bit shift pushes the accompanying integer out of + * the memory footprint for an integer + */ + roles :[ + 'public', + 'user', + 'admin'], + + /* + Build out all the access levels you want referencing the roles listed above + You can use the "*" symbol to represent access to all roles + */ + accessLevels : { + 'public' : "*", + 'anon': ['public'], + 'user' : ['user', 'admin'], + 'admin': ['admin'] + } + + }; + + exports.userRoles = buildRoles(config.roles); + exports.accessLevels = buildAccessLevels(config.accessLevels, exports.userRoles); + + /* + Method to build a distinct bit mask for each role + It starts off with "1" and shifts the bit to the left for each element in the + roles array parameter + */ + + function buildRoles(roles){ + + var bitMask = "01"; + var userRoles = {}; + + for(var role in roles){ + var intCode = parseInt(bitMask, 2); + userRoles[roles[role]] = { + bitMask: intCode, + title: roles[role] + }; + bitMask = (intCode << 1 ).toString(2); + } + + return userRoles; + } + + /* + This method builds access level bit masks based on the accessLevelDeclaration parameter which must + contain an array for each access level containing the allowed user roles. + */ + function buildAccessLevels(accessLevelDeclarations, userRoles){ + + var accessLevels = {}; + var resultBitMask = ''; + for(var level in accessLevelDeclarations){ + + if(typeof accessLevelDeclarations[level] == 'string'){ + if(accessLevelDeclarations[level] == '*'){ + + resultBitMask = ''; + + for( var roleTemp in userRoles){ + resultBitMask += "1"; + } + //accessLevels[level] = parseInt(resultBitMask, 2); + accessLevels[level] = { + bitMask: parseInt(resultBitMask, 2), + title: accessLevelDeclarations[level] + }; + } + else { + console.log("Access Control Error: Could not parse '" + accessLevelDeclarations[level] + "' as access definition for level '" + level + "'"); + } + + } + else { + + resultBitMask = 0; + for(var role in accessLevelDeclarations[level]){ + if(userRoles.hasOwnProperty(accessLevelDeclarations[level][role])) { + resultBitMask = resultBitMask | userRoles[accessLevelDeclarations[level][role]].bitMask; + } + else { + console.log("Access Control Error: Could not find role '" + accessLevelDeclarations[level][role] + "' in registered roles while building access for '" + level + "'"); + } + } + accessLevels[level] = { + bitMask: resultBitMask, + title: accessLevelDeclarations[level][role] + }; + } + } + + return accessLevels; + } + +})(typeof exports === 'undefined' ? this['routingConfig'] = {} : exports); \ No newline at end of file