Repository: zeppelin
Updated Branches:
  refs/heads/master eb84aa22d -> 89b71ca03


[ZEPPELIN-1125] Application does not logout user when authcBasic and `./grunt 
serve` is used

### What is this PR for?
Creating this issue from 
[this](https://github.com/apache/zeppelin/pull/1071#issuecomment-230720461) 
comment, Application does not logout user when authcBasic is used and process 
was running with `grunt serve`

### What type of PR is it?
[Bug Fix]

### What is the Jira issue?
* [ZEPPELIN-1125](https://issues.apache.org/jira/browse/ZEPPELIN-1125)

### How should this be tested?
Run web-app as `grunt serve` and configure shiro auth to use `authcBasic`, and 
then try to logout.

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no

Author: Prabhjyot Singh <[email protected]>

Closes #1140 from prabhjyotsingh/ZEPPELIN-1125 and squashes the following 
commits:

04a2aff [Prabhjyot Singh] remove unrequired params from response, revert to post
986d549 [Prabhjyot Singh] Application does not logout user when authcBasic and 
running on a different host/port


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/89b71ca0
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/89b71ca0
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/89b71ca0

Branch: refs/heads/master
Commit: 89b71ca03c4ec903c0c7d1e2c03443af3de3b2f7
Parents: eb84aa2
Author: Prabhjyot Singh <[email protected]>
Authored: Fri Jul 8 14:42:53 2016 +0530
Committer: Prabhjyot Singh <[email protected]>
Committed: Mon Jul 18 10:56:51 2016 +0530

----------------------------------------------------------------------
 .../org/apache/zeppelin/rest/LoginRestApi.java  | 12 +-----
 .../src/components/navbar/navbar.controller.js  | 42 +++++++++-----------
 2 files changed, 20 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/89b71ca0/zeppelin-server/src/main/java/org/apache/zeppelin/rest/LoginRestApi.java
----------------------------------------------------------------------
diff --git 
a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/LoginRestApi.java 
b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/LoginRestApi.java
index 0b9c9a6..0a23922 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/LoginRestApi.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/LoginRestApi.java
@@ -17,7 +17,6 @@
 package org.apache.zeppelin.rest;
 
 import org.apache.shiro.authc.*;
-import org.apache.shiro.session.Session;
 import org.apache.shiro.subject.Subject;
 import org.apache.zeppelin.annotation.ZeppelinApi;
 import org.apache.zeppelin.server.JsonResponse;
@@ -112,22 +111,15 @@ public class LoginRestApi {
     LOG.warn(response.toString());
     return response.build();
   }
-  
+
   @POST
   @Path("logout")
   @ZeppelinApi
   public Response logout() {
     JsonResponse response;
-    
     Subject currentUser = org.apache.shiro.SecurityUtils.getSubject();
     currentUser.logout();
-
-    Map<String, String> data = new HashMap<>();
-    data.put("principal", "anonymous");
-    data.put("roles", "");
-    data.put("ticket", "anonymous");
-   
-    response = new JsonResponse(Response.Status.OK, "", data);
+    response = new JsonResponse(Response.Status.UNAUTHORIZED, "", "");
     LOG.warn(response.toString());
     return response.build();
   }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/89b71ca0/zeppelin-web/src/components/navbar/navbar.controller.js
----------------------------------------------------------------------
diff --git a/zeppelin-web/src/components/navbar/navbar.controller.js 
b/zeppelin-web/src/components/navbar/navbar.controller.js
index 89faada..594356e 100644
--- a/zeppelin-web/src/components/navbar/navbar.controller.js
+++ b/zeppelin-web/src/components/navbar/navbar.controller.js
@@ -54,30 +54,24 @@ angular.module('zeppelinWebApp')
 
   $scope.logout = function() {
     var logoutURL = baseUrlSrv.getRestApiBase() + '/login/logout';
-    var request = new XMLHttpRequest();
-
-    //force authcBasic (if configured) to logout by setting credentials as 
false:false
-    request.open('post', logoutURL, true, 'false', 'false');
-    request.onreadystatechange = function() {
-      if (request.readyState === 4) {
-        if (request.status === 401 || request.status === 405 || request.status 
=== 500) {
-          $rootScope.userName = '';
-          $rootScope.ticket.principal = '';
-          $rootScope.ticket.ticket = '';
-          $rootScope.ticket.roles = '';
-          BootstrapDialog.show({
-            message: 'Logout Success'
-          });
-          setTimeout(function() {
-            window.location.replace('/');
-          }, 1000);
-        } else {
-          request.open('post', logoutURL, true, 'false', 'false');
-          request.send();
-        }
-      }
-    };
-    request.send();
+
+    //for firefox and safari
+    logoutURL = logoutURL.replace('//', '//false:false@');
+    $http.post(logoutURL).error(function() {
+      //force authcBasic (if configured) to logout
+      $http.post(logoutURL).error(function() {
+        $rootScope.userName = '';
+        $rootScope.ticket.principal = '';
+        $rootScope.ticket.ticket = '';
+        $rootScope.ticket.roles = '';
+        BootstrapDialog.show({
+          message: 'Logout Success'
+        });
+        setTimeout(function() {
+          window.location.replace('/');
+        }, 1000);
+      });
+    });
   };
 
   $scope.search = function(searchTerm) {

Reply via email to