You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/03/01 01:27:29 UTC
incubator-geode git commit: For troubleshooting
NotSerializableException failures
Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-949-2 527c43225 -> 5f377fe6d
For troubleshooting NotSerializableException failures
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/5f377fe6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/5f377fe6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/5f377fe6
Branch: refs/heads/feature/GEODE-949-2
Commit: 5f377fe6df463a27c6138ac8163ab76ffd56f445
Parents: 527c432
Author: Kirk Lund <kl...@pdx2-office-dhcp32.eng.vmware.com>
Authored: Mon Feb 29 16:27:18 2016 -0800
Committer: Kirk Lund <kl...@pdx2-office-dhcp32.eng.vmware.com>
Committed: Mon Feb 29 16:27:18 2016 -0800
----------------------------------------------------------------------
.../security/NotAuthorizedException.java | 7 ++-
.../security/NotAuthorizedExceptionTest.java | 58 ++++++++++++++++++++
.../security/LdapUserAuthenticator.java | 1 +
.../java/templates/security/PKCSPrincipal.java | 4 +-
.../templates/security/PKCSPrincipalTest.java | 48 ++++++++++++++++
.../security/UsernamePrincipalTest.java | 48 ++++++++++++++++
6 files changed, 163 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f377fe6/geode-core/src/main/java/com/gemstone/gemfire/security/NotAuthorizedException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/security/NotAuthorizedException.java b/geode-core/src/main/java/com/gemstone/gemfire/security/NotAuthorizedException.java
index c6165a6..84869bc 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/security/NotAuthorizedException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/security/NotAuthorizedException.java
@@ -26,8 +26,10 @@ import java.security.Principal;
* @since 5.5
*/
public class NotAuthorizedException extends GemFireSecurityException {
-private static final long serialVersionUID = 419215768216387745L;
- private Principal principal = null;
+ private static final long serialVersionUID = 419215768216387745L;
+
+ private transient Principal principal = null;
+
/**
* Constructs instance of <code>NotAuthorizedException</code> with error
* message.
@@ -47,6 +49,7 @@ private static final long serialVersionUID = 419215768216387745L;
public Principal getPrincipal() {
return this.principal;
}
+
/**
* Constructs instance of <code>NotAuthorizedException</code> with error
* message and cause.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f377fe6/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
new file mode 100644
index 0000000..27dab70
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
@@ -0,0 +1,58 @@
+package com.gemstone.gemfire.security;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+import org.apache.commons.lang.SerializationUtils;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.Serializable;
+import java.security.Principal;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Unit tests for {@link NotAuthorizedException}.
+ */
+@Category(UnitTest.class)
+public class NotAuthorizedExceptionTest {
+
+ @Test
+ public void isSerializable() throws Exception {
+ assertThat(NotAuthorizedException.class).isInstanceOf(Serializable.class);
+ }
+
+ @Test
+ public void canBeSerialized() throws Exception {
+ String message = "my message";
+ NotAuthorizedException instance = new NotAuthorizedException(message);
+
+ NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
+
+ assertThat(cloned).hasMessage(message);
+ }
+
+ @Test
+ public void canBeSerializedWithThrowable() throws Exception {
+ String message = "my message";
+ Throwable cause = new Exception("the cause");
+ NotAuthorizedException instance = new NotAuthorizedException(message, cause);
+
+ NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
+
+ assertThat(cloned).hasMessage(message);
+ assertThat(cloned).hasCause(cause);
+ }
+
+ @Test
+ public void canBeSerializedWithPrincipal() throws Exception {
+ String message = "my message";
+ Principal mockPrincipal = mock(Principal.class);
+ NotAuthorizedException instance = new NotAuthorizedException(message, mockPrincipal);
+
+ NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
+
+ assertThat(cloned).hasMessage(message);
+ assertThat(cloned.getPrincipal()).isEqualTo(mockPrincipal);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f377fe6/geode-core/src/test/java/templates/security/LdapUserAuthenticator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/templates/security/LdapUserAuthenticator.java b/geode-core/src/test/java/templates/security/LdapUserAuthenticator.java
index 98efaf9..63b7a42 100755
--- a/geode-core/src/test/java/templates/security/LdapUserAuthenticator.java
+++ b/geode-core/src/test/java/templates/security/LdapUserAuthenticator.java
@@ -102,6 +102,7 @@ public class LdapUserAuthenticator implements Authenticator {
ctx.close();
}
catch (Exception e) {
+ e.printStackTrace();
throw new AuthenticationFailedException(
"LdapUserAuthenticator: Failure with provided username, password "
+ "combination for user name: " + userName, e);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f377fe6/geode-core/src/test/java/templates/security/PKCSPrincipal.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/templates/security/PKCSPrincipal.java b/geode-core/src/test/java/templates/security/PKCSPrincipal.java
index 4dac6e2..bc3049f 100755
--- a/geode-core/src/test/java/templates/security/PKCSPrincipal.java
+++ b/geode-core/src/test/java/templates/security/PKCSPrincipal.java
@@ -14,15 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package templates.security;
+import java.io.Serializable;
import java.security.Principal;
/**
* @author kneeraj
*
*/
-public class PKCSPrincipal implements Principal {
+public class PKCSPrincipal implements Principal, Serializable {
private String alias;
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f377fe6/geode-core/src/test/java/templates/security/PKCSPrincipalTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/templates/security/PKCSPrincipalTest.java b/geode-core/src/test/java/templates/security/PKCSPrincipalTest.java
new file mode 100644
index 0000000..fc8454c
--- /dev/null
+++ b/geode-core/src/test/java/templates/security/PKCSPrincipalTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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 templates.security;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+import org.apache.commons.lang.SerializationUtils;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.Serializable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for {@link PKCSPrincipal}
+ */
+@Category(UnitTest.class)
+public class PKCSPrincipalTest {
+
+ @Test
+ public void isSerializable() throws Exception {
+ assertThat(PKCSPrincipal.class).isInstanceOf(Serializable.class);
+ }
+
+ @Test
+ public void canBeSerialized() throws Exception {
+ String name = "jsmith";
+ PKCSPrincipal instance = new PKCSPrincipal(name);
+
+ PKCSPrincipal cloned = (PKCSPrincipal) SerializationUtils.clone(instance);
+
+ assertThat(cloned.getName()).isEqualTo(name);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f377fe6/geode-core/src/test/java/templates/security/UsernamePrincipalTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/templates/security/UsernamePrincipalTest.java b/geode-core/src/test/java/templates/security/UsernamePrincipalTest.java
new file mode 100644
index 0000000..023c214
--- /dev/null
+++ b/geode-core/src/test/java/templates/security/UsernamePrincipalTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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 templates.security;
+
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+import org.apache.commons.lang.SerializationUtils;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.Serializable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for {@link UsernamePrincipal}
+ */
+@Category(UnitTest.class)
+public class UsernamePrincipalTest {
+
+ @Test
+ public void isSerializable() throws Exception {
+ assertThat(UsernamePrincipal.class).isInstanceOf(Serializable.class);
+ }
+
+ @Test
+ public void canBeSerialized() throws Exception {
+ String name = "jsmith";
+ UsernamePrincipal instance = new UsernamePrincipal(name);
+
+ UsernamePrincipal cloned = (UsernamePrincipal) SerializationUtils.clone(instance);
+
+ assertThat(cloned.getName()).isEqualTo(name);
+ }
+}