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

[ZEPPELIN-3129] Zepplin UI Doesnt logs out in IE #2721

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 64 additions & 3 deletions zeppelin-web/src/components/navbar/navbar.controller.js
Expand Up @@ -89,17 +89,52 @@ function NavCtrl ($scope, $rootScope, $http, $routeParams, $location,
function logout() {
let logoutURL = baseUrlSrv.getRestApiBase() + '/login/logout'

// for firefox and safari
logoutURL = logoutURL.replace('//', '//false:false@')

$http.post(logoutURL).then(function () {}, function (response) {
if (response.data) {
let res = angular.fromJson(response.data).body
if (res['redirectURL']) {
window.location.href = res['redirectURL'] + window.location.href
}
}

// force authcBasic (if configured) to logout
if (detectIE()) {
let outcome
try {
outcome = document.execCommand('ClearAuthenticationCache')
} catch (e) {
console.log(e)
}
if (!outcome) {
// Let's create an xmlhttp object
outcome = (function (x) {
if (x) {
// the reason we use "random" value for password is
// that browsers cache requests. changing
// password effectively behaves like cache-busing.
x.open('HEAD', location.href, true, 'logout',
(new Date()).getTime().toString())
x.send('')
// x.abort()
return 1 // this is **speculative** "We are done."
} else {
// eslint-disable-next-line no-useless-return
return
}
})(window.XMLHttpRequest ? new window.XMLHttpRequest()
// eslint-disable-next-line no-undef
: (window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : u))
}
if (!outcome) {
let m = 'Your browser is too old or too weird to support log out functionality. Close all windows and ' +
'restart the browser.'
alert(m)
}
} else {
// for firefox and safari
logoutURL = logoutURL.replace('//', '//false:false@')
}

$http.post(logoutURL).error(function () {
$rootScope.userName = ''
$rootScope.ticket.principal = ''
Expand All @@ -116,6 +151,32 @@ function NavCtrl ($scope, $rootScope, $http, $routeParams, $location,
})
}

function detectIE() {
let ua = window.navigator.userAgent

let msie = ua.indexOf('MSIE ')
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10)
}

let trident = ua.indexOf('Trident/')
if (trident > 0) {
// IE 11 => return version number
let rv = ua.indexOf('rv:')
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10)
}

let edge = ua.indexOf('Edge/')
if (edge > 0) {
// Edge (IE 12+) => return version number
return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10)
}

// other browser
return false
}

function search (searchTerm) {
$location.path('/search/' + searchTerm)
}
Expand Down