Search in sources :

Example 1 with Properties

use of org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties in project accumulo by apache.

the class CredentialProviderTokenTest method missingProviderProperty.

@Test(expected = IllegalArgumentException.class)
public void missingProviderProperty() throws Exception {
    CredentialProviderToken token = new CredentialProviderToken();
    Properties props = new Properties();
    props.put(CredentialProviderToken.CREDENTIAL_PROVIDERS_PROPERTY, keystorePath);
    token.init(props);
}
Also used : Properties(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties) Test(org.junit.Test)

Example 2 with Properties

use of org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties in project accumulo by apache.

the class CredentialProviderTokenTest method missingNameProperty.

@Test(expected = IllegalArgumentException.class)
public void missingNameProperty() throws Exception {
    CredentialProviderToken token = new CredentialProviderToken();
    Properties props = new Properties();
    props.put(CredentialProviderToken.NAME_PROPERTY, "root.password");
    token.init(props);
}
Also used : Properties(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties) Test(org.junit.Test)

Example 3 with Properties

use of org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties in project accumulo by apache.

the class CredentialProviderTokenTest method testEqualityAfterInit.

@Test
public void testEqualityAfterInit() throws Exception {
    if (!isCredentialProviderAvailable) {
        return;
    }
    CredentialProviderToken token = new CredentialProviderToken("root.password", keystorePath);
    CredentialProviderToken uninitializedToken = new CredentialProviderToken();
    Properties props = new Properties();
    props.put(CredentialProviderToken.NAME_PROPERTY, "root.password");
    props.put(CredentialProviderToken.CREDENTIAL_PROVIDERS_PROPERTY, keystorePath);
    uninitializedToken.init(props);
    Assert.assertArrayEquals(token.getPassword(), uninitializedToken.getPassword());
}
Also used : Properties(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties) Test(org.junit.Test)

Example 4 with Properties

use of org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties in project accumulo by apache.

the class CredentialProviderTokenTest method missingProperties.

@Test(expected = IllegalArgumentException.class)
public void missingProperties() throws Exception {
    CredentialProviderToken token = new CredentialProviderToken();
    token.init(new Properties());
}
Also used : Properties(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties) Test(org.junit.Test)

Example 5 with Properties

use of org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties in project accumulo by apache.

the class TraceServer method ensureTraceTableExists.

/**
 * Exceptions thrown out of here should be things that cause service failure (e.g. misconfigurations that aren't likely to change on retry).
 *
 * @return a working Connection that can be reused
 * @throws ClassNotFoundException
 *           if TRACE_TOKEN_TYPE is set to a class that we can't load.
 * @throws InstantiationException
 *           if we fail to create an instance of TRACE_TOKEN_TYPE.
 * @throws IllegalAccessException
 *           if the class pointed to by TRACE_TOKEN_TYPE is private.
 * @throws AccumuloSecurityException
 *           if the trace user has the wrong permissions
 */
private Connector ensureTraceTableExists(final AccumuloConfiguration conf) throws AccumuloSecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException {
    Connector connector = null;
    while (true) {
        try {
            final boolean isDefaultTokenType = conf.get(Property.TRACE_TOKEN_TYPE).equals(Property.TRACE_TOKEN_TYPE.getDefaultValue());
            String principal = conf.get(Property.TRACE_USER);
            if (conf.getBoolean(Property.INSTANCE_RPC_SASL_ENABLED)) {
                // Make sure that we replace _HOST if it exists in the principal
                principal = SecurityUtil.getServerPrincipal(principal);
            }
            AuthenticationToken at;
            Map<String, String> loginMap = conf.getAllPropertiesWithPrefix(Property.TRACE_TOKEN_PROPERTY_PREFIX);
            if (loginMap.isEmpty() && isDefaultTokenType) {
                // Assume the old type of user/password specification
                Property p = Property.TRACE_PASSWORD;
                at = new PasswordToken(conf.get(p).getBytes(UTF_8));
            } else {
                Properties props = new Properties();
                AuthenticationToken token = AccumuloVFSClassLoader.getClassLoader().loadClass(conf.get(Property.TRACE_TOKEN_TYPE)).asSubclass(AuthenticationToken.class).newInstance();
                int prefixLength = Property.TRACE_TOKEN_PROPERTY_PREFIX.getKey().length();
                for (Entry<String, String> entry : loginMap.entrySet()) {
                    props.put(entry.getKey().substring(prefixLength), entry.getValue());
                }
                token.init(props);
                at = token;
            }
            connector = instance.getConnector(principal, at);
            if (!connector.tableOperations().exists(tableName)) {
                connector.tableOperations().create(tableName);
                IteratorSetting setting = new IteratorSetting(10, "ageoff", AgeOffFilter.class.getName());
                AgeOffFilter.setTTL(setting, 7 * 24 * 60 * 60 * 1000l);
                connector.tableOperations().attachIterator(tableName, setting);
            }
            connector.tableOperations().setProperty(tableName, Property.TABLE_FORMATTER_CLASS.getKey(), TraceFormatter.class.getName());
            break;
        } catch (AccumuloException | TableExistsException | TableNotFoundException | IOException | RuntimeException ex) {
            log.info("Waiting to checking/create the trace table.", ex);
            sleepUninterruptibly(1, TimeUnit.SECONDS);
        }
    }
    return connector;
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AccumuloException(org.apache.accumulo.core.client.AccumuloException) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) IOException(java.io.IOException) Properties(org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableExistsException(org.apache.accumulo.core.client.TableExistsException) Property(org.apache.accumulo.core.conf.Property) AgeOffFilter(org.apache.accumulo.core.iterators.user.AgeOffFilter)

Aggregations

Properties (org.apache.accumulo.core.client.security.tokens.AuthenticationToken.Properties)8 IOException (java.io.IOException)4 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)4 Test (org.junit.Test)4 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)3 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 Property (org.apache.accumulo.core.conf.Property)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Password (org.apache.accumulo.core.cli.ClientOpts.Password)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 Connector (org.apache.accumulo.core.client.Connector)1 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)1 Scanner (org.apache.accumulo.core.client.Scanner)1 TableExistsException (org.apache.accumulo.core.client.TableExistsException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 TokenProperty (org.apache.accumulo.core.client.security.tokens.AuthenticationToken.TokenProperty)1 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)1