Skip to content

Commit

Permalink
Reconfigure unsuccessful login attempt to purge user session
Browse files Browse the repository at this point in the history
Delete X-Miq-Group header when purging session
  • Loading branch information
AllenBW committed Oct 6, 2017
1 parent 64b072a commit 7850d2c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
1 change: 1 addition & 0 deletions client/app/core/session.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export function SessionFactory ($http, $q, $sessionStorage, $cookies, RBAC, Poll
model.token = null
model.user = {}
destroyWsToken()
delete $http.defaults.headers.common['X-Miq-Group']
delete $http.defaults.headers.common['X-Auth-Token']
delete $sessionStorage.miqGroup
delete $sessionStorage.selectedMiqGroup
Expand Down
52 changes: 28 additions & 24 deletions client/app/states/login/login.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,20 @@ function getStates () {
}

/** @ngInject */
function StateController (exception, $state, Text, RBAC, API_LOGIN, API_PASSWORD, AuthenticationApi,
Session, $rootScope, Notifications, Language, ApplianceInfo, $window) {
var vm = this
function StateController (exception, $state, Text, RBAC, API_LOGIN, API_PASSWORD, AuthenticationApi, Session,
$rootScope, Notifications, Language, ApplianceInfo, $window) {
const vm = this

vm.text = Text.login

vm.credentials = {
login: API_LOGIN,
password: API_PASSWORD
}
vm.onSubmit = onSubmit

if ($window.location.href.includes('?timeout')) {
Notifications.message('danger', '', __('Your session has timed out.'), true)
Session.destroy()
}

if ($window.location.href.includes('?pause')) {
Expand All @@ -45,34 +46,37 @@ function StateController (exception, $state, Text, RBAC, API_LOGIN, API_PASSWORD

if (Session.privilegesError) {
Notifications.error(__('User does not have privileges to login.'))
Session.destroy()
}

vm.onSubmit = onSubmit

function onSubmit () {
Session.timeoutNotified = false
Session.privilegesError = false

return AuthenticationApi.login(vm.credentials.login, vm.credentials.password)
.then(Session.loadUser)
.then(Session.requestWsToken)
.then(function (response) {
if (angular.isDefined(response)) {
Language.onLogin(response)
ApplianceInfo.set(response)
RBAC.setRole(response.identity.role)
}
.then(Session.loadUser)
.then(Session.requestWsToken)
.then((response) => {
if (angular.isDefined(response)) {
Language.onLogin(response)
ApplianceInfo.set(response)
RBAC.setRole(response.identity.role)
}

if (RBAC.navigationEnabled()) {
if (angular.isDefined($rootScope.notifications) && $rootScope.notifications.data.length > 0) {
$rootScope.notifications.data.splice(0, $rootScope.notifications.data.length)
}
$window.location.href = $state.href('dashboard')
} else {
Session.privilegesError = true
Notifications.error(__('You do not have permission to view the Service UI. Contact your administrator to update your group permissions.'))
if (RBAC.navigationEnabled()) {
if (angular.isDefined($rootScope.notifications) && $rootScope.notifications.data.length > 0) {
$rootScope.notifications.data.splice(0, $rootScope.notifications.data.length)
}
})
.catch(exception.catch('Login failed, possibly invalid credentials.'))
$window.location.href = $state.href('dashboard')
} else {
Session.privilegesError = true
Notifications.error(__('You do not have permission to view the Service UI. Contact your administrator to update your group permissions.'))
Session.destroy()
}
})
.catch(() => {
exception.catch('Login failed, possibly invalid credentials.')
Session.destroy()
})
}
}
30 changes: 13 additions & 17 deletions client/app/states/login/login.state.spec.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
describe('State: login', () => {
beforeEach(() => {
module('app.states');
});
module('app.states')
})

describe('controller', () => {
let ctrl;
let ctrl

beforeEach(() => {
bard.inject('$controller', '$state', '$stateParams', 'Session', '$window', 'API_LOGIN', 'API_PASSWORD');
bard.inject('$controller', '$state', '$stateParams', 'Session', '$window', 'API_LOGIN', 'API_PASSWORD')

ctrl = $controller($state.get('login').controller, {
Session: {
privilegesError: true
}
});
});
ctrl = $controller($state.get('login').controller, {})
})

describe('controller initialization', () => {
it('is created successfully', () => {
expect(ctrl).to.be.defined;
});
expect(ctrl).to.be.defined
})

it('sets app brand', () => {
expect(ctrl.text.brand).to.equal('<strong>ManageIQ</strong> Service UI');
});
});
});
});
expect(ctrl.text.brand).to.equal('<strong>ManageIQ</strong> Service UI')
})
})
})
})

0 comments on commit 7850d2c

Please sign in to comment.