Skip to content

Commit

Permalink
Merge pull request #218 from TAMULib/2022_dec-217-authfix
Browse files Browse the repository at this point in the history
Issue 217: Weaver authentication is making unsafe assumptions on the data and failing out incorrectly.
  • Loading branch information
kaladay authored Dec 8, 2022
2 parents e991e33 + 2a1bbd9 commit 355d882
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions app/services/userService.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,24 @@ core.service("UserService", function ($q, StorageService, User, WsApi) {

UserService.fetchUser = function () {
userEvents.notify('FETCH');

return WsApi.fetch(currentUser.getMapping().instantiate).then(function (res) {
delete sessionStorage.role;
var credentials = angular.fromJson(res.body).payload.Credentials;
currentUser.anonymous = credentials.role === appConfig.anonymousRole ? true : false;
var body = !!res && !!res.body ? angular.fromJson(res.body) : {};
var credentials = { role: !!currentUser.role ? currentUser.role : appConfig.anonymousRole };

// Only change credentials when packet structure is valid.
if (!!body && !!body.payload && !!body.payload.Credentials) {
delete sessionStorage.role;
credentials = angular.fromJson(res.body).payload.Credentials;
}

currentUser.anonymous = !credentials.role || credentials.role === appConfig.anonymousRole;

// Cannot have a token for the anonymous role.
if (currentUser.anonymous) {
StorageService.delete("token");
}

angular.extend(currentUser, credentials);
StorageService.set("role", currentUser.role);
userEvents.notify('RECEIVED');
Expand Down

0 comments on commit 355d882

Please sign in to comment.