ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smoha...@apache.org
Subject ambari git commit: AMBARI-12131. API to return information regarding the current user who is logged in (for SSO) (smohanty)
Date Thu, 25 Jun 2015 16:03:48 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk d9ecee017 -> 287b7cfde


AMBARI-12131. API to return information regarding the current user who is logged in (for SSO)
(smohanty)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/287b7cfd
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/287b7cfd
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/287b7cfd

Branch: refs/heads/trunk
Commit: 287b7cfde8f261e4c83c527531eb1cbaa774523c
Parents: d9ecee0
Author: Sumit Mohanty <smohanty@hortonworks.com>
Authored: Thu Jun 25 09:03:38 2015 -0700
Committer: Sumit Mohanty <smohanty@hortonworks.com>
Committed: Thu Jun 25 09:03:38 2015 -0700

----------------------------------------------------------------------
 .../authorization/AmbariAuthorizationFilter.java |  3 +++
 .../AmbariAuthorizationFilterTest.java           | 19 +++++++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/287b7cfd/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java
b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java
index d14cc78..5a12d64 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilter.java
@@ -175,6 +175,9 @@ public class AmbariAuthorizationFilter implements Filter {
       }
     }
 
+    if(AuthorizationHelper.getAuthenticatedName() != null) {
+      httpResponse.setHeader("User", AuthorizationHelper.getAuthenticatedName());
+    }
     chain.doFilter(request, response);
   }
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/287b7cfd/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java
index a5df47f..20cc527 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/security/authorization/AmbariAuthorizationFilterTest.java
@@ -21,6 +21,8 @@ package org.apache.ambari.server.security.authorization;
 import static org.easymock.EasyMock.createMockBuilder;
 import static org.easymock.EasyMock.createNiceMock;
 import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
 import static org.easymock.EasyMock.replay;
 import static org.easymock.EasyMock.verify;
 
@@ -45,6 +47,7 @@ import org.apache.ambari.server.view.ViewRegistry;
 import org.easymock.EasyMock;
 import org.easymock.IAnswer;
 import org.junit.Test;
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
 import org.springframework.security.core.Authentication;
 import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.context.SecurityContext;
@@ -52,6 +55,7 @@ import org.springframework.security.core.context.SecurityContext;
 import com.google.common.collect.HashBasedTable;
 import com.google.common.collect.Table;
 import com.google.common.collect.Table.Cell;
+import org.springframework.security.core.context.SecurityContextHolder;
 
 public class AmbariAuthorizationFilterTest {
 
@@ -68,6 +72,8 @@ public class AmbariAuthorizationFilterTest {
     PrivilegeEntity privilegeEntity = createNiceMock(PrivilegeEntity.class);
     PermissionEntity permission = createNiceMock(PermissionEntity.class);
     FilterConfig filterConfig = createNiceMock(FilterConfig.class);
+    Authentication auth = new UsernamePasswordAuthenticationToken("admin",null);
+    SecurityContextHolder.getContext().setAuthentication(auth);
 
 
     expect(filterConfig.getInitParameter("realm")).andReturn("AuthFilter");
@@ -79,6 +85,16 @@ public class AmbariAuthorizationFilterTest {
         .andReturn(Collections.singletonList(authority));
     expect(filter.getSecurityContext()).andReturn(securityContext);
     expect(securityContext.getAuthentication()).andReturn(authentication);
+    response.setHeader("User", "admin");
+    expectLastCall().andAnswer(new IAnswer() {
+      public Object answer() {
+        String arg1 = (String) getCurrentArguments()[0];
+        String arg2 = (String) getCurrentArguments()[1];
+        Assert.assertEquals("User", arg1);
+        Assert.assertEquals("admin", arg2);
+        return null;
+      }
+    });
 
     expect(permission.getId()).andReturn(PermissionEntity.CLUSTER_OPERATE_PERMISSION);
 
@@ -92,7 +108,7 @@ public class AmbariAuthorizationFilterTest {
     filter.doFilter(request, response, chain);
 
     verify(request, response, chain, filter, securityContext, authentication, authority,
-        privilegeEntity, permission, filterConfig);
+               privilegeEntity, permission, filterConfig);
   }
 
   @Test
@@ -109,7 +125,6 @@ public class AmbariAuthorizationFilterTest {
     PermissionEntity permission = createNiceMock(PermissionEntity.class);
     FilterConfig filterConfig = createNiceMock(FilterConfig.class);
 
-
     expect(filterConfig.getInitParameter("realm")).andReturn("AuthFilter");
     expect(authentication.isAuthenticated()).andReturn(true);
     expect(request.getRequestURI()).andReturn("/api/v1/persist/some_val");


Mime
View raw message