本文整理汇总了Java中org.apache.accumulo.core.security.Authorizations类的典型用法代码示例。如果您正苦于以下问题:Java Authorizations类的具体用法?Java Authorizations怎么用?Java Authorizations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Authorizations类属于org.apache.accumulo.core.security包,在下文中一共展示了Authorizations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAuthorizations
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
public static Authorizations getAuthorizations(String sessionId) {
if (!StringUtils.isEmpty(sessionId)) {
Authentication auth = CACHE.asMap().get(sessionId);
if (null != auth) {
Collection<? extends GrantedAuthority> authorities = CACHE.asMap().get(sessionId).getAuthorities();
String[] auths = new String[authorities.size()];
final AtomicInteger i = new AtomicInteger(0);
authorities.forEach(a -> auths[i.getAndIncrement()] = a.getAuthority());
return new Authorizations(auths);
} else {
return null;
}
} else {
throw new IllegalArgumentException("session id cannot be null");
}
}
示例2: parseJson
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
/**
* Parse the user from a JSON object.
*
* @param userObject
* JSON object to parse.
* @return The parsed user object.
*/
static User parseJson(JsonObject userObject) throws InvalidKeySpecException, NoSuchAlgorithmException {
String id = userObject.getAsJsonPrimitive("id").getAsString();
String password = userObject.getAsJsonPrimitive("password").getAsString();
JsonArray authArray = userObject.getAsJsonArray("authorizations");
String[] auths = new String[authArray.size()];
for (int i = 0; i < auths.length; i++) {
auths[i] = authArray.get(i).getAsString();
}
EncryptionKeyContainer encryptionKeys = LocalEncryptionKeyContainer.read(new InputStreamReader(User.class.getResourceAsStream(userObject
.getAsJsonPrimitive("encryptionKeys").getAsString())));
Map<ValueSigner,SignatureKeyContainer> signatureKeys = new HashMap<>();
for (Entry<String,JsonElement> entry : userObject.getAsJsonObject("signatureKeys").entrySet()) {
signatureKeys.put(ValueSigner.valueOf(entry.getKey()),
LocalSignatureKeyContainer.read(new InputStreamReader(User.class.getResourceAsStream(entry.getValue().getAsJsonPrimitive().getAsString()))));
}
return new User(id, password, new Authorizations(auths), encryptionKeys, signatureKeys);
}
示例3: SignedScanner
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
/**
* Create an signed scanner.
*
* @param connector
* The connector for the Accumulo instance.
* @param tableName
* Name of the table to write to.
* @param authorizations
* The authorizations this user has for querying Accumulo.
* @param signatureConfig
* Configuration for the verification.
* @param keys
* Container with the keys to use for signatures.
*/
public SignedScanner(Connector connector, String tableName, Authorizations authorizations, SignatureConfig signatureConfig, SignatureKeyContainer keys)
throws TableNotFoundException {
checkArgument(connector != null, "connection is null");
checkArgument(tableName != null, "tableName is null");
checkArgument(authorizations != null, "authorizations is null");
checkArgument(signatureConfig != null, "config is null");
checkArgument(keys != null, "keys is null");
this.valueScanner = connector.createScanner(tableName, authorizations);
this.verifier = new EntrySigner(signatureConfig, keys);
if (signatureConfig.destination == SignatureConfig.Destination.SEPARATE_TABLE) {
this.signatureScanner = connector.createScanner(signatureConfig.destinationTable, authorizations);
} else {
this.signatureScanner = null;
}
}
示例4: SignedBatchScanner
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
/**
* Create an encrypted batch scanner.
*
* @param connector
* The connector for the Accumulo instance.
* @param tableName
* Name of the table to write to.
* @param authorizations
* The authorizations this user has for querying Accumulo.
* @param numQueryThreads
* Maximimum number of query threads to use for this scanner.
* @param signatureConfig
* Configuration for the decryption.
* @param keys
* Container with the keys to use for decryption.
*/
public SignedBatchScanner(Connector connector, String tableName, Authorizations authorizations, int numQueryThreads, SignatureConfig signatureConfig,
SignatureKeyContainer keys) throws TableNotFoundException {
checkArgument(connector != null, "connection is null");
checkArgument(tableName != null, "tableName is null");
checkArgument(authorizations != null, "authorizations is null");
checkArgument(signatureConfig != null, "config is null");
checkArgument(keys != null, "keys is null");
this.valueScanner = connector.createBatchScanner(tableName, authorizations, numQueryThreads);
this.verifier = new EntrySigner(signatureConfig, keys);
if (signatureConfig.destination == SignatureConfig.Destination.SEPARATE_TABLE) {
this.signatureScanner = connector.createBatchScanner(signatureConfig.destinationTable, authorizations, numQueryThreads);
} else {
this.signatureScanner = null;
}
}
示例5: getRawDataScannerByTimeSpan
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
/**
* Builds a Range from the given start and end timestamp and returns a batch scanner.
*
* @param startTime start time as string
* @param endTime endt time as string
* @return the batch scanner
* @throws AccumuloSecurityException
* @throws AccumuloException
* @throws TableNotFoundException
*/
public BatchScanner getRawDataScannerByTimeSpan(String startTime, String endTime) throws AccumuloSecurityException, AccumuloException, TableNotFoundException {
Connector conn = getConnector();
Authorizations auths = new Authorizations(AccumuloIdentifiers.AUTHORIZATION.toString());
BatchScanner scan = conn.createBatchScanner(TableIdentifier.RAW_TWITTER_DATA.get(), auths, numberOfThreadsForScan);
addReduceIterator(scan);
ByteBuffer bb = ByteBuffer.allocate(Long.BYTES);
bb.putLong(Long.parseLong(startTime));
ByteBuffer bb2 = ByteBuffer.allocate(Long.BYTES); //TODO: make end inclusive again
bb2.putLong(Long.parseLong(endTime));
List<Range> rangeList = new ArrayList<>();
Range r = new Range(new Text(bb.array()), new Text(bb2.array()));
rangeList.add(r);
scan.setRanges(rangeList);
return scan;
}
示例6: testAmc
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
@Test
public void testAmc() throws TableExistsException, AccumuloSecurityException, AccumuloException, TableNotFoundException {
Connector conn = amc.getConnector();
System.out.println("I am connected as: " + conn.whoami());
conn.tableOperations().create("TestTable");
Mutation m1 = new Mutation("row1");
String testString = "42";
m1.put("CF", "CQ", testString);
BatchWriter bw = conn.createBatchWriter("TestTable", new BatchWriterConfig());
bw.addMutation(m1);
bw.close();
Scanner s = conn.createScanner("TestTable", new Authorizations("standard"));
for(Map.Entry<Key, Value> entry: s){
System.out.println(entry.getKey());
System.out.println(entry.getValue());
assertEquals(entry.getValue().toString(), testString);
}
s.close();
}
示例7: createBatchWriter
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
/**
* creates a batchwriter to write data to accumulo
*
* @param table to write data into
* @return a ready to user batch writer object
* @throws AccumuloSecurityException
* @throws AccumuloException
* @throws TableNotFoundException
*/
private BatchWriter createBatchWriter(String table) throws AccumuloSecurityException, AccumuloException, TableNotFoundException, TableExistsException {
final BatchWriterConfig bwConfig = new BatchWriterConfig();
// buffer max 100kb ( 100 * 1024 = 102400)
bwConfig.setMaxMemory(102400);
// buffer max 10 seconds
bwConfig.setMaxLatency(10, TimeUnit.SECONDS);
// ensure persistance
bwConfig.setDurability(Durability.SYNC);
// build the accumulo connector
Instance inst = new ZooKeeperInstance(cfg.accumuloInstanceName, cfg.accumuloZookeeper);
conn = inst.getConnector(cfg.accumuloUser, new PasswordToken(cfg.accumuloPassword));
Authorizations auths = new Authorizations(AccumuloIdentifiers.AUTHORIZATION.toString());
// create the table if not already existent
TableOperations tableOpts = conn.tableOperations();
try{
tableOpts.create(table);
} catch(Exception e) {}
// build and return the batchwriter
return conn.createBatchWriter(table, bwConfig);
}
示例8: createBatchWriter
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
/**
* creates a batchwriter to write data to accumulo
*
* @param table to write data into
* @return a ready to user batch writer object
* @throws AccumuloSecurityException
* @throws AccumuloException
* @throws TableNotFoundException
*/
private BatchWriter createBatchWriter(String table) throws AccumuloSecurityException, AccumuloException, TableNotFoundException, TableExistsException {
final BatchWriterConfig bwConfig = new BatchWriterConfig();
// buffer max 100kb ( 100 * 1024 = 102400)
bwConfig.setMaxMemory(102400);
// buffer max 10 seconds
bwConfig.setMaxLatency(10, TimeUnit.SECONDS);
// ensure persistance
bwConfig.setDurability(Durability.SYNC);
// build the accumulo connector
Instance inst = new ZooKeeperInstance(cfg.accumuloInstanceName, cfg.accumuloZookeeper);
conn = inst.getConnector(cfg.accumuloUser, new PasswordToken(cfg.accumuloPassword));
Authorizations auths = new Authorizations(AccumuloIdentifiers.AUTHORIZATION.toString());
// create the table if not already existent
TableOperations tableOpts = conn.tableOperations();
try{
tableOpts.create(table);
} catch(Exception e) {}
// build and return the batchwriter
return conn.createBatchWriter(table, bwConfig);
}
示例9: list
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
public List<String> list(String what, String when) throws Exception {
String row = what + ":" + when;
// its important to use an isolated scanner so that only whole mutations are seen
try (Scanner scanner = new IsolatedScanner(conn.createScanner(rTable, Authorizations.EMPTY))) {
scanner.setRange(new Range(row));
scanner.fetchColumnFamily(new Text("res"));
List<String> reservations = new ArrayList<>();
for (Entry<Key,Value> entry : scanner) {
String val = entry.getValue().toString();
reservations.add(val);
}
return reservations;
}
}
示例10: test
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
@Test
public void test() throws Exception {
Scanner scanner = conn.createScanner(tableName, new Authorizations());
scanner.fetchColumn(new Text("dir"), new Text("counts"));
assertFalse(scanner.iterator().hasNext());
ScannerOpts scanOpts = new ScannerOpts();
BatchWriterOpts bwOpts = new BatchWriterOpts();
FileCount fc = new FileCount(conn, tableName, Authorizations.EMPTY, new ColumnVisibility(), scanOpts, bwOpts);
fc.run();
ArrayList<Pair<String,String>> expected = new ArrayList<>();
expected.add(new Pair<>(QueryUtil.getRow("").toString(), "1,0,3,3"));
expected.add(new Pair<>(QueryUtil.getRow("/local").toString(), "2,1,2,3"));
expected.add(new Pair<>(QueryUtil.getRow("/local/user1").toString(), "0,2,0,2"));
expected.add(new Pair<>(QueryUtil.getRow("/local/user2").toString(), "0,0,0,0"));
int i = 0;
for (Entry<Key,Value> e : scanner) {
assertEquals(e.getKey().getRow().toString(), expected.get(i).getFirst());
assertEquals(e.getValue().toString(), expected.get(i).getSecond());
i++;
}
assertEquals(i, expected.size());
}
示例11: getClusterInfo
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
@Before
public void getClusterInfo() throws Exception {
c = getConnector();
String user = getAdminPrincipal();
String instance = c.getInstance().getInstanceName();
String keepers = c.getInstance().getZooKeepers();
AuthenticationToken token = getAdminToken();
if (token instanceof PasswordToken) {
String passwd = new String(((PasswordToken) getAdminToken()).getPassword(), UTF_8);
writeConnectionFile(getConnectionFile(), instance, keepers, user, passwd);
} else {
Assert.fail("Unknown token type: " + token);
}
fs = getCluster().getFileSystem();
dir = new Path(cluster.getTemporaryPath(), getClass().getName()).toString();
origAuths = c.securityOperations().getUserAuthorizations(user);
c.securityOperations().changeUserAuthorizations(user, new Authorizations(auths.split(",")));
}
示例12: testAgeoffFilter
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
@Test
public void testAgeoffFilter() throws Exception {
String tableName = getUniqueNames(1)[0];
c.tableOperations().create(tableName);
is = new IteratorSetting(10, AgeOffFilter.class);
AgeOffFilter.setTTL(is, 1000L);
c.tableOperations().attachIterator(tableName, is);
sleepUninterruptibly(500, TimeUnit.MILLISECONDS); // let zookeeper updates propagate.
bw = c.createBatchWriter(tableName, bwc);
Mutation m = new Mutation("foo");
m.put("a", "b", "c");
bw.addMutation(m);
bw.close();
sleepUninterruptibly(1, TimeUnit.SECONDS);
assertEquals(0, Iterators.size(c.createScanner(tableName, Authorizations.EMPTY).iterator()));
}
示例13: printAccumuloTable
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
/**
* Prints specified Accumulo table (accessible using Accumulo connector parameter)
*
* @param conn Accumulo connector of to instance with table to print
* @param accumuloTable Accumulo table to print
*/
public static void printAccumuloTable(Connector conn, String accumuloTable) {
Scanner scanner = null;
try {
scanner = conn.createScanner(accumuloTable, Authorizations.EMPTY);
} catch (TableNotFoundException e) {
throw new IllegalStateException(e);
}
Iterator<Map.Entry<Key, Value>> iterator = scanner.iterator();
System.out.println("== accumulo start ==");
while (iterator.hasNext()) {
Map.Entry<Key, Value> entry = iterator.next();
System.out.println(entry.getKey() + " " + entry.getValue());
}
System.out.println("== accumulo end ==");
}
示例14: dropGraph
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
public void dropGraph() throws Exception {
Connector connector = createConnector();
AccumuloGraphTestUtils.ensureTableExists(connector, GraphConfiguration.DEFAULT_TABLE_NAME_PREFIX);
AccumuloGraphTestUtils.dropGraph(connector, AccumuloGraph.getDataTableName(GraphConfiguration.DEFAULT_TABLE_NAME_PREFIX));
AccumuloGraphTestUtils.dropGraph(connector, AccumuloGraph.getVerticesTableName(GraphConfiguration.DEFAULT_TABLE_NAME_PREFIX));
AccumuloGraphTestUtils.dropGraph(connector, AccumuloGraph.getHistoryVerticesTableName(GraphConfiguration.DEFAULT_TABLE_NAME_PREFIX));
AccumuloGraphTestUtils.dropGraph(connector, AccumuloGraph.getEdgesTableName(GraphConfiguration.DEFAULT_TABLE_NAME_PREFIX));
AccumuloGraphTestUtils.dropGraph(connector, AccumuloGraph.getExtendedDataTableName(GraphConfiguration.DEFAULT_TABLE_NAME_PREFIX));
AccumuloGraphTestUtils.dropGraph(connector, AccumuloGraph.getHistoryEdgesTableName(GraphConfiguration.DEFAULT_TABLE_NAME_PREFIX));
AccumuloGraphTestUtils.dropGraph(connector, AccumuloGraph.getMetadataTableName(GraphConfiguration.DEFAULT_TABLE_NAME_PREFIX));
connector.securityOperations().changeUserAuthorizations(
AccumuloGraphConfiguration.DEFAULT_ACCUMULO_USERNAME,
new org.apache.accumulo.core.security.Authorizations(
VISIBILITY_A_STRING,
VISIBILITY_B_STRING,
VISIBILITY_C_STRING,
VISIBILITY_MIXED_CASE_STRING
)
);
}
示例15: getCommittedWindowId
import org.apache.accumulo.core.security.Authorizations; //导入依赖的package包/类
@Override
public long getCommittedWindowId(String appId, int operatorId)
{
byte[] value = null;
Authorizations auths = new Authorizations();
Scanner scan = null;
String columnKey = appId + "_" + operatorId + "_" + lastWindowColumnName;
lastWindowColumnBytes = columnKey.getBytes();
try {
scan = connector.createScanner(tableName, auths);
} catch (TableNotFoundException e) {
logger.error("error getting committed window id", e);
DTThrowable.rethrow(e);
}
scan.setRange(new Range(new Text(rowBytes)));
scan.fetchColumn(new Text(columnFamilyBytes), new Text(lastWindowColumnBytes));
for (Entry<Key, Value> entry : scan) {
value = entry.getValue().get();
}
if (value != null) {
long longval = toLong(value);
return longval;
}
return -1;
}