Author: kturner
Date: Thu Mar 7 22:10:33 2013
New Revision: 1454126
URL: http://svn.apache.org/r1454126
Log:
ACCUMULO-1018 applied patch from Kevin Faro that adds table info to security
exception messages
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java?rev=1454126&r1=1454125&r2=1454126&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/AccumuloSecurityException.java
Thu Mar 7 22:10:33 2013
@@ -18,6 +18,7 @@ package org.apache.accumulo.core.client;
import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
import org.apache.accumulo.core.client.impl.thrift.ThriftSecurityException;
+import org.apache.commons.lang.StringUtils;
/**
* An Accumulo Exception for security violations, authentication failures,
authorization failures, etc.
@@ -61,6 +62,7 @@ public class AccumuloSecurityException e
}
private String user;
+ private String tableInfo;
private SecurityErrorCode errorCode;
/**
@@ -89,6 +91,23 @@ public class AccumuloSecurityException e
* the relevant user for the security violation
* @param errorcode
* the specific reason for this exception
+ * @param tableInfo
+ * the relevant tableInfo for the security violation
+ * @param cause
+ * the exception that caused this violation
+ */
+ public AccumuloSecurityException(final String user, final SecurityErrorCode
errorcode, final String tableInfo, final Throwable cause) {
+ super(getDefaultErrorMessage(errorcode), cause);
+ this.user = user;
+ this.errorCode = errorcode == null ?
SecurityErrorCode.DEFAULT_SECURITY_ERROR : errorcode;
+ this.tableInfo = tableInfo;
+ }
+
+ /**
+ * @param user
+ * the relevant user for the security violation
+ * @param errorcode
+ * the specific reason for this exception
*/
public AccumuloSecurityException(final String user, final SecurityErrorCode
errorcode) {
super(getDefaultErrorMessage(errorcode));
@@ -97,6 +116,21 @@ public class AccumuloSecurityException e
}
/**
+ * @param user
+ * the relevant user for the security violation
+ * @param errorcode
+ * the specific reason for this exception
+ * @param tableInfo
+ * the relevant tableInfo for the security violation
+ */
+ public AccumuloSecurityException(final String user, final SecurityErrorCode
errorcode, final String tableInfo) {
+ super(getDefaultErrorMessage(errorcode));
+ this.user = user;
+ this.errorCode = errorcode == null ?
SecurityErrorCode.DEFAULT_SECURITY_ERROR : errorcode;
+ this.tableInfo = tableInfo;
+ }
+
+ /**
* @return the relevant user for the security violation
*/
public String getUser() {
@@ -108,6 +142,17 @@ public class AccumuloSecurityException e
}
/**
+ * @return the relevant tableInfo for the security violation
+ */
+ public String getTableInfo() {
+ return tableInfo;
+ }
+
+ public void setTableInfo(String tableInfo) {
+ this.tableInfo = tableInfo;
+ }
+
+ /**
* @return the specific reason for this exception
*/
public SecurityErrorCode getErrorCode() {
@@ -115,6 +160,13 @@ public class AccumuloSecurityException e
}
public String getMessage() {
- return "Error " + errorCode + " for user " + user + " - " +
super.getMessage();
+ StringBuilder message = new StringBuilder();
+ message.append("Error ").append(errorCode);
+ message.append(" for user ").append(user);
+ if(!StringUtils.isEmpty(tableInfo)) {
+ message.append(" on table ").append(tableInfo);
+ }
+ message.append(" - ").append(super.getMessage());
+ return message.toString();
}
}
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java?rev=1454126&r1=1454125&r2=1454126&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/MutationsRejectedException.java
Thu Mar 7 22:10:33 2013
@@ -19,10 +19,12 @@ package org.apache.accumulo.core.client;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.accumulo.core.client.impl.Tables;
import org.apache.accumulo.core.client.impl.thrift.SecurityErrorCode;
import org.apache.accumulo.core.data.ConstraintViolationSummary;
import org.apache.accumulo.core.data.KeyExtent;
@@ -33,7 +35,7 @@ import org.apache.accumulo.core.data.Key
*/
public class MutationsRejectedException extends AccumuloException {
private static final long serialVersionUID = 1L;
-
+
private List<ConstraintViolationSummary> cvsl;
private Map<KeyExtent,Set<SecurityErrorCode>> af;
private Collection<String> es;
@@ -49,9 +51,9 @@ public class MutationsRejectedException
* @param unknownErrors
* number of unknown errors
*/
- public MutationsRejectedException(List<ConstraintViolationSummary> cvsList,
HashMap<KeyExtent,Set<SecurityErrorCode>> hashMap,
+ public MutationsRejectedException(Instance instance,
List<ConstraintViolationSummary> cvsList,
HashMap<KeyExtent,Set<SecurityErrorCode>> hashMap,
Collection<String> serverSideErrors, int unknownErrors, Throwable cause)
{
- super("# constraint violations : " + cvsList.size() + " security codes: "
+ hashMap.values() + " # server errors " + serverSideErrors.size()
+ super("# constraint violations : " + cvsList.size() + " security codes: "
+ format(hashMap, instance) + " # server errors " + serverSideErrors.size()
+ " # exceptions " + unknownErrors, cause);
this.cvsl = cvsList;
this.af = hashMap;
@@ -59,6 +61,22 @@ public class MutationsRejectedException
this.unknownErrors = unknownErrors;
}
+ private static String format(HashMap<KeyExtent,Set<SecurityErrorCode>>
hashMap, Instance instance) {
+ Map<String, Set<SecurityErrorCode>> errorMap = new
HashMap<String,Set<SecurityErrorCode>>();
+
+ for(KeyExtent ke : hashMap.keySet()) {
+ String tableInfo = Tables.getPrintableTableInfoFromId(instance,
ke.getTableId().toString());
+
+ if(!errorMap.containsKey(tableInfo)) {
+ errorMap.put(tableInfo, new HashSet<SecurityErrorCode>());
+ }
+
+ errorMap.get(tableInfo).addAll(hashMap.get(ke));
+ }
+
+ return errorMap.toString();
+ }
+
/**
* @return the internal list of constraint violations
*/
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java?rev=1454126&r1=1454125&r2=1454126&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/admin/TableOperationsImpl.java
Thu Mar 7 22:10:33 2013
@@ -80,6 +80,7 @@ import org.apache.accumulo.core.security
import org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException;
import org.apache.accumulo.core.tabletserver.thrift.TabletClientService;
import org.apache.accumulo.core.util.ArgumentChecker;
+import org.apache.accumulo.core.util.ByteBufferUtil;
import org.apache.accumulo.core.util.CachedConfiguration;
import org.apache.accumulo.core.util.LocalityGroupUtil;
import org.apache.accumulo.core.util.MetadataTable;
@@ -289,7 +290,9 @@ public class TableOperationsImpl extends
Tables.clearCache(instance);
return ret;
} catch (ThriftSecurityException e) {
- throw new AccumuloSecurityException(e.user, e.code, e);
+ String tableName = ByteBufferUtil.toString(args.get(0));
+ String tableInfo = Tables.getPrintableTableInfoFromName(instance,
tableName);
+ throw new AccumuloSecurityException(e.user, e.code, tableInfo, e);
} catch (ThriftTableOperationException e) {
switch (e.getType()) {
case EXISTS:
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java?rev=1454126&r1=1454125&r2=1454126&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java
Thu Mar 7 22:10:33 2013
@@ -102,6 +102,26 @@ public class Tables {
return tableId == null ? "(NAME:" + tableName + ")" : tableId;
}
+ public static String getPrintableTableInfoFromId(Instance instance, String
tableId) {
+ String tableName = null;
+ try {
+ tableName = getTableName(instance, tableId);
+ } catch (TableNotFoundException e) {
+ //handled in the string formatting
+ }
+ return tableName == null ? String.format("?(ID:%s)", tableId) :
String.format("%s(ID:%s)", tableName, tableId);
+ }
+
+ public static String getPrintableTableInfoFromName(Instance instance, String
tableName) {
+ String tableId = null;
+ try {
+ tableId = getTableId(instance, tableName);
+ } catch (TableNotFoundException e) {
+ //handled in the string formatting
+ }
+ return tableId == null ? String.format("%s(?)", tableName) :
String.format("%s(ID:%s)", tableName, tableId);
+ }
+
public static TableState getTableState(Instance instance, String tableId) {
String statePath = ZooUtil.getRoot(instance) + Constants.ZTABLES + "/" +
tableId + Constants.ZTABLE_STATE;
ZooCache zc = getZooCache(instance);
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java?rev=1454126&r1=1454125&r2=1454126&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchReaderIterator.java
Thu Mar 7 22:10:33 2013
@@ -323,6 +323,10 @@ public class TabletServerBatchReaderIter
doLookups(binnedRanges, receiver, columns);
}
+ private String getTableInfo() {
+ return Tables.getPrintableTableInfoFromId(instance, table);
+ }
+
private class QueryTask implements Runnable {
private String tsLocation;
@@ -376,6 +380,7 @@ public class TabletServerBatchReaderIter
locator.invalidateCache(tsLocation);
log.debug(e.getMessage(), e);
} catch (AccumuloSecurityException e) {
+ e.setTableInfo(getTableInfo());
log.debug(e.getMessage(), e);
Tables.clearCache(instance);
@@ -405,6 +410,7 @@ public class TabletServerBatchReaderIter
log.debug(e.getMessage(), e);
fatalException = e;
} catch (AccumuloSecurityException e) {
+ e.setTableInfo(getTableInfo());
log.debug(e.getMessage(), e);
fatalException = e;
} catch (Throwable t) {
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java?rev=1454126&r1=1454125&r2=1454126&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/TabletServerBatchWriter.java
Thu Mar 7 22:10:33 2013
@@ -522,7 +522,7 @@ public class TabletServerBatchWriter {
private void checkForFailures() throws MutationsRejectedException {
if (somethingFailed) {
List<ConstraintViolationSummary> cvsList = violations.asList();
- throw new MutationsRejectedException(cvsList, new
HashMap<KeyExtent,Set<SecurityErrorCode>>(authorizationFailures),
serverSideErrors, unknownErrors, lastUnknownError);
+ throw new MutationsRejectedException(instance, cvsList, new
HashMap<KeyExtent,Set<SecurityErrorCode>>(authorizationFailures),
serverSideErrors, unknownErrors, lastUnknownError);
}
}
Modified:
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java
URL:
http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java?rev=1454126&r1=1454125&r2=1454126&view=diff
==============================================================================
---
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java
(original)
+++
accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/impl/ThriftScanner.java
Thu Mar 7 22:10:33 2013
@@ -300,6 +300,7 @@ public class ThriftScanner {
Tables.clearCache(instance);
if (!Tables.exists(instance, scanState.tableName.toString()))
throw new TableDeletedException(scanState.tableName.toString());
+ e.setTableInfo(Tables.getPrintableTableInfoFromId(instance,
scanState.tableName.toString()));
throw e;
} catch (TApplicationException tae) {
throw new AccumuloServerException(loc.tablet_location, tae);