You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/07/12 14:01:22 UTC

[1/2] activemq-artemis git commit: ARTEMIS-626 re-use context for LDAP

Repository: activemq-artemis
Updated Branches:
  refs/heads/master 1d886730b -> 08ab1f708


ARTEMIS-626 re-use context for LDAP


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/f3a8619d
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/f3a8619d
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/f3a8619d

Branch: refs/heads/master
Commit: f3a8619d7eeabded75f3725f2e77af267e8cb450
Parents: 1d88673
Author: jbertram <jb...@apache.org>
Authored: Mon Jul 11 13:07:35 2016 -0500
Committer: jbertram <jb...@apache.org>
Committed: Mon Jul 11 13:08:34 2016 -0500

----------------------------------------------------------------------
 .../spi/core/security/jaas/LDAPLoginModule.java | 74 +++++++++++---------
 1 file changed, 39 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f3a8619d/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/LDAPLoginModule.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/LDAPLoginModule.java b/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/LDAPLoginModule.java
index edcf38e..8bb5405 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/LDAPLoginModule.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/spi/core/security/jaas/LDAPLoginModule.java
@@ -145,12 +145,15 @@ public class LDAPLoginModule implements LoginModule {
       return true;
    }
 
-   protected void close(DirContext context) {
-      try {
-         context.close();
-      }
-      catch (Exception e) {
-         ActiveMQServerLogger.LOGGER.error(e.toString());
+   protected void closeContext() {
+      if (context != null) {
+         try {
+            context.close();
+            context = null;
+         }
+         catch (Exception e) {
+            ActiveMQServerLogger.LOGGER.error(e.toString());
+         }
       }
    }
 
@@ -159,13 +162,11 @@ public class LDAPLoginModule implements LoginModule {
       MessageFormat userSearchMatchingFormat;
       boolean userSearchSubtreeBool;
 
-      DirContext context = null;
-
       if (logger.isDebugEnabled()) {
          logger.debug("Create the LDAP initial context.");
       }
       try {
-         context = open();
+         openContext();
       }
       catch (NamingException ne) {
          FailedLoginException ex = new FailedLoginException("Error opening LDAP connection");
@@ -246,7 +247,7 @@ public class LDAPLoginModule implements LoginModule {
                }
             }
             catch (URISyntaxException e) {
-               close(context);
+               closeContext();
                FailedLoginException ex = new FailedLoginException("Error parsing absolute name as URI.");
                ex.initCause(e);
                throw ex;
@@ -282,12 +283,13 @@ public class LDAPLoginModule implements LoginModule {
          }
       }
       catch (CommunicationException e) {
+         closeContext();
          FailedLoginException ex = new FailedLoginException("Error contacting LDAP");
          ex.initCause(e);
          throw ex;
       }
       catch (NamingException e) {
-         close(context);
+         closeContext();
          FailedLoginException ex = new FailedLoginException("Error contacting LDAP");
          ex.initCause(e);
          throw ex;
@@ -453,34 +455,36 @@ public class LDAPLoginModule implements LoginModule {
       return values;
    }
 
-   protected DirContext open() throws NamingException {
-      try {
-         Hashtable<String, String> env = new Hashtable<>();
-         env.put(Context.INITIAL_CONTEXT_FACTORY, getLDAPPropertyValue(INITIAL_CONTEXT_FACTORY));
-         if (isLoginPropertySet(CONNECTION_USERNAME)) {
-            env.put(Context.SECURITY_PRINCIPAL, getLDAPPropertyValue(CONNECTION_USERNAME));
-         }
-         else {
-            throw new NamingException("Empty username is not allowed");
-         }
+   protected void openContext() throws NamingException {
+      if (context == null) {
+         try {
+            Hashtable<String, String> env = new Hashtable<>();
+            env.put(Context.INITIAL_CONTEXT_FACTORY, getLDAPPropertyValue(INITIAL_CONTEXT_FACTORY));
+            if (isLoginPropertySet(CONNECTION_USERNAME)) {
+               env.put(Context.SECURITY_PRINCIPAL, getLDAPPropertyValue(CONNECTION_USERNAME));
+            }
+            else {
+               throw new NamingException("Empty username is not allowed");
+            }
+
+            if (isLoginPropertySet(CONNECTION_PASSWORD)) {
+               env.put(Context.SECURITY_CREDENTIALS, getLDAPPropertyValue(CONNECTION_PASSWORD));
+            }
+            else {
+               throw new NamingException("Empty password is not allowed");
+            }
+            env.put(Context.SECURITY_PROTOCOL, getLDAPPropertyValue(CONNECTION_PROTOCOL));
+            env.put(Context.PROVIDER_URL, getLDAPPropertyValue(CONNECTION_URL));
+            env.put(Context.SECURITY_AUTHENTICATION, getLDAPPropertyValue(AUTHENTICATION));
+            context = new InitialDirContext(env);
 
-         if (isLoginPropertySet(CONNECTION_PASSWORD)) {
-            env.put(Context.SECURITY_CREDENTIALS, getLDAPPropertyValue(CONNECTION_PASSWORD));
          }
-         else {
-            throw new NamingException("Empty password is not allowed");
+         catch (NamingException e) {
+            closeContext();
+            ActiveMQServerLogger.LOGGER.error(e.toString());
+            throw e;
          }
-         env.put(Context.SECURITY_PROTOCOL, getLDAPPropertyValue(CONNECTION_PROTOCOL));
-         env.put(Context.PROVIDER_URL, getLDAPPropertyValue(CONNECTION_URL));
-         env.put(Context.SECURITY_AUTHENTICATION, getLDAPPropertyValue(AUTHENTICATION));
-         context = new InitialDirContext(env);
-
-      }
-      catch (NamingException e) {
-         ActiveMQServerLogger.LOGGER.error(e.toString());
-         throw e;
       }
-      return context;
    }
 
    private String getLDAPPropertyValue(String propertyName) {


[2/2] activemq-artemis git commit: This closes #629

Posted by cl...@apache.org.
This closes #629


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/08ab1f70
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/08ab1f70
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/08ab1f70

Branch: refs/heads/master
Commit: 08ab1f70822fddf18ff739b5c49257af6cbd0b25
Parents: 1d88673 f3a8619
Author: Clebert Suconic <cl...@apache.org>
Authored: Tue Jul 12 10:01:02 2016 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Tue Jul 12 10:01:02 2016 -0400

----------------------------------------------------------------------
 .../spi/core/security/jaas/LDAPLoginModule.java | 74 +++++++++++---------
 1 file changed, 39 insertions(+), 35 deletions(-)
----------------------------------------------------------------------