User Authentication Implemented

This commit is contained in:
Luis Fernando Molina committed 2018-06-14 16:10:57 +02:00
1 parent 35cf0a50ce
commit 70ec8f0e90
6 files changed
+100 -59

No files matched your search

+55 -5
View File
@@ -1,23 +1,73 @@
exports.newUserAuthentication = function newUserAuthentication() {
MAX_STORAGE_PERMISSION_DAYS = 3;
let thisObject = {
authenticateUser: authenticateUser,
initialize: initialize
}
let serverConfig;
let sessionManager;
let storageAccessManager;
return thisObject;
function initialize(pServerConfig) {
function initialize(pSessionManager, pStorageAccessManager) {
serverConfig = pServerConfig;
sessionManager = pSessionManager;
storageAccessManager = pStorageAccessManager;
}
function authenticateUser(callBackFunction) {
function authenticateUser(pSessionToken, callBackFunction) {
callBackFunction(global.DEFAULT_OK_RESPONSE);
let userProfile = {
userName: "Guest",
devTeams: [],
storagePermissions: new Map()
};
/* The first possibility is that the sessionToken is not there. */
if (pSessionToken === "") {
callBackFunction(global.DEFAULT_OK_RESPONSE, userProfile);
return;
}
/* The second posiibility is that the session is not found. */
let session = sessionManager.getSession(sessionToken);
if (session === undefined) {
let customResponse = {
result: global.CUSTOM_FAIL_RESPONSE.result,
message: "Invalid session token received. Please login again."
};
callBackFunction(customResponse, userProfile);
return;
}
/* The last one is that the session is found, meaning valid. */
userProfile.userName = session.userName;
userProfile.devTeams = session.devTeams;
for (let i = 0; i < session.devTeams.lenght; i++) {
let devTeam = session.devTeams[i];
let readPermission = storageAccessManager.getPermission(devTeam, "READ", MAX_STORAGE_PERMISSION_DAYS);
let writePermission = storageAccessManager.getPermission(devTeam, "WRITE", MAX_STORAGE_PERMISSION_DAYS);
userProfile.storagePermissions.set(devTeam + "." + "READ", readPermission);
userProfile.storagePermissions.set(devTeam + "." + "WRITE", writePermission);
}
callBackFunction(global.DEFAULT_OK_RESPONSE, userProfile);
}
}
+6 -2
View File
@@ -52,9 +52,11 @@ function loadAdvancedAlgosPlatform() {
callServer(undefined, path, onServerReponded);
function onServerReponded(pResponse) {
function onServerReponded(pResponseFromServer) {
err = JSON.parse(pResponse);
let responseFromServer = JSON.parse(pResponseFromServer);
err = responseFromServer.err;
if (err.result !== GLOBAL.DEFAULT_OK_RESPONSE.result) {
@@ -63,6 +65,8 @@ function loadAdvancedAlgosPlatform() {
}
window.USER_PROFILE = responseFromServer.userProfile;
loadModules();
}
+26 -42
View File
@@ -1,7 +1,7 @@
exports.newStorageAccessManager = function newStorageAccessManager() {
let thisObject = {
getPermissions: getPermissions,
getPermission: getPermission,
initialize: initialize
}
@@ -34,7 +34,7 @@
}
}
function getPermissions(pTeams) {
function getPermission(pTeam, pType, pDays) {
let azure = require('azure-storage');
let blobService = azure.createBlobService(permissions.connectionString);
@@ -43,52 +43,36 @@
startDate.setDate(startDate.getDate() - 1);
let expiryDate = new Date(startDate);
expiryDate.setDate(startDate.getDate() + 3);
expiryDate.setDate(startDate.getDate() + pDays);
for (let i = 0; i < pTeams.length; i++) {
let azurePermissions;
let team = pTeams[i];
if (team.readConnectionString !== undefined) {
let azurePermissions = azure.BlobUtilities.SharedAccessPermissions.READ;
let container = team.codeName;
let blobName = undefined;
let sharedAccessPolicy = {
AccessPolicy: {
Permissions: azurePermissions,
Start: startDate,
Expiry: expiryDate
}
};
let sasToken = blobService.generateSharedAccessSignature(container, blobName, sharedAccessPolicy);
team.readConnectionString = "BlobEndpoint=https://aadevelop.blob.core.windows.net;SharedAccessSignature=" + sasToken + "";
switch (pType) {
case "READ": {
azurePermissions = azure.BlobUtilities.SharedAccessPermissions.READ;
break;
}
if (team.writeConnectionString !== undefined) {
let azurePermissions = azure.BlobUtilities.SharedAccessPermissions.WRITE;
let container = team.codeName;
let blobName = undefined;
let sharedAccessPolicy = {
AccessPolicy: {
Permissions: azurePermissions,
Start: startDate,
Expiry: expiryDate
}
};
let sasToken = blobService.generateSharedAccessSignature(container, blobName, sharedAccessPolicy);
team.readConnectionString = "BlobEndpoint=https://aadevelop.blob.core.windows.net;SharedAccessSignature=" + sasToken + "";
case "WRITE": {
azurePermissions = azure.BlobUtilities.SharedAccessPermissions.WRITE;
break;
}
}
let container = team.codeName;
let blobName = undefined;
let sharedAccessPolicy = {
AccessPolicy: {
Permissions: azurePermissions,
Start: startDate,
Expiry: expiryDate
}
};
let sasToken = blobService.generateSharedAccessSignature(container, blobName, sharedAccessPolicy);
return "BlobEndpoint=https://aadevelop.blob.core.windows.net;SharedAccessSignature=" + sasToken + "";
return pTeams;
}
}
+4 -3
View File
@@ -24,11 +24,12 @@ function newDevTeam() {
function initialize() {
window.DEV_TEAM = window.localStorage.getItem("devTeam");
if (window.DEV_TEAM === null) {
if (window.USER_PROFILE.devTeams.length === 0) {
window.DEV_TEAM = "Not a devTeam Member";
} else {
window.DEV_TEAM = window.USER_PROFILE.devTeams[0];
}
}
function getContainer(point) {
+1 -4
View File
@@ -24,11 +24,8 @@ function newEndUser() {
function initialize() {
window.USER_LOGGED_IN = window.localStorage.getItem("userName");
window.USER_LOGGED_IN = window.USER_PROFILE.userName;
if (window.USER_LOGGED_IN === null) {
window.USER_LOGGED_IN = "Guest User";
}
}
function getContainer(point) {
+8 -3
View File
@@ -465,11 +465,16 @@ function onBrowserRequest(request, response) {
let userAuthentication = AABROSER_API_USER_AUTHENTICATION.newUserAuthentication();
userAuthentication.initialize();
userAuthentication.authenticateUser(onFinish);
userAuthentication.authenticateUser(requestParameters[3], sessionManager, storageAccessManager, onFinish);
function onFinish(err) {
function onFinish(err, pUserProfile) {
respondWithContent(JSON.stringify(err), response);
let responseToBrowser = {
err: err,
userProfile: pUserProfile
};
respondWithContent(JSON.stringify(responseToBrowser), response);
}
break;