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/03 02:04:50 UTC

[1/2] incubator-geode git commit: Fix up javadocs and make certain methods final

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-949-2 9d801e352 -> 5f18b9d30


Fix up javadocs and make certain methods final


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

Branch: refs/heads/feature/GEODE-949-2
Commit: dcb766f6fbce6ad56fcd6bfb1fb772563bd07d5f
Parents: 9d801e3
Author: Kirk Lund <kl...@apache.org>
Authored: Wed Mar 2 17:00:38 2016 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Wed Mar 2 17:00:38 2016 -0800

----------------------------------------------------------------------
 .../security/GemFireSecurityException.java      |  82 ++++++++++-----
 .../security/NotAuthorizedException.java        | 100 +++++++++++++------
 .../security/GemFireSecurityExceptionTest.java  |  17 ++--
 .../security/NotAuthorizedExceptionTest.java    |  28 +++---
 4 files changed, 155 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dcb766f6/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java b/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java
index d099525..e57191a 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java
@@ -14,13 +14,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package com.gemstone.gemfire.security;
 
-import com.gemstone.gemfire.GemFireException;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
 
 import javax.naming.NamingException;
-import java.io.*;
+
+import com.gemstone.gemfire.GemFireException;
 
 /**
  * The base class for all com.gemstone.gemfire.security package related
@@ -30,66 +32,100 @@ import java.io.*;
  * @since 5.5
  */
 public class GemFireSecurityException extends GemFireException {
+
   private static final long serialVersionUID = 3814254578203076926L;
 
   private Throwable cause;
 
   /**
-   * Constructs instance of <code>SecurityException</code> with error message.
-   * 
-   * @param message
-   *                the error message
+   * Constructs a new exception with the specified detail message.
+   *
+   * @param  message the detail message (which is saved for later retrieval
+   *         by the {@link #getMessage()} method).  (A <tt>null</tt> value
+   *         is permitted.)
    */
   public GemFireSecurityException(final String message) {
     this(message, null);
   }
 
+  /**
+   * Constructs a new exception with the specified cause.
+   *
+   * <p>Note that the detail message associated with {@code cause} <i>is</i>
+   * automatically used as this exception's detail message.
+   *
+   * @param  cause the cause (which is saved for later retrieval by the
+   *         {@link #getCause()} method).  (A <tt>null</tt> value is
+   *         permitted, and indicates that the cause is nonexistent or
+   *         unknown.)
+   */
   public GemFireSecurityException(final Throwable cause) {
     this(cause != null ? cause.getMessage() : null, cause);
   }
 
   /**
-   * Constructs instance of <code>SecurityException</code> with error message
-   * and cause.
-   * 
-   * @param message
-   *                the error message
-   * @param cause
-   *                a <code>Throwable</code> that is a cause of this exception
+   * Constructs a new exception with the specified detail message and cause.
+   *
+   * <p>If {@code message} is null, then the detail message associated with
+   * {@code cause} <i>is</i> automatically used as this exception's detail
+   * message.
+   *
+   * @param  message the detail message (which is saved for later retrieval
+   *         by the {@link #getMessage()} method).  (A <tt>null</tt> value
+   *         is permitted.)
+   * @param  cause the cause (which is saved for later retrieval by the
+   *         {@link #getCause()} method).  (A <tt>null</tt> value is
+   *         permitted, and indicates that the cause is nonexistent or
+   *         unknown.)
    */
   public GemFireSecurityException(final String message, final Throwable cause) {
-    super(message);
+    super(message != null ? message : (cause != null ? cause.getMessage() : null));
     this.cause = cause;
   }
 
   @Override
-  public Throwable getCause() {
+  public final Throwable getCause() {
     return (this.cause == this ? null : this.cause);
   }
 
-  protected boolean isSerializable(final Object object) {
+  /**
+   * Returns true if the provided {@code object} implements {@code Serializable}.
+   *
+   * @param  object the {@code object} to test for implementing {@code Serializable}.
+   * @return true if the provided {@code object} implements {@code Serializable}.
+   */
+  protected final boolean isSerializable(final Object object) {
     if (object == null) {
       return true;
     }
     return Serializable.class.isInstance(object);
   }
 
-  protected Object getResolvedObj() {
-    if (getCause() != null && NamingException.class.isInstance(getCause())) {
-      return ((javax.naming.NamingException) getCause()).getResolvedObj();
+  /**
+   * Returns {@link NamingException#getResolvedObj()} if the {@code cause}
+   * is a {@code NamingException}. Returns <tt>null</tt> for any other type
+   * of {@code cause}.
+   *
+   * @return {@code NamingException#getResolvedObj()} if the {@code cause}
+   *         is a {@code NamingException}.
+   */
+  protected final Object getResolvedObj() {
+    final Throwable thisCause = this.cause;
+    if (thisCause != null && NamingException.class.isInstance(thisCause)) {
+      return ((NamingException) thisCause).getResolvedObj();
     }
     return null;
   }
 
-  private void writeObject(final ObjectOutputStream stream) throws IOException {
+  private synchronized void writeObject(final ObjectOutputStream out) throws IOException {
     final Object resolvedObj = getResolvedObj();
     if (isSerializable(resolvedObj)) {
-      stream.defaultWriteObject();
+      out.defaultWriteObject();
     } else {
       final NamingException namingException = (NamingException) getCause();
       namingException.setResolvedObj(null);
       try {
-        stream.defaultWriteObject();
+        out.defaultWriteObject();
       } finally {
         namingException.setResolvedObj(resolvedObj);
       }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dcb766f6/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 4108742..096df93 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
@@ -14,7 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package com.gemstone.gemfire.security;
 
 import javax.naming.NamingException;
@@ -29,50 +28,95 @@ import java.security.Principal;
  * @since 5.5
  */
 public class NotAuthorizedException extends GemFireSecurityException {
+
   private static final long serialVersionUID = 419215768216387745L;
 
   private Principal principal = null;
 
   /**
-   * Constructs instance of <code>NotAuthorizedException</code> with error
-   * message.
-   * 
-   * @param message
-   *                the error message
+   * Constructs a new exception with the specified detail message and
+   * principal.
+   *
+   * @param  message the detail message (which is saved for later retrieval
+   *         by the {@link #getMessage()} method).  (A <tt>null</tt> value
+   *         is permitted.)
    */
-  public NotAuthorizedException(String message) {
-    super(message);
+  public NotAuthorizedException(final String message) {
+    this(message, null, null);
   }
 
-  public NotAuthorizedException(String message, Principal ppl) {
-    super(message);
-    this.principal = ppl;
+  /**
+   * Constructs a new exception with the specified detail message and cause.
+   *
+   * <p>If {@code message} is null, then the detail message associated with
+   * {@code cause} <i>is</i> automatically used as this exception's detail
+   * message.
+   *
+   * @param  message the detail message (which is saved for later retrieval
+   *         by the {@link #getMessage()} method).  (A <tt>null</tt> value
+   *         is permitted.)
+   * @param  cause the cause (which is saved for later retrieval by the
+   *         {@link #getCause()} method).  (A <tt>null</tt> value is
+   *         permitted, and indicates that the cause is nonexistent or
+   *         unknown.)
+   */
+  public NotAuthorizedException(final String message, final Throwable cause) {
+    this(message, cause, null);
   }
-  
-  public Principal getPrincipal() {
-    return this.principal;
+
+  /**
+   * Constructs a new exception with the specified detail message and
+   * principal.
+   *
+   * @param  message the detail message (which is saved for later retrieval
+   *         by the {@link #getMessage()} method).  (A <tt>null</tt> value
+   *         is permitted.)
+   * @param  principal the principal for which authorization failed.
+   *         (A <tt>null</tt> value is permitted.)
+   */
+  public NotAuthorizedException(final String message, final Principal principal) {
+    this(message, null, principal);
   }
 
   /**
-   * Constructs instance of <code>NotAuthorizedException</code> with error
-   * message and cause.
-   * 
-   * @param message
-   *                the error message
-   * @param cause
-   *                a <code>Throwable</code> that is a cause of this exception
+   * Constructs a new exception with the specified detail message, cause and
+   * principal.
+   *
+   * <p>If {@code message} is null, then the detail message associated with
+   * {@code cause} <i>is</i> automatically used as this exception's detail
+   * message.
+   *
+   * @param  message the detail message (which is saved for later retrieval
+   *         by the {@link #getMessage()} method).  (A <tt>null</tt> value
+   *         is permitted.)
+   * @param  cause the cause (which is saved for later retrieval by the
+   *         {@link #getCause()} method).  (A <tt>null</tt> value is
+   *         permitted, and indicates that the cause is nonexistent or
+   *         unknown.)
+   * @param  principal the principal for which authorization failed.
+   *         (A <tt>null</tt> value is permitted.)
    */
-  public NotAuthorizedException(String message, Throwable cause) {
+  public NotAuthorizedException(final String message, final Throwable cause, final Principal principal) {
     super(message, cause);
+    this.principal = principal;
+  }
+
+  /**
+   * Returns the {@code principal} for which authorization failed.
+   *
+   * @return the {@code principal} for which authorization failed.
+   */
+  public Principal getPrincipal() {
+    return this.principal;
   }
 
-  private void writeObject(final ObjectOutputStream stream) throws IOException {
-    Principal myPrincipal = this.principal;
-    if (!isSerializable(myPrincipal)) {
+  private synchronized void writeObject(final ObjectOutputStream out) throws IOException {
+    final Principal thisPrincipal = this.principal;
+    if (!isSerializable(thisPrincipal)) {
       this.principal = null;
     }
 
-    Object resolvedObj = getResolvedObj();
+    final Object resolvedObj = getResolvedObj();
     NamingException namingException = null;
     if (!isSerializable(resolvedObj)) {
       namingException = (NamingException) getCause();
@@ -80,9 +124,9 @@ public class NotAuthorizedException extends GemFireSecurityException {
     }
 
     try {
-      stream.defaultWriteObject();
+      out.defaultWriteObject();
     } finally {
-      this.principal = myPrincipal;
+      this.principal = thisPrincipal;
       if (namingException != null) {
         namingException.setResolvedObj(resolvedObj);
       }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dcb766f6/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java
index 2c76138..314fcbc 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java
@@ -16,6 +16,14 @@
  */
 package com.gemstone.gemfire.security;
 
+import static com.googlecode.catchexception.CatchException.*;
+import static org.assertj.core.api.Assertions.*;
+
+import java.io.NotSerializableException;
+import java.io.Serializable;
+
+import javax.naming.NamingException;
+
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 import org.apache.commons.lang.SerializationUtils;
 import org.junit.Before;
@@ -24,15 +32,6 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.TestName;
 
-import javax.naming.NamingException;
-import java.io.NotSerializableException;
-import java.io.Serializable;
-import java.security.Principal;
-
-import static com.googlecode.catchexception.CatchException.*;
-import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Mockito.mock;
-
 /**
  * Unit tests for {@link GemFireSecurityException}.
  */

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/dcb766f6/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
index 162d5ff..d9f462e 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
@@ -16,6 +16,16 @@
  */
 package com.gemstone.gemfire.security;
 
+import static com.googlecode.catchexception.CatchException.*;
+import static org.assertj.core.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+import java.io.NotSerializableException;
+import java.io.Serializable;
+import java.security.Principal;
+
+import javax.naming.NamingException;
+
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 import org.apache.commons.lang.SerializationUtils;
 import org.junit.Before;
@@ -24,17 +34,6 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.rules.TestName;
 
-import javax.naming.NamingException;
-import javax.security.auth.Subject;
-import java.io.NotSerializableException;
-import java.io.Serializable;
-import java.security.Principal;
-
-import static com.googlecode.catchexception.CatchException.catchException;
-import static com.googlecode.catchexception.CatchException.caughtException;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
 /**
  * Unit tests for {@link NotAuthorizedException}.
  */
@@ -49,7 +48,7 @@ public class NotAuthorizedExceptionTest {
   private NamingException serializableNamingException;
   private String principalName;
   private Principal nonSerializablePrincipal;
-  private Principal serializablePrincipal;
+  private SerializablePrincipal serializablePrincipal;
 
   @Rule
   public TestName testName = new TestName();
@@ -86,6 +85,11 @@ public class NotAuthorizedExceptionTest {
 
     catchException(this).clone(this.serializableResolvedObj);
     assertThat((Throwable)caughtException()).isNull();
+
+    assertThat(this.nonSerializablePrincipal).isNotInstanceOf(Serializable.class);
+
+    catchException(this).clone(this.serializablePrincipal);
+    assertThat((Throwable)caughtException()).isNull();
   }
 
   @Test


[2/2] incubator-geode git commit: Organize imports

Posted by kl...@apache.org.
Organize imports


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

Branch: refs/heads/feature/GEODE-949-2
Commit: 5f18b9d3084900740e3f9057fc3d0c0b37c280c0
Parents: dcb766f
Author: Kirk Lund <kl...@apache.org>
Authored: Wed Mar 2 17:04:46 2016 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Wed Mar 2 17:04:46 2016 -0800

----------------------------------------------------------------------
 .../com/gemstone/gemfire/security/GemFireSecurityException.java    | 1 -
 .../java/com/gemstone/gemfire/security/NotAuthorizedException.java | 2 +-
 .../gemstone/gemfire/security/GemFireSecurityExceptionTest.java    | 1 -
 .../com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java  | 1 -
 4 files changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f18b9d3/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java b/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java
index e57191a..40be542 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/security/GemFireSecurityException.java
@@ -19,7 +19,6 @@ package com.gemstone.gemfire.security;
 import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
-
 import javax.naming.NamingException;
 
 import com.gemstone.gemfire.GemFireException;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f18b9d3/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 096df93..27c612f 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
@@ -16,10 +16,10 @@
  */
 package com.gemstone.gemfire.security;
 
-import javax.naming.NamingException;
 import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.security.Principal;
+import javax.naming.NamingException;
 
 /**
  * Thrown when a client/peer is unauthorized to perform a requested operation.

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f18b9d3/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java
index 314fcbc..0c048d3 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/GemFireSecurityExceptionTest.java
@@ -21,7 +21,6 @@ import static org.assertj.core.api.Assertions.*;
 
 import java.io.NotSerializableException;
 import java.io.Serializable;
-
 import javax.naming.NamingException;
 
 import com.gemstone.gemfire.test.junit.categories.UnitTest;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5f18b9d3/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
index d9f462e..c5e0ba5 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.*;
 import java.io.NotSerializableException;
 import java.io.Serializable;
 import java.security.Principal;
-
 import javax.naming.NamingException;
 
 import com.gemstone.gemfire.test.junit.categories.UnitTest;