hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From szets...@apache.org
Subject svn commit: r802224 - in /hadoop/common/trunk: CHANGES.txt src/java/org/apache/hadoop/security/AccessTokenHandler.java src/test/core/org/apache/hadoop/security/SecurityTestUtil.java
Date Fri, 07 Aug 2009 21:40:02 GMT
Author: szetszwo
Date: Fri Aug  7 21:40:01 2009
New Revision: 802224

URL: http://svn.apache.org/viewvc?rev=802224&view=rev
Log:
HADOOP-6176. Add a couple package private methods to AccessTokenHandler for testing.  Contributed
by Kan Zhang

Added:
    hadoop/common/trunk/src/test/core/org/apache/hadoop/security/SecurityTestUtil.java
Modified:
    hadoop/common/trunk/CHANGES.txt
    hadoop/common/trunk/src/java/org/apache/hadoop/security/AccessTokenHandler.java

Modified: hadoop/common/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=802224&r1=802223&r2=802224&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Fri Aug  7 21:40:01 2009
@@ -489,6 +489,9 @@
     (gkesavan)
     
     HADOOP-6169. Removing deprecated method calls in TFile. (hong tang via mahadev)
+
+    HADOOP-6176. Add a couple package private methods to AccessTokenHandler
+    for testing.  (Kan Zhang via szetszwo)
  
   OPTIMIZATIONS
 

Modified: hadoop/common/trunk/src/java/org/apache/hadoop/security/AccessTokenHandler.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/java/org/apache/hadoop/security/AccessTokenHandler.java?rev=802224&r1=802223&r2=802224&view=diff
==============================================================================
--- hadoop/common/trunk/src/java/org/apache/hadoop/security/AccessTokenHandler.java (original)
+++ hadoop/common/trunk/src/java/org/apache/hadoop/security/AccessTokenHandler.java Fri Aug
 7 21:40:01 2009
@@ -60,7 +60,7 @@
    * sync'ed their access keys with NN at least once during each interval.
    */
   private final long keyUpdateInterval;
-  private final long tokenLifetime;
+  private long tokenLifetime;
   private long serialNo = new SecureRandom().nextLong();
   private KeyGenerator keyGen;
   private AccessKey currentKey;
@@ -203,7 +203,7 @@
   }
 
   /** Check if token is well formed */
-  private synchronized Boolean verifyToken(long keyID, AccessToken token)
+  private synchronized boolean verifyToken(long keyID, AccessToken token)
       throws IOException {
     AccessKey key = allKeys.get(keyID);
     if (key == null) {
@@ -252,7 +252,7 @@
   }
 
   /** Check if access should be allowed. userID is not checked if null */
-  public Boolean checkAccess(AccessToken token, String userID, long blockID,
+  public boolean checkAccess(AccessToken token, String userID, long blockID,
       AccessMode mode) throws IOException {
     long oExpiry = 0;
     long oKeyID = 0;
@@ -282,8 +282,26 @@
           + blockID + ", access mode=" + mode + ", keyID=" + oKeyID);
     }
     return (userID == null || userID.equals(oUserID)) && oBlockID == blockID
-        && System.currentTimeMillis() < oExpiry && oModes.contains(mode)
+        && !isExpired(oExpiry) && oModes.contains(mode)
         && verifyToken(oKeyID, token);
   }
 
+  private static boolean isExpired(long expiryDate) {
+    return System.currentTimeMillis() > expiryDate;
+  }
+
+  /** check if a token is expired. for unit test only.
+   *  return true when token is expired, false otherwise */
+  static boolean isTokenExpired(AccessToken token) throws IOException {
+    ByteArrayInputStream buf = new ByteArrayInputStream(token.getTokenID()
+        .getBytes());
+    DataInputStream in = new DataInputStream(buf);
+    long expiryDate = WritableUtils.readVLong(in);
+    return isExpired(expiryDate);
+  }
+
+  /** set token lifetime. for unit test only */
+  synchronized void setTokenLifetime(long tokenLifetime) {
+    this.tokenLifetime = tokenLifetime;
+  }
 }
\ No newline at end of file

Added: hadoop/common/trunk/src/test/core/org/apache/hadoop/security/SecurityTestUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/security/SecurityTestUtil.java?rev=802224&view=auto
==============================================================================
--- hadoop/common/trunk/src/test/core/org/apache/hadoop/security/SecurityTestUtil.java (added)
+++ hadoop/common/trunk/src/test/core/org/apache/hadoop/security/SecurityTestUtil.java Fri
Aug  7 21:40:01 2009
@@ -0,0 +1,43 @@
+/**
+ * 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.hadoop.security;
+
+import java.io.IOException;
+
+/** Utilities for security tests */
+public class SecurityTestUtil {
+
+  /**
+   * check if an access token is expired. return true when token is expired,
+   * false otherwise
+   */
+  public static boolean isAccessTokenExpired(AccessToken token)
+      throws IOException {
+    return AccessTokenHandler.isTokenExpired(token);
+  }
+
+  /**
+   * set access token lifetime.
+   */
+  public static void setAccessTokenLifetime(AccessTokenHandler handler,
+      long tokenLifetime) {
+    handler.setTokenLifetime(tokenLifetime);
+  }
+
+}



Mime
View raw message