Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2012-2018 the original author or authors.
Copyright 2012-2019 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,9 +24,12 @@

import net.spy.memcached.CASResponse;
import net.spy.memcached.CASValue;
import net.spy.memcached.ConnectionFactoryBuilder;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.internal.OperationFuture;

import net.spy.memcached.auth.AuthDescriptor;
import net.spy.memcached.auth.PlainCallbackHandler;
import org.apache.ibatis.cache.CacheException;
import org.apache.ibatis.logging.Log;
import org.apache.ibatis.logging.LogFactory;
Expand Down Expand Up @@ -81,7 +84,15 @@ public void setCas(long cas) {
public MemcachedClientWrapper() {
configuration = MemcachedConfigurationBuilder.getInstance().parseConfiguration();
try {
client = new MemcachedClient(configuration.getConnectionFactory(), configuration.getAddresses());
if (configuration.isUsingSASL()) {
AuthDescriptor ad = new AuthDescriptor(new String[] { "PLAIN" },
new PlainCallbackHandler(configuration.getUsername(), configuration.getPassword()));
client = new MemcachedClient(new ConnectionFactoryBuilder()
.setProtocol(ConnectionFactoryBuilder.Protocol.BINARY).setAuthDescriptor(ad).build(),
configuration.getAddresses());
} else {
client = new MemcachedClient(configuration.getConnectionFactory(), configuration.getAddresses());
}
} catch (IOException e) {
String message = "Impossible to instantiate a new memecached client instance, see nested exceptions";
LOG.error(message, e);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -70,6 +70,21 @@ final class MemcachedConfiguration {
*/
private TimeUnit timeUnit;

/**
* The flag to enable SASL Connection
*/
private boolean usingSASL;

/**
* The Memcached SASL username
*/
private String username;

/**
* The Memcached SASL password
*/
private String password;

/**
* @return the keyPrefix
*/
Expand Down Expand Up @@ -190,13 +205,58 @@ public void setTimeUnit(TimeUnit timeUnit) {
this.timeUnit = timeUnit;
}

/**
* @return the usingSASL
*/
public boolean isUsingSASL() {
return usingSASL;
}

/**
* @param usingSASL
* the usingSASL to set
*/
public void setUsingSASL(boolean usingSASL) {
this.usingSASL = usingSASL;
}

/**
* @return the username
*/
public String getUsername() {
return username;
}

/**
* @param username
* the username to set
*/
public void setUsername(String username) {
this.username = username;
}

/**
* @return the password
*/
public String getPassword() {
return password;
}

/**
* @param password
* the password to set
*/
public void setPassword(String password) {
this.password = password;
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return hash(1, 31, addresses, compressionEnabled, connectionFactory, expiration, keyPrefix, timeUnit, timeout,
usingAsyncGet);
usingAsyncGet, usingSASL, username, password);
}

/**
Expand Down Expand Up @@ -234,7 +294,8 @@ public boolean equals(Object obj) {
return eq(addresses, other.addresses) && eq(compressionEnabled, other.compressionEnabled)
&& eq(connectionFactory, other.connectionFactory) && eq(expiration, other.expiration)
&& eq(keyPrefix, other.keyPrefix) && eq(timeUnit, other.timeUnit) && eq(timeout, other.timeout)
&& eq(usingAsyncGet, other.usingAsyncGet);
&& eq(usingAsyncGet, other.usingAsyncGet) && eq(usingSASL, other.usingSASL) && eq(username, other.username)
&& eq(password, other.password);
}

/**
Expand All @@ -256,8 +317,9 @@ private static <O> boolean eq(O o1, O o2) {
@Override
public String toString() {
return format(
"MemcachedConfiguration [addresses=%s, compressionEnabled=%s, connectionFactory=%s, , expiration=%s, keyPrefix=%s, timeUnit=%s, timeout=%s, usingAsyncGet=%s]",
addresses, compressionEnabled, connectionFactory, expiration, keyPrefix, timeUnit, timeout, usingAsyncGet);
"MemcachedConfiguration [addresses=%s, compressionEnabled=%s, connectionFactory=%s, , expiration=%s, keyPrefix=%s, timeUnit=%s, timeout=%s, usingAsyncGet=%s, usingSASL=%s, username=%s, password=%s]",
addresses, compressionEnabled, connectionFactory, expiration, keyPrefix, timeUnit, timeout, usingAsyncGet,
usingSASL, username, password);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2018 the original author or authors.
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,8 @@ private MemcachedConfigurationBuilder() {
memcachedPropertiesFilename = System.getProperty(SYSTEM_PROPERTY_MEMCACHED_PROPERTIES_FILENAME, MEMCACHED_RESOURCE);

settersRegistry.add(new StringPropertySetter("org.mybatis.caches.memcached.keyprefix", "keyPrefix", "_mybatis_"));
settersRegistry.add(new StringPropertySetter("org.mybatis.caches.memcached.username", "username", ""));
settersRegistry.add(new StringPropertySetter("org.mybatis.caches.memcached.password", "password", ""));

settersRegistry
.add(new IntegerPropertySetter("org.mybatis.caches.memcached.expiration", "expiration", 60 * 60 * 24 * 30));
Expand All @@ -63,6 +65,7 @@ private MemcachedConfigurationBuilder() {
settersRegistry.add(new BooleanPropertySetter("org.mybatis.caches.memcached.asyncget", "usingAsyncGet", false));
settersRegistry
.add(new BooleanPropertySetter("org.mybatis.caches.memcached.compression", "compressionEnabled", false));
settersRegistry.add(new BooleanPropertySetter("org.mybatis.caches.memcached.sasl", "usingSASL", false));

settersRegistry.add(new InetSocketAddressListPropertySetter());
settersRegistry.add(new ConnectionFactorySetter());
Expand Down
2 changes: 1 addition & 1 deletion src/site/site.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2012-2016 the original author or authors.
Copyright 2012-2019 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down