/** * Returns true if the SASL client is enabled. By default, the client is * enabled but can be disabled by setting the system property * <code>zookeeper.sasl.client</code> to <code>false</code>. See * ZOOKEEPER-1657 for more information. * * @return true if the SASL client is enabled. */ public boolean isSaslClientEnabled() { return Boolean.valueOf(getProperty(ENABLE_CLIENT_SASL_KEY, ENABLE_CLIENT_SASL_DEFAULT)); }
/** * Get the value of the <code>key</code> property as an <code>long</code>. * If property is not set, the provided <code>defaultValue</code> is * returned * * @param key * property key. * @param defaultValue * default value. * @throws NumberFormatException * when the value is invalid * @return return property value as an <code>long</code>, or * <code>defaultValue</code> */ public long getLong(String key, long defaultValue) { String value = getProperty(key); if (value != null) { return Long.parseLong(value.trim()); } return defaultValue; } }
protected void initProperties() throws IOException { try { packetLen = clientConfig.getInt(ZKConfig.JUTE_MAXBUFFER, ZKClientConfig.CLIENT_MAX_PACKET_LENGTH_DEFAULT); LOG.info("{} value is {} Bytes", ZKConfig.JUTE_MAXBUFFER, packetLen); } catch (NumberFormatException e) { String msg = MessageFormat.format( "Configured value {0} for property {1} can not be parsed to int", clientConfig.getProperty(ZKConfig.JUTE_MAXBUFFER), ZKConfig.JUTE_MAXBUFFER); LOG.error(msg); throw new IOException(msg); } }
private void initRequestTimeout() { try { requestTimeout = clientConfig.getLong( ZKClientConfig.ZOOKEEPER_REQUEST_TIMEOUT, ZKClientConfig.ZOOKEEPER_REQUEST_TIMEOUT_DEFAULT); LOG.info("{} value is {}. feature enabled=", ZKClientConfig.ZOOKEEPER_REQUEST_TIMEOUT, requestTimeout, requestTimeout > 0); } catch (NumberFormatException e) { LOG.error( "Configured value {} for property {} can not be parsed to long.", clientConfig.getProperty( ZKClientConfig.ZOOKEEPER_REQUEST_TIMEOUT), ZKClientConfig.ZOOKEEPER_REQUEST_TIMEOUT); throw e; } } }
private ClientCnxnSocket getClientCnxnSocket() throws IOException { String clientCnxnSocketName = getClientConfig().getProperty( ZKClientConfig.ZOOKEEPER_CLIENT_CNXN_SOCKET); if (clientCnxnSocketName == null) { clientCnxnSocketName = ClientCnxnSocketNIO.class.getName(); } try { Constructor<?> clientCxnConstructor = Class.forName(clientCnxnSocketName).getDeclaredConstructor(ZKClientConfig.class); ClientCnxnSocket clientCxnSocket = (ClientCnxnSocket) clientCxnConstructor.newInstance(getClientConfig()); return clientCxnSocket; } catch (Exception e) { IOException ioe = new IOException("Couldn't instantiate " + clientCnxnSocketName); ioe.initCause(e); throw ioe; } }
String principalUserName = clientConfig.getProperty(ZKClientConfig.ZK_SASL_CLIENT_USERNAME, ZKClientConfig.ZK_SASL_CLIENT_USERNAME_DEFAULT); String hostName = addr.getHostName(); String canonicalizeText = clientConfig.getProperty(ZKClientConfig.ZK_SASL_CLIENT_CANONICALIZE_HOSTNAME, ZKClientConfig.ZK_SASL_CLIENT_CANONICALIZE_HOSTNAME_DEFAULT); try {
String clientSection = clientConfig.getProperty( ZKClientConfig.LOGIN_CONTEXT_NAME_KEY, ZKClientConfig.LOGIN_CONTEXT_NAME_KEY_DEFAULT); .getProperty(ZKClientConfig.LOGIN_CONTEXT_NAME_KEY); if (explicitClientSection != null) { throw new LoginException( "Zookeeper client cannot authenticate using the '" + clientConfig.getProperty( ZKClientConfig.LOGIN_CONTEXT_NAME_KEY, ZKClientConfig.LOGIN_CONTEXT_NAME_KEY_DEFAULT) throw new LoginException( "No JAAS configuration section named '" + clientConfig.getProperty( ZKClientConfig.LOGIN_CONTEXT_NAME_KEY, ZKClientConfig.LOGIN_CONTEXT_NAME_KEY_DEFAULT)
@Test public void testSystemPropertyValue() { String clientName = "zookeeper1"; System.setProperty(ZK_SASL_CLIENT_USERNAME, clientName); ZKClientConfig conf = new ZKClientConfig(); assertEquals(conf.getProperty(ZK_SASL_CLIENT_USERNAME), clientName); String newClientName = "zookeeper2"; conf.setProperty(ZK_SASL_CLIENT_USERNAME, newClientName); assertEquals(conf.getProperty(ZK_SASL_CLIENT_USERNAME), newClientName); }
@Test public void testReadConfigurationFile() throws IOException, ConfigException { File file = File.createTempFile("clientConfig", ".conf", testData); file.deleteOnExit(); Properties clientConfProp = new Properties(); clientConfProp.setProperty(ENABLE_CLIENT_SASL_KEY, "true"); clientConfProp.setProperty(ZK_SASL_CLIENT_USERNAME, "ZK"); clientConfProp.setProperty(LOGIN_CONTEXT_NAME_KEY, "MyClient"); clientConfProp.setProperty(ZOOKEEPER_SERVER_REALM, "HADOOP.COM"); clientConfProp.setProperty("dummyProperty", "dummyValue"); OutputStream io = new FileOutputStream(file); try { clientConfProp.store(io, "Client Configurations"); } finally { io.close(); } ZKClientConfig conf = new ZKClientConfig(); conf.addConfiguration(file.getAbsolutePath()); assertEquals(conf.getProperty(ENABLE_CLIENT_SASL_KEY), "true"); assertEquals(conf.getProperty(ZK_SASL_CLIENT_USERNAME), "ZK"); assertEquals(conf.getProperty(LOGIN_CONTEXT_NAME_KEY), "MyClient"); assertEquals(conf.getProperty(ZOOKEEPER_SERVER_REALM), "HADOOP.COM"); assertEquals(conf.getProperty("dummyProperty"), "dummyValue"); // try to delete it now as we have done with the created file, why to // wait for deleteOnExit() deletion file.delete(); }
@Test public void testSetConfiguration() { ZKClientConfig conf = new ZKClientConfig(); String defaultValue = conf.getProperty(ZKClientConfig.ENABLE_CLIENT_SASL_KEY, ZKClientConfig.ENABLE_CLIENT_SASL_DEFAULT); if (defaultValue.equals("true")) { conf.setProperty(ENABLE_CLIENT_SASL_KEY, "false"); } else { conf.setProperty(ENABLE_CLIENT_SASL_KEY, "true"); } assertTrue(conf.getProperty(ENABLE_CLIENT_SASL_KEY) != defaultValue); }
assertEquals(e.getValue(), conf.getProperty(e.getKey())); String result = conf.getProperty(e.getKey()); assertNull(result);
if ((clientConfig.getJaasConfKey() != null) || ((Configuration.getConfiguration() != null) && (Configuration.getConfiguration() .getAppConfigurationEntry(clientConfig.getProperty(ZKClientConfig.LOGIN_CONTEXT_NAME_KEY, ZKClientConfig.LOGIN_CONTEXT_NAME_KEY_DEFAULT)) != null))) {