net.spy.memcached.auth.AuthDescriptor Java Examples
The following examples show how to use
net.spy.memcached.auth.AuthDescriptor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpyMemcacheClientFactory.java From hibernate-l2-memcached with Apache License 2.0 | 6 votes |
private DefaultConnectionFactory buildDefaultConnectionFactory() { return new DefaultConnectionFactory(getOperationQueueLength(), getReadBufferSize(), getHashAlgorithm()) { @Override public long getOperationTimeout() { return getOperationTimeoutMillis(); } @Override public boolean isDaemon() { return isDaemonMode(); } @Override public AuthDescriptor getAuthDescriptor() { return createAuthDescriptor(); } }; }
Example #2
Source File: SpyMemcacheClientFactory.java From hibernate-l2-memcached with Apache License 2.0 | 6 votes |
private KetamaConnectionFactory buildKetamaConnectionFactory() { return new KetamaConnectionFactory() { @Override public long getOperationTimeout() { return getOperationTimeoutMillis(); } @Override public boolean isDaemon() { return isDaemonMode(); } @Override public AuthDescriptor getAuthDescriptor() { return createAuthDescriptor(); } }; }
Example #3
Source File: SpyMemcacheClientFactory.java From hibernate-l2-memcached with Apache License 2.0 | 6 votes |
private BinaryConnectionFactory buildBinaryConnectionFactory() { return new BinaryConnectionFactory(getOperationQueueLength(), getReadBufferSize(), getHashAlgorithm()) { @Override public long getOperationTimeout() { return getOperationTimeoutMillis(); } @Override public boolean isDaemon() { return isDaemonMode(); } @Override public AuthDescriptor getAuthDescriptor() { return createAuthDescriptor(); } }; }
Example #4
Source File: SpyMemcachedAdapterTest.java From hibernate4-memcached with Apache License 2.0 | 6 votes |
@Test public void createConnectionFactoryBuilder() throws Exception { Properties props = new Properties(); props.setProperty(HASH_ALGORITHM_PROPERTY_KEY, DefaultHashAlgorithm.NATIVE_HASH.name()); props.setProperty(OPERATION_TIMEOUT_MILLIS_PROPERTY_KEY, String.valueOf(13579)); props.setProperty(TRANSCODER_PROPERTY_KEY, FakeTranscoder.class.getName()); props.setProperty(AUTH_GENERATOR_PROPERTY_KEY, FakeAuthDescriptorGenerator.class.getName()); ConnectionFactoryBuilder builder = spyMemcachedAdapter.createConnectionFactoryBuilder(new OverridableReadOnlyPropertiesImpl(props)); ConnectionFactory connectionFactory = builder.build(); assertThat(connectionFactory.getHashAlg()).isEqualTo(DefaultHashAlgorithm.NATIVE_HASH); assertThat(connectionFactory.getOperationTimeout()).isEqualTo(13579); Transcoder<Object> transcoder = connectionFactory.getDefaultTranscoder(); assertThat(transcoder).isExactlyInstanceOf(FakeTranscoder.class); FakeTranscoder fakeTranscoder = (FakeTranscoder) transcoder; assertThat(fakeTranscoder.isInitialized()).isTrue(); AuthDescriptor authDescriptor = connectionFactory.getAuthDescriptor(); assertThat(authDescriptor.getMechs()).isEqualTo(FakeAuthDescriptorGenerator.FAKE_MECHS); }
Example #5
Source File: MemcachePoolMixin.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public void activateService() throws Exception { MemcacheConfiguration config = configuration.get(); expiration = ( config.expiration().get() == null ) ? 3600 : config.expiration().get(); String addresses = ( config.addresses().get() == null ) ? "localhost:11211" : config.addresses().get(); Protocol protocol = ( config.protocol().get() == null ) ? Protocol.TEXT : Protocol.valueOf( config.protocol().get().toUpperCase() ); String username = config.username().get(); String password = config.password().get(); String authMech = config.authMechanism().get() == null ? "PLAIN" : config.authMechanism().get(); ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder(); builder.setProtocol( protocol ); if( username != null && !username.isEmpty() ) { String[] authType = { authMech }; AuthDescriptor to = new AuthDescriptor( authType, new PlainCallbackHandler( username, password ) ); builder.setAuthDescriptor( to ); } client = new MemcachedClient( builder.build(), AddrUtil.getAddresses( addresses ) ); }
Example #6
Source File: SpyMemcacheClientFactory.java From hibernate-l2-memcached with Apache License 2.0 | 5 votes |
protected AuthDescriptor createAuthDescriptor() { String username = properties.get(PROP_USERNAME); String password = properties.get(PROP_PASSWORD); if (username == null || password == null) { return null; } return new AuthDescriptor(new String[]{"PLAIN"}, new PlainCallbackHandler(username, password)); }
Example #7
Source File: PlainAuthDescriptorGenerator.java From hibernate4-memcached with Apache License 2.0 | 5 votes |
@Override public AuthDescriptor generate(OverridableReadOnlyProperties properties) { String username = properties.getRequiredProperty(USERNAME_PROPERTY_KEY); String password = properties.getRequiredProperty(PASSWORD_PROPERTY_KEY); AuthDescriptor authDescriptor = new AuthDescriptor(new String[]{"PLAIN"}, new PlainCallbackHandler(username, password)); return authDescriptor; }
Example #8
Source File: PlainAuthDescriptorGeneratorTest.java From hibernate4-memcached with Apache License 2.0 | 5 votes |
@Test public void generate() throws Exception { Properties props = new Properties(); props.setProperty(PlainAuthDescriptorGenerator.USERNAME_PROPERTY_KEY, "username"); props.setProperty(PlainAuthDescriptorGenerator.PASSWORD_PROPERTY_KEY, "password"); AuthDescriptor authDescriptor = generator.generate(new OverridableReadOnlyPropertiesImpl(props)); assertThat(authDescriptor).isNotNull(); assertThat(authDescriptor.getMechs()).isEqualTo(new String[]{"PLAIN"}); assertThat(authDescriptor.getCallback()).isExactlyInstanceOf(PlainCallbackHandler.class); }
Example #9
Source File: MemcachedDriver.java From hazelcast-simulator with Apache License 2.0 | 5 votes |
@Override public void startVendorInstance() throws Exception { String[] nodes = get("nodes").split(","); List<InetSocketAddress> addresses = new ArrayList<>(); for (String node : nodes) { String[] addressParts = node.split(":"); if (addressParts.length == 0 || addressParts.length > 2) { throw new IllegalArgumentException("Invalid node address. Example: localhost:11211"); } int port = 11211; //default memcached port if (addressParts.length == 2) { port = Integer.parseInt(addressParts[1]); } addresses.add(new InetSocketAddress(addressParts[0], port)); } if (get("MEMCACHED_USERNAME") != null && get("MEMCACHED_PASSWORD") != null) { AuthDescriptor authDescriptor = new AuthDescriptor(new String[]{"PLAIN"}, new PlainCallbackHandler(get("MEMCACHED_USERNAME"), get("MEMCACHED_PASSWORD"))); this.client = new MemcachedClient(new ConnectionFactoryBuilder() .setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setAuthDescriptor(authDescriptor).build(), addresses); } else { this.client = new MemcachedClient(addresses); } }
Example #10
Source File: ApiMemcached.java From iaf with Apache License 2.0 | 5 votes |
public ApiMemcached() { AppConstants ac = AppConstants.getInstance(); String address = ac.getProperty("etag.cache.server", "localhost:11211"); String username = ac.getProperty("etag.cache.username", ""); String password = ac.getProperty("etag.cache.password", ""); int timeout = ac.getInt("etag.cache.timeout", 10); List<InetSocketAddress> addresses = AddrUtil.getAddresses(address); ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder() .setProtocol(Protocol.BINARY) .setOpTimeout(timeout) .setInitialObservers(Collections.singleton(obs)); if(addresses.size() > 1) connectionFactoryBuilder.setFailureMode(FailureMode.Redistribute); else connectionFactoryBuilder.setFailureMode(FailureMode.Retry); if(!username.isEmpty()) connectionFactoryBuilder.setAuthDescriptor(AuthDescriptor.typical(username, password)); ConnectionFactory cf = connectionFactoryBuilder.build(); try { client = new MemcachedClient(cf, addresses); //Fetching a none-existing key to test the connection Future<Object> future = client.asyncGet("test-connection"); future.get(timeout, TimeUnit.MILLISECONDS); } catch (Exception e) { ConfigurationWarnings.add(log, "Unable to connect to one or more memcached servers."); } }
Example #11
Source File: MemcachedConnectionFactory.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
@Override public AuthDescriptor getAuthDescriptor() { return underlying.getAuthDescriptor(); }
Example #12
Source File: MemcachedConnectionFactory.java From kylin with Apache License 2.0 | 4 votes |
@Override public AuthDescriptor getAuthDescriptor() { return underlying.getAuthDescriptor(); }
Example #13
Source File: SpyMemcachedAdapterTest.java From hibernate4-memcached with Apache License 2.0 | 4 votes |
@Override public AuthDescriptor generate(OverridableReadOnlyProperties properties) { return new AuthDescriptor(FAKE_MECHS, null); }
Example #14
Source File: AuthDescriptorGenerator.java From hibernate4-memcached with Apache License 2.0 | votes |
AuthDescriptor generate(OverridableReadOnlyProperties properties);