You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2013/12/30 19:02:43 UTC
git commit: ACCUMULO-2030 Clean up javadoc
Updated Branches:
refs/heads/1.6.0-SNAPSHOT cbbcaac88 -> 063c88d7e
ACCUMULO-2030 Clean up javadoc
Fix ambiguous javadoc reference by removing it
Remove incorrect exception declaration
Remove unused import warning
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/063c88d7
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/063c88d7
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/063c88d7
Branch: refs/heads/1.6.0-SNAPSHOT
Commit: 063c88d7e28573888ebb56773071ba344920a1dd
Parents: cbbcaac
Author: Christopher Tubbs <ct...@apache.org>
Authored: Mon Dec 30 13:01:00 2013 -0500
Committer: Christopher Tubbs <ct...@apache.org>
Committed: Mon Dec 30 13:01:00 2013 -0500
----------------------------------------------------------------------
.../accumulo/core/security/Authorizations.java | 137 ++++++++++---------
.../accumulo/core/security/Credentials.java | 48 ++++---
.../apache/accumulo/test/randomwalk/State.java | 59 ++++----
3 files changed, 127 insertions(+), 117 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/accumulo/blob/063c88d7/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java b/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
index 67349d4..6047352 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/Authorizations.java
@@ -38,72 +38,74 @@ import org.apache.commons.codec.binary.Base64;
* A collection of authorization strings.
*/
public class Authorizations implements Iterable<byte[]>, Serializable, AuthorizationContainer {
-
+
private static final long serialVersionUID = 1L;
-
+
private Set<ByteSequence> auths = new HashSet<ByteSequence>();
- private List<byte[]> authsList = new ArrayList<byte[]>(); // sorted order
-
+ private List<byte[]> authsList = new ArrayList<byte[]>(); // sorted order
+
/**
* An empty set of authorizations.
*/
public static final Authorizations EMPTY = new Authorizations();
-
+
private static final boolean[] validAuthChars = new boolean[256];
-
+
/**
* A special header string used when serializing instances of this class.
- *
+ *
* @see #serialize()
*/
public static final String HEADER = "!AUTH1:";
-
+
static {
for (int i = 0; i < 256; i++) {
validAuthChars[i] = false;
}
-
+
for (int i = 'a'; i <= 'z'; i++) {
validAuthChars[i] = true;
}
-
+
for (int i = 'A'; i <= 'Z'; i++) {
validAuthChars[i] = true;
}
-
+
for (int i = '0'; i <= '9'; i++) {
validAuthChars[i] = true;
}
-
+
validAuthChars['_'] = true;
validAuthChars['-'] = true;
validAuthChars[':'] = true;
validAuthChars['.'] = true;
validAuthChars['/'] = true;
}
-
+
static final boolean isValidAuthChar(byte b) {
return validAuthChars[0xff & b];
}
-
+
private void checkAuths() {
Set<ByteSequence> sortedAuths = new TreeSet<ByteSequence>(auths);
-
+
for (ByteSequence bs : sortedAuths) {
if (bs.length() == 0) {
throw new IllegalArgumentException("Empty authorization");
}
-
+
authsList.add(bs.toArray());
}
}
-
+
/**
- * Constructs an authorization object from a collection of string authorizations that have each already been encoded as UTF-8 bytes. Warning: This method
- * does not verify that each encoded string is valid UTF-8.
+ * Constructs an authorization object from a collection of string authorizations that have each already been encoded as UTF-8 bytes. Warning: This method does
+ * not verify that each encoded string is valid UTF-8.
*
- * @param authorizations collection of authorizations, as strings encoded in UTF-8
- * @throws IllegalArgumentException if authorizations is null
+ * @param authorizations
+ * collection of authorizations, as strings encoded in UTF-8
+ * @throws IllegalArgumentException
+ * if authorizations is null
* @see #Authorizations(String...)
*/
public Authorizations(Collection<byte[]> authorizations) {
@@ -112,13 +114,15 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza
auths.add(new ArrayByteSequence(auth));
checkAuths();
}
-
+
/**
* Constructs an authorization object from a list of string authorizations that have each already been encoded as UTF-8 bytes. Warning: This method does not
* verify that each encoded string is valid UTF-8.
*
- * @param authorizations list of authorizations, as strings encoded in UTF-8 and placed in buffers
- * @throws IllegalArgumentException if authorizations is null
+ * @param authorizations
+ * list of authorizations, as strings encoded in UTF-8 and placed in buffers
+ * @throws IllegalArgumentException
+ * if authorizations is null
* @see #Authorizations(String...)
*/
public Authorizations(List<ByteBuffer> authorizations) {
@@ -128,19 +132,20 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza
}
checkAuths();
}
-
+
/**
* Constructs an authorizations object from a serialized form. This is NOT a constructor for a set of authorizations of size one. Warning: This method does
* not verify that the encoded serialized form is valid UTF-8.
*
* @param authorizations
* a serialized authorizations string produced by {@link #getAuthorizationsArray()} or {@link #serialize()}, converted to UTF-8 bytes
- * @throws IllegalArgumentException if authorizations is null
+ * @throws IllegalArgumentException
+ * if authorizations is null
*/
public Authorizations(byte[] authorizations) {
-
+
ArgumentChecker.notNull(authorizations);
-
+
String authsString = new String(authorizations, Constants.UTF8);
if (authsString.startsWith(HEADER)) {
// it's the new format
@@ -159,25 +164,26 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza
setAuthorizations(authsString.split(","));
}
}
-
+
/**
* Constructs an empty set of authorizations.
*
* @see #Authorizations(String...)
*/
public Authorizations() {}
-
+
/**
* Constructs an authorizations object from a set of human-readable authorizations.
*
* @param authorizations
* array of authorizations
- * @throws IllegalArgumentException if authorizations is null
+ * @throws IllegalArgumentException
+ * if authorizations is null
*/
public Authorizations(String... authorizations) {
setAuthorizations(authorizations);
}
-
+
private void setAuthorizations(String... authorizations) {
ArgumentChecker.notNull(authorizations);
auths.clear();
@@ -185,10 +191,10 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza
str = str.trim();
auths.add(new ArrayByteSequence(str.getBytes(Constants.UTF8)));
}
-
+
checkAuths();
}
-
+
/**
* Returns a serialized form of these authorizations.
*
@@ -198,10 +204,10 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza
public byte[] getAuthorizationsArray() {
return serialize().getBytes(Constants.UTF8);
}
-
+
/**
* Gets the authorizations in sorted order. The returned list is not modifiable.
- *
+ *
* @return authorizations, each as a string encoded in UTF-8
* @see #Authorizations(Collection)
*/
@@ -214,17 +220,16 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza
}
return Collections.unmodifiableList(copy);
}
-
+
/**
* Gets the authorizations in sorted order. The returned list is not modifiable.
- *
+ *
* @return authorizations, each as a string encoded in UTF-8 and within a buffer
- * @see #Authorizations(List)
*/
public List<ByteBuffer> getAuthorizationsBB() {
return ByteBufferUtil.toImmutableByteBufferList(getAuthorizations());
}
-
+
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
@@ -234,56 +239,59 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza
sep = ",";
sb.append(new String(auth.toArray(), Constants.UTF8));
}
-
+
return sb.toString();
}
-
+
/**
* Checks whether this object contains the given authorization.
- *
- * @param auth authorization, as a string encoded in UTF-8
+ *
+ * @param auth
+ * authorization, as a string encoded in UTF-8
* @return true if authorization is in this collection
*/
public boolean contains(byte[] auth) {
return auths.contains(new ArrayByteSequence(auth));
}
-
+
/**
* Checks whether this object contains the given authorization. Warning: This method does not verify that the encoded string is valid UTF-8.
- *
- * @param auth authorization, as a string encoded in UTF-8
+ *
+ * @param auth
+ * authorization, as a string encoded in UTF-8
* @return true if authorization is in this collection
*/
@Override
public boolean contains(ByteSequence auth) {
return auths.contains(auth);
}
-
+
/**
* Checks whether this object contains the given authorization.
- *
- * @param auth authorization
+ *
+ * @param auth
+ * authorization
* @return true if authorization is in this collection
*/
public boolean contains(String auth) {
return auths.contains(auth.getBytes(Constants.UTF8));
}
-
+
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
-
+
if (o instanceof Authorizations) {
Authorizations ao = (Authorizations) o;
-
+
return auths.equals(ao.auths);
}
-
+
return false;
}
-
+
@Override
public int hashCode() {
int result = 0;
@@ -291,34 +299,33 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza
result += b.hashCode();
return result;
}
-
+
/**
* Gets the size of this collection of authorizations.
- *
+ *
* @return collection size
*/
public int size() {
return auths.size();
}
-
+
/**
* Checks if this collection of authorizations is empty.
- *
+ *
* @return true if this collection contains no authorizations
*/
public boolean isEmpty() {
return auths.isEmpty();
}
-
+
@Override
public Iterator<byte[]> iterator() {
return getAuthorizations().iterator();
}
-
+
/**
- * Returns a serialized form of these authorizations. Convert the returned
- * string to UTF-8 bytes to deserialize with {@link #Authorizations(byte[])}.
- *
+ * Returns a serialized form of these authorizations. Convert the returned string to UTF-8 bytes to deserialize with {@link #Authorizations(byte[])}.
+ *
* @return serialized form of authorizations
*/
public String serialize() {
@@ -329,7 +336,7 @@ public class Authorizations implements Iterable<byte[]>, Serializable, Authoriza
sep = ",";
sb.append(new String(Base64.encodeBase64(auth), Constants.UTF8));
}
-
+
return sb.toString();
}
}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/063c88d7/core/src/main/java/org/apache/accumulo/core/security/Credentials.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/accumulo/core/security/Credentials.java b/core/src/main/java/org/apache/accumulo/core/security/Credentials.java
index f04e115..5afc6e8 100644
--- a/core/src/main/java/org/apache/accumulo/core/security/Credentials.java
+++ b/core/src/main/java/org/apache/accumulo/core/security/Credentials.java
@@ -37,46 +37,50 @@ import org.apache.commons.codec.binary.Base64;
* @since 1.6.0
*/
public class Credentials {
-
+
private String principal;
private AuthenticationToken token;
-
+
/**
* Creates a new credentials object.
- *
- * @param principal unique identifier for the entity (e.g. a user or service) authorized for these credentials
- * @param token authentication token used to prove that the principal for these credentials has been properly verified
+ *
+ * @param principal
+ * unique identifier for the entity (e.g. a user or service) authorized for these credentials
+ * @param token
+ * authentication token used to prove that the principal for these credentials has been properly verified
*/
public Credentials(String principal, AuthenticationToken token) {
this.principal = principal;
this.token = token;
}
-
+
/**
* Gets the principal.
- *
+ *
* @return unique identifier for the entity (e.g. a user or service) authorized for these credentials
*/
public String getPrincipal() {
return principal;
}
-
+
/**
* Gets the authentication token.
- *
+ *
* @return authentication token used to prove that the principal for these credentials has been properly verified
*/
public AuthenticationToken getToken() {
return token;
}
-
+
/**
* Converts the current object to the relevant thrift type. The object returned from this contains a non-destroyable version of the
* {@link AuthenticationToken}, so this should be used just before placing on the wire, and references to it should be tightly controlled.
- *
- * @param instance client instance
+ *
+ * @param instance
+ * client instance
* @return Thrift credentials
- * @throws RuntimeException if the authentication token has been destroyed (expired)
+ * @throws RuntimeException
+ * if the authentication token has been destroyed (expired)
*/
public TCredentials toThrift(Instance instance) {
TCredentials tCreds = new TCredentials(getPrincipal(), getToken().getClass().getName(),
@@ -85,24 +89,24 @@ public class Credentials {
throw new RuntimeException("Token has been destroyed", new AccumuloSecurityException(getPrincipal(), SecurityErrorCode.TOKEN_EXPIRED));
return tCreds;
}
-
+
/**
* Converts the current object to a serialized form. The object returned from this contains a non-destroyable version of the {@link AuthenticationToken}, so
* references to it should be tightly controlled.
- *
+ *
* @return serialized form of these credentials
- * @throws AccumuloSecurityException
*/
public final String serialize() {
return (getPrincipal() == null ? "-" : Base64.encodeBase64String(getPrincipal().getBytes(Constants.UTF8))) + ":"
+ (getToken() == null ? "-" : Base64.encodeBase64String(getToken().getClass().getName().getBytes(Constants.UTF8))) + ":"
+ (getToken() == null ? "-" : Base64.encodeBase64String(AuthenticationTokenSerializer.serialize(getToken())));
}
-
+
/**
* Converts the serialized form to an instance of {@link Credentials}. The original serialized form will not be affected.
- *
- * @param serializedForm serialized form of credentials
+ *
+ * @param serializedForm
+ * serialized form of credentials
* @return deserialized credentials
*/
public static final Credentials deserialize(String serializedForm) {
@@ -116,12 +120,12 @@ public class Credentials {
}
return new Credentials(principal, token);
}
-
+
@Override
public int hashCode() {
return getPrincipal() == null ? 0 : getPrincipal().hashCode();
}
-
+
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof Credentials))
@@ -133,7 +137,7 @@ public class Credentials {
boolean tEq = getToken() == null ? (other.getToken() == null) : (getToken().equals(other.getToken()));
return tEq;
}
-
+
@Override
public String toString() {
return getClass().getName() + ":" + getPrincipal() + ":" + (getToken() == null ? null : getToken().getClass().getName()) + ":<hidden>";
http://git-wip-us.apache.org/repos/asf/accumulo/blob/063c88d7/test/src/main/java/org/apache/accumulo/test/randomwalk/State.java
----------------------------------------------------------------------
diff --git a/test/src/main/java/org/apache/accumulo/test/randomwalk/State.java b/test/src/main/java/org/apache/accumulo/test/randomwalk/State.java
index 5998eef..38cf8b7 100644
--- a/test/src/main/java/org/apache/accumulo/test/randomwalk/State.java
+++ b/test/src/main/java/org/apache/accumulo/test/randomwalk/State.java
@@ -29,7 +29,6 @@ import org.apache.accumulo.core.client.ClientConfiguration;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.Instance;
import org.apache.accumulo.core.client.MultiTableBatchWriter;
-import org.apache.accumulo.core.client.MutationsRejectedException;
import org.apache.accumulo.core.client.ZooKeeperInstance;
import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
@@ -37,25 +36,25 @@ import org.apache.accumulo.core.security.Credentials;
import org.apache.log4j.Logger;
public class State {
-
+
private static final Logger log = Logger.getLogger(State.class);
private HashMap<String,Object> stateMap = new HashMap<String,Object>();
private Properties props;
private int numVisits = 0;
private int maxVisits = Integer.MAX_VALUE;
-
+
private MultiTableBatchWriter mtbw = null;
private Connector connector = null;
private Instance instance = null;
-
+
State(Properties props) {
this.props = props;
}
-
+
public void setMaxVisits(int num) {
maxVisits = num;
}
-
+
public void visitedNode() throws Exception {
numVisits++;
if (numVisits > maxVisits) {
@@ -63,26 +62,26 @@ public class State {
throw new Exception("Visited max number (" + maxVisits + ") of nodes");
}
}
-
+
public String getPid() {
return ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
}
-
+
public void set(String key, Object value) {
stateMap.put(key, value);
}
-
+
public Object get(String key) {
if (stateMap.containsKey(key) == false) {
throw new RuntimeException("State does not contain " + key);
}
return stateMap.get(key);
}
-
+
public HashMap<String,Object> getMap() {
return stateMap;
}
-
+
/**
*
* @return a copy of Properties, so accidental changes don't affect the framework
@@ -90,38 +89,38 @@ public class State {
public Properties getProperties() {
return new Properties(props);
}
-
+
public String getString(String key) {
return (String) stateMap.get(key);
}
-
+
public Long getLong(String key) {
return (Long) stateMap.get(key);
}
-
+
public String getProperty(String key) {
return props.getProperty(key);
}
-
+
public Connector getConnector() throws AccumuloException, AccumuloSecurityException {
if (connector == null) {
connector = getInstance().getConnector(getUserName(), getToken());
}
return connector;
}
-
+
public Credentials getCredentials() {
return new Credentials(getUserName(), getToken());
}
-
+
public String getUserName() {
return props.getProperty("USERNAME");
}
-
+
public AuthenticationToken getToken() {
return new PasswordToken(props.getProperty("PASSWORD"));
}
-
+
public Instance getInstance() {
if (instance == null) {
String instance = props.getProperty("INSTANCE");
@@ -130,7 +129,7 @@ public class State {
}
return instance;
}
-
+
public MultiTableBatchWriter getMultiTableBatchWriter() {
if (mtbw == null) {
long maxMem = Long.parseLong(props.getProperty("MAX_MEM"));
@@ -141,30 +140,30 @@ public class State {
}
return mtbw;
}
-
+
public boolean isMultiTableBatchWriterInitialized() {
return mtbw != null;
}
-
+
public void resetMultiTableBatchWriter() {
if (!mtbw.isClosed()) {
log.warn("Setting non-closed MultiTableBatchWriter to null (leaking resources)");
}
-
+
mtbw = null;
}
-
+
public String getMapReduceJars() {
-
+
String acuHome = System.getenv("ACCUMULO_HOME");
String zkHome = System.getenv("ZOOKEEPER_HOME");
-
+
if (acuHome == null || zkHome == null) {
throw new RuntimeException("ACCUMULO or ZOOKEEPER home not set!");
}
-
+
String retval = null;
-
+
File zkLib = new File(zkHome);
String[] files = zkLib.list();
for (int i = 0; i < files.length; i++) {
@@ -177,12 +176,12 @@ public class State {
}
}
}
-
+
File libdir = new File(acuHome + "/lib");
for (String jar : "accumulo-core accumulo-server-base accumulo-fate accumulo-trace libthrift".split(" ")) {
retval += String.format(",%s/%s.jar", libdir.getAbsolutePath(), jar);
}
-
+
return retval;
}
}