Search in sources :

Example 31 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class ClientContextTest method loadSensitivePropertyFromCredentialProvider.

@Test
public void loadSensitivePropertyFromCredentialProvider() {
    if (!isCredentialProviderAvailable) {
        return;
    }
    String absPath = getKeyStoreUrl(keystore);
    ClientConfiguration clientConf = ClientConfiguration.create().with(Property.GENERAL_SECURITY_CREDENTIAL_PROVIDER_PATHS.getKey(), absPath);
    AccumuloConfiguration accClientConf = ClientContext.convertClientConfig(clientConf);
    Assert.assertEquals("mysecret", accClientConf.get(Property.INSTANCE_SECRET));
}
Also used : ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Test(org.junit.Test)

Example 32 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class ConnectionInfoFactory method getClientConfiguration.

public static ClientConfiguration getClientConfiguration(ConnectionInfo info) {
    ClientConfiguration config = ClientConfiguration.create();
    for (Object keyObj : info.getProperties().keySet()) {
        String key = (String) keyObj;
        String val = info.getProperties().getProperty(key);
        if (key.equals(ClientProperty.INSTANCE_ZOOKEEPERS.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_ZK_HOST, val);
        } else if (key.equals(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT_SEC.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_ZK_TIMEOUT, val);
        } else if (key.equals(ClientProperty.SSL_ENABLED.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_RPC_SSL_ENABLED, val);
        } else if (key.equals(ClientProperty.SSL_KEYSTORE_PATH.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_KEYSTORE_PATH, val);
            config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_RPC_SSL_CLIENT_AUTH, "true");
        } else if (key.equals(ClientProperty.SSL_KEYSTORE_TYPE.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_KEYSTORE_TYPE, val);
        } else if (key.equals(ClientProperty.SSL_KEYSTORE_PASSWORD.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_KEYSTORE_PASSWORD, val);
        } else if (key.equals(ClientProperty.SSL_TRUSTSTORE_PATH.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_TRUSTSTORE_PATH, val);
        } else if (key.equals(ClientProperty.SSL_TRUSTSTORE_TYPE.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_TRUSTSTORE_PATH, val);
        } else if (key.equals(ClientProperty.SSL_TRUSTSTORE_PASSWORD.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.RPC_SSL_TRUSTSTORE_PATH, val);
        } else if (key.equals(ClientProperty.SSL_USE_JSSE.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.RPC_USE_JSSE, val);
        } else if (key.equals(ClientProperty.SASL_ENABLED.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.INSTANCE_RPC_SSL_ENABLED, val);
        } else if (key.equals(ClientProperty.SASL_QOP.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.RPC_SASL_QOP, val);
        } else if (key.equals(ClientProperty.SASL_KERBEROS_SERVER_PRIMARY.getKey())) {
            config.setProperty(ClientConfiguration.ClientProperty.KERBEROS_SERVER_PRIMARY, val);
        } else {
            config.setProperty(key, val);
        }
    }
    return config;
}
Also used : ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration)

Example 33 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class ConditionalWriterIT method testFields.

