当前位置: 首页>>代码示例>>Java>>正文


Java Authorizations类代码示例

本文整理汇总了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");
    }
}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:17,代码来源:AuthCache.java

示例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);
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:29,代码来源:User.java

示例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;
  }
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:32,代码来源:SignedScanner.java

示例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;
  }
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:34,代码来源:SignedBatchScanner.java

示例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;
}
 
开发者ID:IIDP,项目名称:OSTMap,代码行数:29,代码来源:AccumuloService.java

示例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();
}
 
开发者ID:IIDP,项目名称:OSTMap,代码行数:23,代码来源:AmcHelperTest.java

示例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);
}
 
开发者ID:IIDP,项目名称:OSTMap,代码行数:33,代码来源:LanguageFrequencySink.java

示例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);
}
 
开发者ID:IIDP,项目名称:OSTMap,代码行数:34,代码来源:TermIndexSink.java

示例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;
  }
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:19,代码来源:ARS.java

示例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());
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:26,代码来源:CountIT.java

示例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(",")));
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:20,代码来源:ExamplesIT.java

示例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()));
}
 
开发者ID:apache,项目名称:accumulo-examples,代码行数:17,代码来源:ExamplesIT.java

示例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 ==");
}
 
开发者ID:apache,项目名称:fluo-recipes,代码行数:23,代码来源:FluoITHelper.java

示例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
            )
    );
}
 
开发者ID:visallo,项目名称:vertexium,代码行数:21,代码来源:AccumuloResource.java

示例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;
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:26,代码来源:AccumuloWindowStore.java


注:本文中的org.apache.accumulo.core.security.Authorizations类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。