net.spy.memcached.auth.PlainCallbackHandler Java Examples
The following examples show how to use
net.spy.memcached.auth.PlainCallbackHandler.
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: 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 #2
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 #3
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 #4
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 #5
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); } }