@Test
public void testFields() throws Exception {
    Connector conn = getConnector();
    String tableName = getUniqueNames(1)[0];
    String user = null;
    ClientConfiguration clientConf = cluster.getClientConfig();
    final boolean saslEnabled = clientConf.hasSasl();
    ClusterUser user1 = getUser(0);
    user = user1.getPrincipal();
    if (saslEnabled) {
        // The token is pointless for kerberos
        conn.securityOperations().createLocalUser(user, null);
    } else {
        conn.securityOperations().createLocalUser(user, new PasswordToken(user1.getPassword()));
    }
    Authorizations auths = new Authorizations("A", "B");
    conn.securityOperations().changeUserAuthorizations(user, auths);
    conn.securityOperations().grantSystemPermission(user, SystemPermission.CREATE_TABLE);
    conn = conn.getInstance().getConnector(user, user1.getToken());
    conn.tableOperations().create(tableName);
    try (ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig().setAuthorizations(auths));
        Scanner scanner = conn.createScanner(tableName, auths)) {
        ColumnVisibility cva = new ColumnVisibility("A");
        ColumnVisibility cvb = new ColumnVisibility("B");
        ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva));
        cm0.put("name", "last", cva, "doe");
        cm0.put("name", "first", cva, "john");
        cm0.put("tx", "seq", cva, "1");
        Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
        scanner.setRange(new Range("99006"));
        // TODO verify all columns
        scanner.fetchColumn(new Text("tx"), new Text("seq"));
        Entry<Key, Value> entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("1", entry.getValue().toString());
        long ts = entry.getKey().getTimestamp();
        // test wrong colf
        ConditionalMutation cm1 = new ConditionalMutation("99006", new Condition("txA", "seq").setVisibility(cva).setValue("1"));
        cm1.put("name", "last", cva, "Doe");
        cm1.put("name", "first", cva, "John");
        cm1.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm1).getStatus());
        // test wrong colq
        ConditionalMutation cm2 = new ConditionalMutation("99006", new Condition("tx", "seqA").setVisibility(cva).setValue("1"));
        cm2.put("name", "last", cva, "Doe");
        cm2.put("name", "first", cva, "John");
        cm2.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm2).getStatus());
        // test wrong colv
        ConditionalMutation cm3 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cvb).setValue("1"));
        cm3.put("name", "last", cva, "Doe");
        cm3.put("name", "first", cva, "John");
        cm3.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm3).getStatus());
        // test wrong timestamp
        ConditionalMutation cm4 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts + 1).setValue("1"));
        cm4.put("name", "last", cva, "Doe");
        cm4.put("name", "first", cva, "John");
        cm4.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm4).getStatus());
        // test wrong timestamp
        ConditionalMutation cm5 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts - 1).setValue("1"));
        cm5.put("name", "last", cva, "Doe");
        cm5.put("name", "first", cva, "John");
        cm5.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.REJECTED, cw.write(cm5).getStatus());
        // ensure no updates were made
        entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("1", entry.getValue().toString());
        // set all columns correctly
        ConditionalMutation cm6 = new ConditionalMutation("99006", new Condition("tx", "seq").setVisibility(cva).setTimestamp(ts).setValue("1"));
        cm6.put("name", "last", cva, "Doe");
        cm6.put("name", "first", cva, "John");
        cm6.put("tx", "seq", cva, "2");
        Assert.assertEquals(Status.ACCEPTED, cw.write(cm6).getStatus());
        entry = Iterables.getOnlyElement(scanner);
        Assert.assertEquals("2", entry.getValue().toString());
    }
}
Also used : Condition(org.apache.accumulo.core.data.Condition) Connector(org.apache.accumulo.core.client.Connector) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) ConditionalWriter(org.apache.accumulo.core.client.ConditionalWriter) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ConditionalMutation(org.apache.accumulo.core.data.ConditionalMutation) Value(org.apache.accumulo.core.data.Value) ClusterUser(org.apache.accumulo.cluster.ClusterUser) ConditionalWriterConfig(org.apache.accumulo.core.client.ConditionalWriterConfig) ColumnVisibility(org.apache.accumulo.core.security.ColumnVisibility) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 34 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project incubator-rya by apache.

the class RyaGiraphUtils method initializeAccumuloInputFormat.

public static void initializeAccumuloInputFormat(Configuration conf) {
    // get accumulo connect information
    boolean mock = MRUtils.getACMock(conf, false);
    String zk = MRUtils.getACZK(conf);
    String instance = MRUtils.getACInstance(conf);
    String userName = MRUtils.getACUserName(conf);
    String pwd = MRUtils.getACPwd(conf);
    String tablePrefix = MRUtils.getTablePrefix(conf);
    TABLE_LAYOUT rdfTableLayout = MRUtils.getTableLayout(conf, TABLE_LAYOUT.SPO);
    String authString = conf.get(MRUtils.AC_AUTH_PROP);
    Authorizations authorizations;
    if (authString != null && !authString.isEmpty()) {
        authorizations = new Authorizations(authString.split(","));
        // for consistency
        conf.set(ConfigUtils.CLOUDBASE_AUTHS, authString);
    } else {
        authorizations = AccumuloRdfConstants.ALL_AUTHORIZATIONS;
    }
    // set up the accumulo input format so that we know what table to use and everything
    try {
        Job job = new Job(conf);
        AccumuloInputFormat.setConnectorInfo(job, userName, new PasswordToken(pwd));
        String tableName = RdfCloudTripleStoreUtils.layoutPrefixToTable(rdfTableLayout, tablePrefix);
        AccumuloInputFormat.setInputTableName(job, tableName);
        AccumuloInputFormat.setScanAuthorizations(job, authorizations);
        if (mock) {
            AccumuloInputFormat.setMockInstance(job, instance);
        } else {
            ClientConfiguration clientConfig = ClientConfiguration.loadDefault().withInstance(instance).withZkHosts(zk);
            AccumuloInputFormat.setZooKeeperInstance(job, clientConfig);
        }
    } catch (IOException | AccumuloSecurityException e) {
        // TODO better exception handling here
        e.printStackTrace();
    }
}
Also used : TABLE_LAYOUT(org.apache.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT) Authorizations(org.apache.accumulo.core.security.Authorizations) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) IOException(java.io.IOException) Job(org.apache.hadoop.mapreduce.Job) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration)

