[
https://issues.apache.org/jira/browse/GEODE-3412?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16127571#comment-16127571
]
ASF GitHub Bot commented on GEODE-3412:
---------------------------------------
Github user pivotal-amurmann commented on a diff in the pull request:
https://github.com/apache/geode/pull/707#discussion_r133246611
--- Diff:
geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ServerConnectionFactory.java
---
@@ -22,59 +22,89 @@
import java.io.IOException;
import java.net.Socket;
+import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import java.util.ServiceLoader;
-import javax.management.ServiceNotFoundException;
/**
* Creates instances of ServerConnection based on the connection mode
provided.
*/
public class ServerConnectionFactory {
- private static ClientProtocolMessageHandler protobufProtocolHandler;
- private static final Object protocolLoadLock = new Object();
+ private ClientProtocolMessageHandler protobufProtocolHandler;
+ private Map<String, Class<? extends StreamAuthenticator>> authenticators
= null;
- private static ClientProtocolMessageHandler
findClientProtocolMessageHandler() {
+ public ServerConnectionFactory() {}
+
+ private synchronized void initializeAuthenticatorsMap() {
+ if (authenticators != null) {
+ return;
+ }
+ authenticators = new HashMap<>();
+ ServiceLoader<StreamAuthenticator> loader =
ServiceLoader.load(StreamAuthenticator.class);
+ for (StreamAuthenticator streamAuthenticator : loader) {
+ authenticators.put(streamAuthenticator.implementationID(),
streamAuthenticator.getClass());
+ }
+ }
+
+ private synchronized ClientProtocolMessageHandler
initializeMessageHandler() {
if (protobufProtocolHandler != null) {
return protobufProtocolHandler;
}
+ ServiceLoader<ClientProtocolMessageHandler> loader =
+ ServiceLoader.load(ClientProtocolMessageHandler.class);
+ Iterator<ClientProtocolMessageHandler> iterator = loader.iterator();
- synchronized (protocolLoadLock) {
- if (protobufProtocolHandler != null) {
- return protobufProtocolHandler;
- }
-
- ServiceLoader<ClientProtocolMessageHandler> loader =
- ServiceLoader.load(ClientProtocolMessageHandler.class);
- Iterator<ClientProtocolMessageHandler> iterator = loader.iterator();
-
- if (!iterator.hasNext()) {
- throw new ServiceLoadingFailureException(
- "ClientProtocolMessageHandler implementation not found in
JVM");
- }
+ if (!iterator.hasNext()) {
+ throw new ServiceLoadingFailureException(
+ "There is no ClientProtocolMessageHandler implementation found
in JVM");
+ }
- ClientProtocolMessageHandler returnValue = iterator.next();
+ protobufProtocolHandler = iterator.next();
+ return protobufProtocolHandler;
+ }
- if (iterator.hasNext()) {
+ private StreamAuthenticator findStreamAuthenticator(String
implementationID) {
+ if (authenticators == null) {
+ initializeAuthenticatorsMap();
+ }
+ Class<? extends StreamAuthenticator> streamAuthenticatorClass =
+ authenticators.get(implementationID);
+ if (streamAuthenticatorClass == null) {
+ throw new ServiceLoadingFailureException(
+ "Could not find implementation for StreamAuthenticator with
implementation ID "
+ + implementationID);
+ } else {
+ try {
+ return streamAuthenticatorClass.newInstance();
+ } catch (InstantiationException | IllegalAccessException e) {
throw new ServiceLoadingFailureException(
- "Multiple service implementations found for
ClientProtocolMessageHandler");
--- End diff --
Where are we now handling the case of having multiple implementations?
> Implement a basic authentication mechanism for the new protocol
> ---------------------------------------------------------------
>
> Key: GEODE-3412
> URL: https://issues.apache.org/jira/browse/GEODE-3412
> Project: Geode
> Issue Type: New Feature
> Components: client/server
> Reporter: Brian Rowe
>
> Implement a simple username/password authentication for the new protocol.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)