You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2017/08/21 16:36:42 UTC

geode git commit: GEODE-3474: protobuf auth with ExampleSecurityManager. This closes #726

Repository: geode
Updated Branches:
  refs/heads/develop d809076d0 -> b43f502c6


GEODE-3474: protobuf auth with ExampleSecurityManager. This closes #726


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

Branch: refs/heads/develop
Commit: b43f502c60b8f60c1447c3daf3059c76d6abb78c
Parents: d809076
Author: Galen O'Sullivan <go...@pivotal.io>
Authored: Mon Aug 21 08:29:54 2017 -0700
Committer: Udo Kohlmeyer <uk...@pivotal.io>
Committed: Mon Aug 21 09:36:25 2017 -0700

----------------------------------------------------------------------
 .../protobuf/ProtobufSimpleAuthenticator.java   |  5 ++--
 .../ProtobufSimpleAuthenticatorJUnitTest.java   | 28 ++++++++++++++++----
 2 files changed, 26 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/b43f502c/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticator.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticator.java b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticator.java
index 1517552..00285bb 100644
--- a/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticator.java
+++ b/geode-protobuf/src/main/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticator.java
@@ -14,6 +14,7 @@
  */
 package org.apache.geode.protocol.protobuf;
 
+import org.apache.geode.management.internal.security.ResourceConstants;
 import org.apache.geode.security.StreamAuthenticator;
 import org.apache.geode.security.AuthenticationFailedException;
 import org.apache.geode.security.SecurityManager;
@@ -37,8 +38,8 @@ public class ProtobufSimpleAuthenticator implements StreamAuthenticator {
     }
 
     Properties properties = new Properties();
-    properties.setProperty("username", authenticationRequest.getUsername());
-    properties.setProperty("password", authenticationRequest.getPassword());
+    properties.setProperty(ResourceConstants.USER_NAME, authenticationRequest.getUsername());
+    properties.setProperty(ResourceConstants.PASSWORD, authenticationRequest.getPassword());
 
     try {
       Object principal = securityManager.authenticate(properties);

http://git-wip-us.apache.org/repos/asf/geode/blob/b43f502c/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticatorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticatorJUnitTest.java b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticatorJUnitTest.java
index 3d16f5e..71f4daf 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticatorJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/protocol/protobuf/ProtobufSimpleAuthenticatorJUnitTest.java
@@ -15,6 +15,8 @@
 
 package org.apache.geode.protocol.protobuf;
 
+import org.apache.geode.examples.security.ExampleSecurityManager;
+import org.apache.geode.management.internal.security.ResourceConstants;
 import org.apache.geode.security.AuthenticationFailedException;
 import org.apache.geode.security.ResourcePermission;
 import org.apache.geode.security.SecurityManager;
@@ -45,6 +47,7 @@ public class ProtobufSimpleAuthenticatorJUnitTest {
   private ProtobufSimpleAuthenticator protobufSimpleAuthenticator;
   private SecurityManager mockSecurityManager;
   private Object securityPrincipal;
+  private Properties expectedAuthProperties;
 
   @Before
   public void setUp() throws IOException {
@@ -52,9 +55,9 @@ public class ProtobufSimpleAuthenticatorJUnitTest {
         AuthenticationAPI.SimpleAuthenticationRequest.newBuilder().setUsername(TEST_USERNAME)
             .setPassword(TEST_PASSWORD).build();
 
-    Properties expectedAuthProperties = new Properties();
-    expectedAuthProperties.setProperty("username", TEST_USERNAME);
-    expectedAuthProperties.setProperty("password", TEST_PASSWORD);
+    expectedAuthProperties = new Properties();
+    expectedAuthProperties.setProperty(ResourceConstants.USER_NAME, TEST_USERNAME);
+    expectedAuthProperties.setProperty(ResourceConstants.PASSWORD, TEST_PASSWORD);
 
     ByteArrayOutputStream messageStream = new ByteArrayOutputStream();
     basicAuthenticationRequest.writeDelimitedTo(messageStream);
@@ -88,8 +91,8 @@ public class ProtobufSimpleAuthenticatorJUnitTest {
     assertFalse(protobufSimpleAuthenticator.isAuthenticated());
 
     Properties expectedAuthProperties = new Properties();
-    expectedAuthProperties.setProperty("username", TEST_USERNAME);
-    expectedAuthProperties.setProperty("password", TEST_PASSWORD);
+    expectedAuthProperties.setProperty(ResourceConstants.USER_NAME, TEST_USERNAME);
+    expectedAuthProperties.setProperty(ResourceConstants.PASSWORD, TEST_PASSWORD);
     when(mockSecurityManager.authenticate(expectedAuthProperties))
         .thenThrow(new AuthenticationFailedException("BOOM!"));
 
@@ -103,6 +106,21 @@ public class ProtobufSimpleAuthenticatorJUnitTest {
     assertFalse(protobufSimpleAuthenticator.isAuthenticated());
   }
 
+  @Test
+  public void testExampleSecurityManager() throws IOException {
+    assertFalse(protobufSimpleAuthenticator.isAuthenticated());
+
+    protobufSimpleAuthenticator.receiveMessage(byteArrayInputStream, byteArrayOutputStream,
+        mockSecurityManager);
+
+    new ExampleSecurityManager().init(expectedAuthProperties);
+    AuthenticationAPI.SimpleAuthenticationResponse simpleAuthenticationResponse =
+        getSimpleAuthenticationResponse(byteArrayOutputStream);
+
+    assertTrue(simpleAuthenticationResponse.getAuthenticated());
+    assertTrue(protobufSimpleAuthenticator.isAuthenticated());
+  }
+
   private AuthenticationAPI.SimpleAuthenticationResponse getSimpleAuthenticationResponse(
       ByteArrayOutputStream outputStream) throws IOException {
     ByteArrayInputStream responseStream = new ByteArrayInputStream(outputStream.toByteArray());