Example 35 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project incubator-rya by apache.

the class GraphXGraphGenerator method getVertexRDD.

public RDD<Tuple2<Object, RyaTypeWritable>> getVertexRDD(SparkContext sc, Configuration conf) throws IOException, AccumuloSecurityException {
    // Load configuration parameters
    zk = MRUtils.getACZK(conf);
    instance = MRUtils.getACInstance(conf);
    userName = MRUtils.getACUserName(conf);
    pwd = MRUtils.getACPwd(conf);
    mock = MRUtils.getACMock(conf, false);
    tablePrefix = MRUtils.getTablePrefix(conf);
    // Set authorizations if specified
    String authString = conf.get(MRUtils.AC_AUTH_PROP);
    if (authString != null && !authString.isEmpty()) {
        authorizations = new Authorizations(authString.split(","));
        // for consistency
        conf.set(ConfigUtils.CLOUDBASE_AUTHS, authString);
    } else {
        authorizations = AccumuloRdfConstants.ALL_AUTHORIZATIONS;
    }
    // Set table prefix to the default if not set
    if (tablePrefix == null) {
        tablePrefix = RdfCloudTripleStoreConstants.TBL_PRFX_DEF;
        MRUtils.setTablePrefix(conf, tablePrefix);
    }
    // Check for required configuration parameters
    Preconditions.checkNotNull(instance, "Accumulo instance name [" + MRUtils.AC_INSTANCE_PROP + "] not set.");
    Preconditions.checkNotNull(userName, "Accumulo username [" + MRUtils.AC_USERNAME_PROP + "] not set.");
    Preconditions.checkNotNull(pwd, "Accumulo password [" + MRUtils.AC_PWD_PROP + "] not set.");
    Preconditions.checkNotNull(tablePrefix, "Table prefix [" + MRUtils.TABLE_PREFIX_PROPERTY + "] not set.");
    RdfCloudTripleStoreConstants.prefixTables(tablePrefix);
    // for consistency
    if (!mock)
        conf.set(ConfigUtils.CLOUDBASE_ZOOKEEPERS, zk);
    // Ensure consistency between alternative configuration properties
    conf.set(ConfigUtils.CLOUDBASE_INSTANCE, instance);
    conf.set(ConfigUtils.CLOUDBASE_USER, userName);
    conf.set(ConfigUtils.CLOUDBASE_PASSWORD, pwd);
    conf.setBoolean(ConfigUtils.USE_MOCK_INSTANCE, mock);
    conf.set(RdfCloudTripleStoreConfiguration.CONF_TBL_PREFIX, tablePrefix);
    Job job = Job.getInstance(conf, sc.appName());
    ClientConfiguration clientConfig = new ClientConfiguration().with(ClientProperty.INSTANCE_NAME, instance).with(ClientProperty.INSTANCE_ZK_HOST, zk);
    GraphXInputFormat.setInputTableName(job, EntityCentricIndex.getTableName(conf));
    GraphXInputFormat.setConnectorInfo(job, userName, new PasswordToken(pwd));
    GraphXInputFormat.setZooKeeperInstance(job, clientConfig);
    GraphXInputFormat.setScanAuthorizations(job, authorizations);
    return sc.newAPIHadoopRDD(job.getConfiguration(), GraphXInputFormat.class, Object.class, RyaTypeWritable.class);
}
Also used : Authorizations(org.apache.accumulo.core.security.Authorizations) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Job(org.apache.hadoop.mapreduce.Job) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration)

Aggregations

ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)78 Test (org.junit.Test)40 Connector (org.apache.accumulo.core.client.Connector)28 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)27 IOException (java.io.IOException)16 TestIngest (org.apache.accumulo.test.TestIngest)15 BatchWriterOpts (org.apache.accumulo.core.cli.BatchWriterOpts)13 ScannerOpts (org.apache.accumulo.core.cli.ScannerOpts)12 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)12 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)11 VerifyIngest (org.apache.accumulo.test.VerifyIngest)11 ClusterUser (org.apache.accumulo.cluster.ClusterUser)9 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)9 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)8 Map (java.util.Map)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)6 Instance (org.apache.accumulo.core.client.Instance)6 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)6 Authorizations (org.apache.accumulo.core.security.Authorizations)6 Path (org.apache.hadoop.fs.Path)6