You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ji...@apache.org on 2016/12/20 17:23:19 UTC
geode git commit: GEODE-2188: ExampleSecurityManager references
SampleSecurityManager in javadoc
Repository: geode
Updated Branches:
refs/heads/develop 94f43e46d -> 7c243346e
GEODE-2188: ExampleSecurityManager references SampleSecurityManager in javadoc
* this closes #316
Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/7c243346
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/7c243346
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/7c243346
Branch: refs/heads/develop
Commit: 7c243346ef4e49f589725aa69138e93d2b23aeca
Parents: 94f43e4
Author: Kevin J. Duling <kd...@pivotal.io>
Authored: Wed Dec 14 13:23:19 2016 -0800
Committer: Jinmei Liao <ji...@pivotal.io>
Committed: Tue Dec 20 09:22:41 2016 -0800
----------------------------------------------------------------------
.../security/ExampleSecurityManager.java | 66 ++++++++++--
.../security/ExampleSecurityManagerTest.java | 104 +++++++++++++++++++
.../security/SampleSecurityManagerTest.java | 103 ------------------
.../geode/security/TestSecurityManager.java | 11 +-
4 files changed, 167 insertions(+), 117 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode/blob/7c243346/geode-core/src/main/java/org/apache/geode/examples/security/ExampleSecurityManager.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/examples/security/ExampleSecurityManager.java b/geode-core/src/main/java/org/apache/geode/examples/security/ExampleSecurityManager.java
index 612726a..84f97de 100644
--- a/geode-core/src/main/java/org/apache/geode/examples/security/ExampleSecurityManager.java
+++ b/geode-core/src/main/java/org/apache/geode/examples/security/ExampleSecurityManager.java
@@ -46,7 +46,7 @@ import java.util.stream.StreamSupport;
* A Geode member must be configured with the following:
*
* <p>
- * {@code security-manager = org.apache.geode.security.examples.SampleSecurityManager}
+ * {@code security-manager = org.apache.geode.security.examples.ExampleSecurityManager}
*
* <p>
* The class can be initialized with from a JSON resource called {@code security.json}. This file
@@ -130,7 +130,7 @@ public class ExampleSecurityManager implements SecurityManager {
if (!initializeFromJsonResource(jsonPropertyValue)) {
throw new AuthenticationFailedException(
- "SampleSecurityManager: unable to find json resource \"" + jsonPropertyValue
+ "ExampleSecurityManager: unable to find json resource \"" + jsonPropertyValue
+ "\" as specified by [" + SECURITY_JSON + "].");
}
}
@@ -142,11 +142,11 @@ public class ExampleSecurityManager implements SecurityManager {
User userObj = this.userNameToUser.get(user);
if (userObj == null) {
- throw new AuthenticationFailedException("SampleSecurityManager: wrong username/password");
+ throw new AuthenticationFailedException("ExampleSecurityManager: wrong username/password");
}
if (user != null && !userObj.password.equals(password) && !"".equals(user)) {
- throw new AuthenticationFailedException("SampleSecurityManager: wrong username/password");
+ throw new AuthenticationFailedException("ExampleSecurityManager: wrong username/password");
}
return user;
@@ -165,7 +165,7 @@ public class ExampleSecurityManager implements SecurityManager {
}
}
- boolean initializeFromJsonResource(final String jsonResource) {
+ public boolean initializeFromJsonResource(final String jsonResource) {
try {
InputStream input = ClassLoader.getSystemResourceAsStream(jsonResource);
if (input != null) {
@@ -177,7 +177,7 @@ public class ExampleSecurityManager implements SecurityManager {
return false;
}
- User getUser(final String user) {
+ public User getUser(final String user) {
return this.userNameToUser.get(user);
}
@@ -257,15 +257,65 @@ public class ExampleSecurityManager implements SecurityManager {
return roleMap;
}
- static class Role {
+ public static class Role {
List<ResourcePermission> permissions = new ArrayList<>();
+
+ public List<ResourcePermission> getPermissions() {
+ return permissions;
+ }
+
+ public void setPermissions(final List<ResourcePermission> permissions) {
+ this.permissions = permissions;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getServerGroup() {
+ return serverGroup;
+ }
+
+ public void setServerGroup(final String serverGroup) {
+ this.serverGroup = serverGroup;
+ }
+
String name;
String serverGroup;
}
- static class User {
+ public static class User {
String name;
Set<Role> roles = new HashSet<>();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public Set<Role> getRoles() {
+ return roles;
+ }
+
+ public void setRoles(final Set<Role> roles) {
+ this.roles = roles;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(final String password) {
+ this.password = password;
+ }
+
String password;
}
http://git-wip-us.apache.org/repos/asf/geode/blob/7c243346/geode-core/src/test/java/org/apache/geode/security/ExampleSecurityManagerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/ExampleSecurityManagerTest.java b/geode-core/src/test/java/org/apache/geode/security/ExampleSecurityManagerTest.java
new file mode 100644
index 0000000..9093a7b
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/security/ExampleSecurityManagerTest.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.security;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.geode.examples.security.ExampleSecurityManager;
+import org.apache.geode.examples.security.ExampleSecurityManager.User;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.apache.geode.test.junit.categories.SecurityTest;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.util.Properties;
+
+@Category({IntegrationTest.class, SecurityTest.class})
+public class ExampleSecurityManagerTest {
+
+ private ExampleSecurityManager exampleSecurityManager;
+ private String jsonResource;
+ private File jsonFile;
+ private String json;
+
+ @Rule
+ public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+ @Before
+ public void setUp() throws Exception {
+ // resource file
+ this.jsonResource = "org/apache/geode/security/templates/security.json";
+ InputStream inputStream = ClassLoader.getSystemResourceAsStream(this.jsonResource);
+
+ assertThat(inputStream).isNotNull();
+
+ // non-resource file
+ this.jsonFile = new File(temporaryFolder.getRoot(), "security.json");
+ IOUtils.copy(inputStream, new FileOutputStream(this.jsonFile));
+
+ // string
+ this.json = FileUtils.readFileToString(this.jsonFile, "UTF-8");
+ this.exampleSecurityManager = new ExampleSecurityManager();
+ }
+
+ @Test
+ public void shouldDefaultToSecurityJsonInClasspathIfNullProperties() throws Exception {
+ this.exampleSecurityManager.init(null);
+ verifySecurityManagerState();
+ }
+
+ @Test
+ public void shouldDefaultToSecurityJsonInClasspathIfEmptyProperties() throws Exception {
+ this.exampleSecurityManager.init(new Properties());
+ verifySecurityManagerState();
+ }
+
+ @Test
+ public void shouldInitializeFromJsonResource() throws Exception {
+ this.exampleSecurityManager.initializeFromJsonResource(this.jsonResource);
+ verifySecurityManagerState();
+ }
+
+ @Test
+ public void initShouldUsePropertyAsJsonResource() throws Exception {
+ Properties securityProperties = new Properties();
+ securityProperties.setProperty(TestSecurityManager.SECURITY_JSON, this.jsonResource);
+ this.exampleSecurityManager.init(securityProperties);
+ verifySecurityManagerState();
+ }
+
+ private void verifySecurityManagerState() {
+ User adminUser = this.exampleSecurityManager.getUser("admin");
+ assertThat(adminUser).isNotNull();
+ assertThat(adminUser.getName()).isEqualTo("admin");
+ assertThat(adminUser.getPassword()).isEqualTo("secret");
+ assertThat(adminUser.getRoles()).hasSize(1);
+
+ User guestUser = this.exampleSecurityManager.getUser("guest");
+ assertThat(guestUser).isNotNull();
+ assertThat(guestUser.getName()).isEqualTo("guest");
+ assertThat(guestUser.getPassword()).isEqualTo("guest");
+ assertThat(guestUser.getRoles()).hasSize(1);
+ // TODO: need to do more verification
+ }
+}
http://git-wip-us.apache.org/repos/asf/geode/blob/7c243346/geode-core/src/test/java/org/apache/geode/security/SampleSecurityManagerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/SampleSecurityManagerTest.java b/geode-core/src/test/java/org/apache/geode/security/SampleSecurityManagerTest.java
deleted file mode 100644
index 96cabf6..0000000
--- a/geode-core/src/test/java/org/apache/geode/security/SampleSecurityManagerTest.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package org.apache.geode.security;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.geode.security.TestSecurityManager.User;
-import org.apache.geode.test.junit.categories.IntegrationTest;
-import org.apache.geode.test.junit.categories.SecurityTest;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TemporaryFolder;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.util.Properties;
-
-@Category({IntegrationTest.class, SecurityTest.class})
-public class SampleSecurityManagerTest {
-
- private TestSecurityManager sampleSecurityManager;
- private String jsonResource;
- private File jsonFile;
- private String json;
-
- @Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
-
- @Before
- public void setUp() throws Exception {
- // resource file
- this.jsonResource = "org/apache/geode/security/templates/security.json";
- InputStream inputStream = ClassLoader.getSystemResourceAsStream(this.jsonResource);
-
- assertThat(inputStream).isNotNull();
-
- // non-resource file
- this.jsonFile = new File(temporaryFolder.getRoot(), "security.json");
- IOUtils.copy(inputStream, new FileOutputStream(this.jsonFile));
-
- // string
- this.json = FileUtils.readFileToString(this.jsonFile, "UTF-8");
- this.sampleSecurityManager = new TestSecurityManager();
- }
-
- @Test
- public void shouldDefaultToSecurityJsonInClasspathIfNullProperties() throws Exception {
- this.sampleSecurityManager.init(null);
- verifySecurityManagerState();
- }
-
- @Test
- public void shouldDefaultToSecurityJsonInClasspathIfEmptyProperties() throws Exception {
- this.sampleSecurityManager.init(new Properties());
- verifySecurityManagerState();
- }
-
- @Test
- public void shouldInitializeFromJsonResource() throws Exception {
- this.sampleSecurityManager.initializeFromJsonResource(this.jsonResource);
- verifySecurityManagerState();
- }
-
- @Test
- public void initShouldUsePropertyAsJsonResource() throws Exception {
- Properties securityProperties = new Properties();
- securityProperties.setProperty(TestSecurityManager.SECURITY_JSON, this.jsonResource);
- this.sampleSecurityManager.init(securityProperties);
- verifySecurityManagerState();
- }
-
- private void verifySecurityManagerState() {
- User adminUser = this.sampleSecurityManager.getUser("admin");
- assertThat(adminUser).isNotNull();
- assertThat(adminUser.name).isEqualTo("admin");
- assertThat(adminUser.password).isEqualTo("secret");
- assertThat(adminUser.roles).hasSize(1);
-
- User guestUser = this.sampleSecurityManager.getUser("guest");
- assertThat(guestUser).isNotNull();
- assertThat(guestUser.name).isEqualTo("guest");
- assertThat(guestUser.password).isEqualTo("guest");
- assertThat(guestUser.roles).hasSize(1);
- // TODO: need to do more verification
- }
-}
http://git-wip-us.apache.org/repos/asf/geode/blob/7c243346/geode-core/src/test/java/org/apache/geode/security/TestSecurityManager.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/security/TestSecurityManager.java b/geode-core/src/test/java/org/apache/geode/security/TestSecurityManager.java
index 3fbd96a..6080b5d 100644
--- a/geode-core/src/test/java/org/apache/geode/security/TestSecurityManager.java
+++ b/geode-core/src/test/java/org/apache/geode/security/TestSecurityManager.java
@@ -42,7 +42,7 @@ import java.util.stream.StreamSupport;
* A Geode member must be configured with the following:
*
* <p>
- * {@code security-manager = org.apache.geode.security.examples.SampleSecurityManager}
+ * {@code security-manager = org.apache.geode.security.examples.TestSecurityManager}
*
* <p>
* The class can be initialized with from a JSON resource called {@code security.json}. This file
@@ -125,9 +125,8 @@ public class TestSecurityManager implements SecurityManager {
}
if (!initializeFromJsonResource(jsonPropertyValue)) {
- throw new AuthenticationFailedException(
- "SampleSecurityManager: unable to find json resource \"" + jsonPropertyValue
- + "\" as specified by [" + SECURITY_JSON + "].");
+ throw new AuthenticationFailedException("TestSecurityManager: unable to find json resource \""
+ + jsonPropertyValue + "\" as specified by [" + SECURITY_JSON + "].");
}
}
@@ -138,11 +137,11 @@ public class TestSecurityManager implements SecurityManager {
User userObj = this.userNameToUser.get(user);
if (userObj == null) {
- throw new AuthenticationFailedException("SampleSecurityManager: wrong username/password");
+ throw new AuthenticationFailedException("TestSecurityManager: wrong username/password");
}
if (user != null && !userObj.password.equals(password) && !"".equals(user)) {
- throw new AuthenticationFailedException("SampleSecurityManager: wrong username/password");
+ throw new AuthenticationFailedException("TestSecurityManager: wrong username/password");
}
return user;