11package com .googlecode .hibernate .memcached .spymemcached ;
22
3+ import net .spy .memcached .AddrUtil ;
4+ import net .spy .memcached .BinaryConnectionFactory ;
5+ import net .spy .memcached .ConnectionFactory ;
6+ import net .spy .memcached .DefaultConnectionFactory ;
7+ import net .spy .memcached .HashAlgorithm ;
8+ import net .spy .memcached .KetamaConnectionFactory ;
9+ import net .spy .memcached .MemcachedClient ;
10+ import net .spy .memcached .auth .AuthDescriptor ;
11+ import net .spy .memcached .auth .PlainCallbackHandler ;
12+
313import com .googlecode .hibernate .memcached .Config ;
414import com .googlecode .hibernate .memcached .Memcache ;
515import com .googlecode .hibernate .memcached .MemcacheClientFactory ;
616import com .googlecode .hibernate .memcached .PropertiesHelper ;
7- import net .spy .memcached .*;
817
918/**
1019 * Parses hibernate properties to produce a MemcachedClient.<br/>
@@ -21,6 +30,8 @@ public class SpyMemcacheClientFactory implements MemcacheClientFactory {
2130 public static final String PROP_HASH_ALGORITHM = Config .PROP_PREFIX + "hashAlgorithm" ;
2231 public static final String PROP_CONNECTION_FACTORY = Config .PROP_PREFIX + "connectionFactory" ;
2332 public static final String PROP_DAEMON_MODE = Config .PROP_PREFIX + "daemonMode" ;
33+ public static final String PROP_USERNAME = Config .PROP_PREFIX + "username" ;
34+ public static final String PROP_PASSWORD = Config .PROP_PREFIX + "password" ;
2435 private final PropertiesHelper properties ;
2536
2637 public SpyMemcacheClientFactory (PropertiesHelper properties ) {
@@ -67,6 +78,11 @@ public long getOperationTimeout() {
6778 public boolean isDaemon () {
6879 return isDaemonMode ();
6980 }
81+
82+ @ Override
83+ public AuthDescriptor getAuthDescriptor () {
84+ return createAuthDescriptor ();
85+ }
7086 };
7187 }
7288
@@ -81,6 +97,11 @@ public long getOperationTimeout() {
8197 public boolean isDaemon () {
8298 return isDaemonMode ();
8399 }
100+
101+ @ Override
102+ public AuthDescriptor getAuthDescriptor () {
103+ return createAuthDescriptor ();
104+ }
84105 };
85106 }
86107
@@ -95,9 +116,24 @@ public long getOperationTimeout() {
95116 public boolean isDaemon () {
96117 return isDaemonMode ();
97118 }
119+
120+ @ Override
121+ public AuthDescriptor getAuthDescriptor () {
122+ return createAuthDescriptor ();
123+ }
98124 };
99125 }
100126
127+ protected AuthDescriptor createAuthDescriptor () {
128+ String username = properties .get (PROP_USERNAME );
129+ String password = properties .get (PROP_PASSWORD );
130+ if (username == null || password == null ) {
131+ return null ;
132+ }
133+ return new AuthDescriptor (new String [] { "PLAIN" },
134+ new PlainCallbackHandler (username , password ));
135+ }
136+
101137 public String getServerList () {
102138 return properties .get (PROP_SERVERS , "localhost:11211" );
103139 }
@@ -120,7 +156,7 @@ public long getOperationTimeoutMillis() {
120156 public boolean isDaemonMode () {
121157 return properties .getBoolean (PROP_DAEMON_MODE , false );
122158 }
123-
159+
124160 public HashAlgorithm getHashAlgorithm () {
125161 return properties .getEnum (PROP_HASH_ALGORITHM ,
126162 HashAlgorithm .class ,
0 commit comments