use of org.apache.accumulo.core.security.Authorizations in project incubator-rya by apache.
the class MergeTool method createTempTableIfNeeded.
/**
* Creates the temp child table if it doesn't already exist in the parent.
* @param childTableName the name of the child table.
* @throws IOException
*/
public void createTempTableIfNeeded(final String childTableName) throws IOException {
try {
final AccumuloRdfConfiguration accumuloRdfConfiguration = new AccumuloRdfConfiguration(conf);
accumuloRdfConfiguration.setTablePrefix(childTablePrefix);
final Connector connector = AccumuloRyaUtils.setupConnector(accumuloRdfConfiguration);
if (!connector.tableOperations().exists(childTableName)) {
log.info("Creating table: " + childTableName);
connector.tableOperations().create(childTableName);
log.info("Created table: " + childTableName);
log.info("Granting authorizations to table: " + childTableName);
final SecurityOperations secOps = connector.securityOperations();
secOps.grantTablePermission(userName, childTableName, TablePermission.WRITE);
log.info("Granted authorizations to table: " + childTableName);
final Authorizations parentAuths = secOps.getUserAuthorizations(userName);
// Add child authorizations so the temp parent table can be accessed.
if (!parentAuths.equals(childAuthorizations)) {
final List<String> childAuthList = findUniqueAuthsFromChild(parentAuths.toString(), childAuthorizations.toString());
tempChildAuths = Joiner.on(",").join(childAuthList);
log.info("Adding the authorization, \"" + tempChildAuths + "\", to the parent user, \"" + userName + "\"");
final Authorizations newAuths = AccumuloRyaUtils.addUserAuths(userName, secOps, new Authorizations(tempChildAuths));
secOps.changeUserAuthorizations(userName, newAuths);
}
}
} catch (TableExistsException | AccumuloException | AccumuloSecurityException e) {
throw new IOException(e);
}
}
use of org.apache.accumulo.core.security.Authorizations in project incubator-rya by apache.
the class RowRuleMapper method flush.
private void flush(final Context context) throws IOException, InterruptedException {
try {
childDao.flush();
} catch (final RyaDAOException e) {
throw new IOException("Error writing to in-memory table", e);
}
final TableOperations ops = childConnector.tableOperations();
final SecurityOperations secOps = childConnector.securityOperations();
Authorizations childAuths;
try {
childAuths = secOps.getUserAuthorizations(childUser);
} catch (AccumuloException | AccumuloSecurityException e) {
throw new IOException("Error connecting to mock instance", e);
}
for (final String table : ops.list()) {
// Only copy Rya tables (skip system tables)
if (!table.startsWith(childTablePrefix)) {
continue;
}
compositeKey.setGroup(table);
try {
// Output every row in this mock table
int rows = 0;
final Scanner scanner = childDao.getConnector().createScanner(table, childAuths);
for (final Map.Entry<Key, Value> row : scanner) {
compositeKey.setKey(row.getKey());
compositeVal.setKey(row.getKey());
compositeVal.setValue(row.getValue());
context.write(compositeKey, compositeVal);
rows++;
}
log.info("Flushed " + rows + " in-memory rows to output (" + table + ").");
// Then clear the table
if (rows > 0) {
ops.deleteRows(table, null, null);
}
} catch (TableNotFoundException | AccumuloException | AccumuloSecurityException e) {
throw new IOException("Error flushing in-memory table", e);
}
}
// All tables should be empty
cachedStatements = 0;
}
use of org.apache.accumulo.core.security.Authorizations in project incubator-rya by apache.
the class AccumuloInstanceDriver method addAuths.
/**
* Adds authorizations to the {@link SecurityOperations} of this instance's user.
* @param auths the list of authorizations to add.
* @throws AccumuloException
* @throws AccumuloSecurityException
*/
public void addAuths(final String... auths) throws AccumuloException, AccumuloSecurityException {
final Authorizations newAuths = AccumuloRyaUtils.addUserAuths(user, secOps, auths);
secOps.changeUserAuthorizations(user, newAuths);
}
use of org.apache.accumulo.core.security.Authorizations in project incubator-rya by apache.
the class AccumuloRyaUtils method addUserAuths.
/**
* Adds authorizations to a user's authorizations list.
* @param user the name of the user to add authorizations for.
* @param secOps the {@link SecurityOperations}.
* @param auths the list of authorizations to add
* @return the {@link Authorizations}.
* @throws AccumuloException
* @throws AccumuloSecurityException
*/
public static Authorizations addUserAuths(final String user, final SecurityOperations secOps, final String... auths) throws AccumuloException, AccumuloSecurityException {
final Authorizations currentUserAuths = secOps.getUserAuthorizations(user);
final List<byte[]> authList = new ArrayList<>();
for (final byte[] currentAuth : currentUserAuths.getAuthorizations()) {
authList.add(currentAuth);
}
for (final String newAuth : auths) {
authList.add(newAuth.getBytes(StandardCharsets.UTF_8));
}
final Authorizations result = new Authorizations(authList);
return result;
}
use of org.apache.accumulo.core.security.Authorizations in project incubator-rya by apache.
the class HistoricStreamingVisibilityIT method historicResults.
/**
* Ensure historic matches are included in the result.
*/
@Test
public void historicResults() throws Exception {
// A query that finds people who talk to Eve and work at Chipotle.
final String sparql = "SELECT ?x " + "WHERE { " + "?x <http://talksTo> <http://Eve>. " + "?x <http://worksAt> <http://Chipotle>." + "}";
final Connector accumuloConn = super.getAccumuloConnector();
accumuloConn.securityOperations().changeUserAuthorizations(getUsername(), new Authorizations("U", "V", "W"));
final AccumuloRyaDAO dao = new AccumuloRyaDAO();
dao.setConnector(accumuloConn);
dao.setConf(makeConfig());
dao.init();
// Triples that are loaded into Rya before the PCJ is created.
final ValueFactory vf = new ValueFactoryImpl();
final Set<RyaStatement> historicTriples = Sets.newHashSet(makeRyaStatement(vf.createStatement(vf.createURI("http://Alice"), vf.createURI("http://talksTo"), vf.createURI("http://Eve")), "U"), makeRyaStatement(vf.createStatement(vf.createURI("http://Bob"), vf.createURI("http://talksTo"), vf.createURI("http://Eve")), "V"), makeRyaStatement(vf.createStatement(vf.createURI("http://Charlie"), vf.createURI("http://talksTo"), vf.createURI("http://Eve")), "W"), makeRyaStatement(vf.createStatement(vf.createURI("http://Eve"), vf.createURI("http://helps"), vf.createURI("http://Kevin")), "U"), makeRyaStatement(vf.createStatement(vf.createURI("http://Bob"), vf.createURI("http://worksAt"), vf.createURI("http://Chipotle")), "W"), makeRyaStatement(vf.createStatement(vf.createURI("http://Charlie"), vf.createURI("http://worksAt"), vf.createURI("http://Chipotle")), "V"), makeRyaStatement(vf.createStatement(vf.createURI("http://Eve"), vf.createURI("http://worksAt"), vf.createURI("http://Chipotle")), "U"), makeRyaStatement(vf.createStatement(vf.createURI("http://David"), vf.createURI("http://worksAt"), vf.createURI("http://Chipotle")), "V"));
dao.add(historicTriples.iterator());
dao.flush();
// The expected results of the SPARQL query once the PCJ has been computed.
final Set<BindingSet> expected = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("x", vf.createURI("http://Bob"));
expected.add(bs);
bs = new MapBindingSet();
bs.addBinding("x", vf.createURI("http://Charlie"));
expected.add(bs);
// Create the PCJ table.
final PrecomputedJoinStorage pcjStorage = new AccumuloPcjStorage(accumuloConn, getRyaInstanceName());
final String pcjId = pcjStorage.createPcj(sparql);
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
new CreateFluoPcj().withRyaIntegration(pcjId, pcjStorage, fluoClient, accumuloConn, getRyaInstanceName());
}
// Verify the end results of the query match the expected results.
super.getMiniFluo().waitForObservers();
final Set<BindingSet> results = Sets.newHashSet(pcjStorage.listResults(pcjId));
Assert.assertEquals(expected, results);
}
Aggregations