use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class ThriftClientHandler method bulkImport.
@Override
public List<TKeyExtent> bulkImport(TInfo tinfo, TCredentials credentials, final long tid, final Map<TKeyExtent, Map<String, MapFileInfo>> files, final boolean setTime) throws ThriftSecurityException {
if (!security.canPerformSystemActions(credentials)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
}
try {
return transactionWatcher.run(Constants.BULK_ARBITRATOR_TYPE, tid, () -> {
List<TKeyExtent> failures = new ArrayList<>();
for (Entry<TKeyExtent, Map<String, MapFileInfo>> entry : files.entrySet()) {
TKeyExtent tke = entry.getKey();
Map<String, MapFileInfo> fileMap = entry.getValue();
Map<TabletFile, MapFileInfo> fileRefMap = new HashMap<>();
for (Entry<String, MapFileInfo> mapping : fileMap.entrySet()) {
Path path = new Path(mapping.getKey());
FileSystem ns = context.getVolumeManager().getFileSystemByPath(path);
path = ns.makeQualified(path);
fileRefMap.put(new TabletFile(path), mapping.getValue());
}
Tablet importTablet = server.getOnlineTablet(KeyExtent.fromThrift(tke));
if (importTablet == null) {
failures.add(tke);
} else {
try {
importTablet.importMapFiles(tid, fileRefMap, setTime);
} catch (IOException ioe) {
log.info("files {} not imported to {}: {}", fileMap.keySet(), KeyExtent.fromThrift(tke), ioe.getMessage());
failures.add(tke);
}
}
}
return failures;
});
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class ThriftClientHandler method unloadTablet.
@Override
public void unloadTablet(TInfo tinfo, TCredentials credentials, String lock, TKeyExtent textent, TUnloadTabletGoal goal, long requestTime) {
try {
checkPermission(credentials, lock, "unloadTablet");
} catch (ThriftSecurityException e) {
log.error("Caller doesn't have permission to unload a tablet", e);
throw new RuntimeException(e);
}
KeyExtent extent = KeyExtent.fromThrift(textent);
server.resourceManager.addMigration(extent, new UnloadTabletHandler(server, extent, goal, requestTime));
}
use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class AuditedSecurityOperation method canScan.
@Override
public boolean canScan(TCredentials credentials, TableId tableId, NamespaceId namespaceId, TRange range, List<TColumn> columns, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, List<ByteBuffer> authorizations) throws ThriftSecurityException {
if (shouldAudit(credentials, tableId)) {
Range convertedRange = new Range(range);
List<String> convertedColumns = truncate(columns.stream().map(Column::new).collect(Collectors.toList()));
String tableName = getTableName(tableId);
try {
boolean canScan = super.canScan(credentials, tableId, namespaceId);
audit(credentials, canScan, CAN_SCAN_AUDIT_TEMPLATE, tableName, getAuthString(authorizations), convertedRange, convertedColumns, ssiList, ssio);
return canScan;
} catch (ThriftSecurityException ex) {
audit(credentials, ex, CAN_SCAN_AUDIT_TEMPLATE, getAuthString(authorizations), tableId, convertedRange, convertedColumns, ssiList, ssio);
throw ex;
}
} else {
return super.canScan(credentials, tableId, namespaceId);
}
}
use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class SecurityOperation method grantTablePermission.
public void grantTablePermission(TCredentials c, String user, TableId tableId, TablePermission permission, NamespaceId namespaceId) throws ThriftSecurityException {
if (!canGrantTable(c, user, tableId, namespaceId))
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
targetUserExists(user);
try {
permHandle.grantTablePermission(user, tableId.canonical(), permission);
log.info("Granted table permission {} for user {} on the table {} at the request of user {}", permission, user, tableId, c.getPrincipal());
} catch (AccumuloSecurityException e) {
throw e.asThriftException();
} catch (TableNotFoundException e) {
throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.TABLE_DOESNT_EXIST);
}
}
use of org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException in project accumulo by apache.
the class SecurityOperation method _hasTablePermission.
/**
* Checks if a user has a table permission<br>
* This cannot check if a system user has permission.
*
* @return true if a user exists and has permission; false otherwise
*/
protected boolean _hasTablePermission(String user, TableId table, TablePermission permission, boolean useCached) throws ThriftSecurityException {
targetUserExists(user);
@SuppressWarnings("deprecation") TableId replicationTableId = org.apache.accumulo.core.replication.ReplicationTable.ID;
if ((table.equals(MetadataTable.ID) || table.equals(RootTable.ID) || table.equals(replicationTableId)) && permission.equals(TablePermission.READ))
return true;
try {
if (useCached)
return permHandle.hasCachedTablePermission(user, table.canonical(), permission);
return permHandle.hasTablePermission(user, table.canonical(), permission);
} catch (TableNotFoundException e) {
throw new ThriftSecurityException(user, SecurityErrorCode.TABLE_DOESNT_EXIST);
}
}
Aggregations