Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BZ#1498984-DB/LDAP User is not able to log into SSUI #1061

Merged
merged 1 commit into from
Oct 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
})
}
}
41 changes: 22 additions & 19 deletions client/app/states/login/login.state.spec.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
describe('State: login', () => {
let failureNotificationSpy
beforeEach(() => {
module('app.states');
});
module('app.states')

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

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

ctrl = $controller($state.get('login').controller, {
Session: {
privilegesError: true
}
});
});
bard.inject('$controller', '$state', '$stateParams', 'Session', '$window', 'API_LOGIN', 'API_PASSWORD', 'EventNotifications')
failureNotificationSpy = sinon.spy(EventNotifications, 'error')
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')
})

it('sets session timeoutNotified and privilegesError', () => {
ctrl.onSubmit()
expect(Session.timeoutNotified).to.be.false
expect(Session.privilegesError).to.be.false
})
})
})
})