@Override public AuthenticationToken getAuthenticationToken() { if (token == null) { token = ClientProperty.getAuthenticationToken(properties); } return token; }
protected ClientContext getContextForPeer(AccumuloConfiguration localConf, ReplicationTarget target, String principal, AuthenticationToken token) { requireNonNull(localConf); requireNonNull(target); requireNonNull(principal); requireNonNull(token); Properties properties = new Properties(); properties.setProperty(ClientProperty.INSTANCE_NAME.getKey(), instanceName); properties.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), zookeepers); properties.setProperty(ClientProperty.AUTH_PRINCIPAL.getKey(), principal); ClientProperty.setAuthenticationToken(properties, token); return new ClientContext(ClientInfo.from(properties, token), localConf); }
@Override void property(ClientProperty prop) { doc.println("## " + prop.getDescription()); if (!prop.isRequired()) { doc.print("#"); } doc.println(prop.getKey() + "=" + prop.getDefaultValue() + "\n"); } }
if (ClientProperty.SASL_ENABLED.getBoolean(clientProperties)) { log.debug("SASL is enabled, disabling authorization timeout"); disableAuthTimeout = true; if (ClientProperty.INSTANCE_ZOOKEEPERS.isEmpty(clientProperties)) { throw new IllegalArgumentException("ZooKeepers must be set using -z or -zh on command line" + " or in accumulo-client.properties"); if (ClientProperty.INSTANCE_NAME.isEmpty(clientProperties)) { throw new IllegalArgumentException("Instance name must be set using -z or -zi on command " + "line or in accumulo-client.properties"); if (password == null && clientProperties.containsKey(ClientProperty.AUTH_TOKEN.getKey()) && principal.equals(ClientProperty.AUTH_PRINCIPAL.getValue(clientProperties))) { token = ClientProperty.getAuthenticationToken(clientProperties);
/** * Gets the {@link BatchWriterConfig} settings that were stored with ClientInfo */ public static BatchWriterConfig getBatchWriterOptions(Class<?> implementingClass, Configuration conf) { BatchWriterConfig bwConfig = new BatchWriterConfig(); Properties props = getClientProperties(implementingClass, conf); String property = props.getProperty(BATCH_WRITER_DURABILITY.getKey()); if (property != null) bwConfig.setDurability(DurabilityImpl.fromString(property)); Long value = BATCH_WRITER_LATENCY_MAX.getTimeInMillis(props); if (value != null) bwConfig.setMaxLatency(value, TimeUnit.MILLISECONDS); value = BATCH_WRITER_MEMORY_MAX.getBytes(props); if (value != null) bwConfig.setMaxMemory(value); value = BATCH_WRITER_TIMEOUT_MAX.getTimeInMillis(props); if (value != null) bwConfig.setTimeout(value, TimeUnit.MILLISECONDS); Integer intValue = BATCH_WRITER_THREADS_MAX.getInteger(props); if (intValue != null) bwConfig.setMaxWriteThreads(intValue); return bwConfig; }
@Override void property(ClientProperty prop) { Objects.nonNull(prop); doc.print("| <a name=\"" + prop.getKey().replace(".", "_") + "\" class=\"prop\"></a> " + prop.getKey() + " | "); String defaultValue = sanitize(prop.getDefaultValue()).trim(); if (defaultValue.length() == 0) { defaultValue = "*empty*"; } doc.println( defaultValue + " | " + prop.getSince() + " | " + sanitize(prop.getDescription() + " |")); }
public String getValue(Properties properties) { Objects.requireNonNull(properties); String value = properties.getProperty(getKey()); if (value == null || value.isEmpty()) { value = getDefaultValue(); } Objects.requireNonNull(value); if (isRequired() && value.isEmpty()) { throw new IllegalArgumentException(getKey() + " must be set!"); } if (!type.isValidFormat(value)) { throw new IllegalArgumentException( "Invalid format for type \"" + type + "\" for provided value: " + value); } return value; }
cachedProps.setProperty(ClientProperty.SASL_ENABLED.getKey(), "true"); cachedProps.setProperty(ClientProperty.SSL_ENABLED.getKey(), "true"); cachedProps.setProperty(ClientProperty.AUTH_PRINCIPAL.getKey(), principal); cachedProps.setProperty(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), zookeepers); cachedProps.setProperty(ClientProperty.INSTANCE_NAME.getKey(), instance); ClientProperty.setPassword(cachedProps, securePassword.toString()); } else if (password != null) { ClientProperty.setPassword(cachedProps, password.toString()); } else if (keytabPath != null) { ClientProperty.setKerberosKeytab(cachedProps, keytabPath);
public static void setAuthenticationToken(Properties properties, AuthenticationToken token) { properties.setProperty(ClientProperty.AUTH_TYPE.getKey(), token.getClass().getName()); properties.setProperty(ClientProperty.AUTH_TOKEN.getKey(), encodeToken(token)); }
private String getString(ClientProperty property) { return property.getValue(properties); }
public String getUsername() throws Exception { if (username == null) { username = getClientProperties().getProperty(ClientProperty.AUTH_PRINCIPAL.getKey()); if (username == null || username.isEmpty()) { if (ClientProperty.SASL_ENABLED.getBoolean(getClientProperties())) { if (!UserGroupInformation.isSecurityEnabled()) { throw new IllegalArgumentException( "Kerberos security is not" + " enabled. Run with --sasl or set 'sasl.enabled' in" + " accumulo-client.properties"); } UserGroupInformation ugi = UserGroupInformation.getCurrentUser(); username = ugi.getUserName(); } else { throw new IllegalArgumentException("Username is not set. Run with '-u" + " myuser' or set 'auth.principal' in accumulo-client.properties"); } } } return username; }
public BatchWriterConfig getBatchWriterConfig() { ensureOpen(); if (batchWriterConfig == null) { Properties props = info.getProperties(); batchWriterConfig = new BatchWriterConfig(); Long maxMemory = ClientProperty.BATCH_WRITER_MEMORY_MAX.getBytes(props); if (maxMemory != null) { batchWriterConfig.setMaxMemory(maxMemory); } Long maxLatency = ClientProperty.BATCH_WRITER_LATENCY_MAX.getTimeInMillis(props); if (maxLatency != null) { batchWriterConfig.setMaxLatency(maxLatency, TimeUnit.SECONDS); } Long timeout = ClientProperty.BATCH_WRITER_TIMEOUT_MAX.getTimeInMillis(props); if (timeout != null) { batchWriterConfig.setTimeout(timeout, TimeUnit.SECONDS); } String durability = ClientProperty.BATCH_WRITER_DURABILITY.getValue(props); if (!durability.isEmpty()) { batchWriterConfig.setDurability(Durability.valueOf(durability.toUpperCase())); } } return batchWriterConfig; }
/** * Enable tracing by setting up SpanReceivers for the current process. If host name is null, it * will be determined. If service name is null, the simple name of the class will be used. * Properties required in the client configuration include * {@link org.apache.accumulo.core.conf.ClientProperty#TRACE_SPAN_RECEIVERS} and any properties * specific to the span receiver. */ public static void enable(String hostname, String service, Properties properties) { String spanReceivers = ClientProperty.TRACE_SPAN_RECEIVERS.getValue(properties); String zookeepers = ClientProperty.INSTANCE_ZOOKEEPERS.getValue(properties); long timeout = ConfigurationTypeHelper .getTimeInMillis(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT.getValue(properties)); String zkPath = ClientProperty.TRACE_ZOOKEEPER_PATH.getValue(properties); Map<String,String> props = ClientProperty .toMap(ClientProperty.getPrefix(properties, ClientProperty.TRACE_SPAN_RECEIVER_PREFIX)); enableTracing(hostname, service, spanReceivers, zookeepers, timeout, zkPath, props); }
public Long getBytes(Properties properties) { String value = getValue(properties); if (value.isEmpty()) { return null; } checkState(getType() == PropertyType.BYTES, "Invalid type getting bytes. Type must be " + PropertyType.BYTES + ", not " + getType()); return ConfigurationTypeHelper.getMemoryAsBytes(value); }
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "code runs in same security context as user who providing the token file") public static AuthenticationToken getAuthenticationToken(Properties properties) { String authType = ClientProperty.AUTH_TYPE.getValue(properties); String token = ClientProperty.AUTH_TOKEN.getValue(properties); switch (authType) { case "password": return new PasswordToken(token); case "PasswordToken": return decodeToken(PasswordToken.class.getName(), token); case "kerberos": try { String principal = ClientProperty.AUTH_PRINCIPAL.getValue(properties); return new KerberosToken(principal, new File(token)); } catch (IOException e) { throw new IllegalArgumentException(e); } case "KerberosToken": return decodeToken(KerberosToken.class.getName(), token); case "CredentialProviderToken": return decodeToken(CredentialProviderToken.class.getName(), token); case "DelegationToken": return decodeToken(DelegationToken.class.getName(), token); default: return decodeToken(authType, token); } }
@Override public ConnectionOptions<T> as(CharSequence principal, AuthenticationToken token) { if (token.isDestroyed()) { throw new IllegalArgumentException("AuthenticationToken has been destroyed"); } setProperty(ClientProperty.AUTH_PRINCIPAL, principal.toString()); ClientProperty.setAuthenticationToken(properties, token); this.token = token; return this; }