Repository: qpid-broker-j
Updated Branches:
  refs/heads/master 16a186bab -> d4d408f27


QPID-7934: [Java Broker] Refactor CO implementation overridding changeAttribute 
to use changeAttribute instead. Made changeAttribute final.


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/54f8074c
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/54f8074c
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/54f8074c

Branch: refs/heads/master
Commit: 54f8074c4447815f2a3cf66da897fcb27364612f
Parents: 16a186b
Author: Keith Wall <[email protected]>
Authored: Fri Sep 29 11:59:24 2017 +0100
Committer: Keith Wall <[email protected]>
Committed: Fri Sep 29 13:03:53 2017 +0100

----------------------------------------------------------------------
 .../apache/qpid/server/queue/AbstractQueue.java | 51 ++++++++------------
 .../security/auth/manager/ManagedUser.java      | 15 ++++--
 .../PrincipalDatabaseAuthenticationManager.java | 15 +++---
 3 files changed, 35 insertions(+), 46 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/54f8074c/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
----------------------------------------------------------------------
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java 
b/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
index 1bfe661..565a0dd 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
@@ -3088,46 +3088,19 @@ public abstract class AbstractQueue<X extends 
AbstractQueue<X>>
     }
 
     @Override
-    protected boolean changeAttribute(String name, Object desired) throws 
IllegalStateException, AccessControlException, IllegalArgumentException
-    {
-        if(EXCLUSIVE.equals(name))
-        {
-            ExclusivityPolicy existingPolicy = getExclusive();
-            if(super.changeAttribute(name, desired))
-            {
-                try
-                {
-                    if(existingPolicy != _exclusive)
-                    {
-                        ExclusivityPolicy newPolicy = _exclusive;
-                        _exclusive = existingPolicy;
-                        updateExclusivityPolicy(newPolicy);
-                    }
-                    return true;
-                }
-                catch (ExistingConsumerPreventsExclusive 
existingConsumerPreventsExclusive)
-                {
-                    throw new IllegalArgumentException("Unable to set 
exclusivity policy to " + desired + " as an existing combinations of consumers 
prevents this");
-                }
-            }
-            return false;
-        }
-
-        return super.changeAttribute(name, desired);
-    }
-
-    @Override
     protected void changeAttributes(final Map<String, Object> attributes)
     {
-        OverflowPolicy existingPolicy = getOverflowPolicy();
+        final OverflowPolicy existingOverflowPolicy = getOverflowPolicy();
+        final ExclusivityPolicy existingExclusivePolicy = getExclusive();
+
         super.changeAttributes(attributes);
 
         // Overflow policies depend on queue depth attributes.
         // Thus, we need to create and invoke  overflow policy handler
         // after all required attributes are changed.
-        if (attributes.containsKey(OVERFLOW_POLICY) && existingPolicy != 
_overflowPolicy)
+        if (attributes.containsKey(OVERFLOW_POLICY) && existingOverflowPolicy 
!= _overflowPolicy)
         {
-            if (existingPolicy == OverflowPolicy.REJECT)
+            if (existingOverflowPolicy == OverflowPolicy.REJECT)
             {
                 _rejectPolicyHandler = null;
             }
@@ -3135,6 +3108,20 @@ public abstract class AbstractQueue<X extends 
AbstractQueue<X>>
 
             _postEnqueueOverflowPolicyHandler.checkOverflow(null);
         }
+
+        if (attributes.containsKey(EXCLUSIVE) && existingExclusivePolicy != 
_exclusive)
+        {
+            ExclusivityPolicy newPolicy = _exclusive;
+            try
+            {
+                _exclusive = existingExclusivePolicy;
+                updateExclusivityPolicy(newPolicy);
+            }
+            catch (ExistingConsumerPreventsExclusive 
existingConsumerPreventsExclusive)
+            {
+                throw new IllegalArgumentException("Unable to set exclusivity 
policy to " + newPolicy + " as an existing combinations of consumers prevents 
this");
+            }
+        }
     }
 
     private static final String[] NON_NEGATIVE_NUMBERS = {

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/54f8074c/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ManagedUser.java
----------------------------------------------------------------------
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ManagedUser.java
 
b/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ManagedUser.java
index 7f867d2..b00edd9 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ManagedUser.java
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/ManagedUser.java
@@ -21,8 +21,11 @@
 package org.apache.qpid.server.security.auth.manager;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Map;
 
+import javax.security.auth.login.AccountNotFoundException;
+
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
 
@@ -81,17 +84,19 @@ class ManagedUser extends 
AbstractConfiguredObject<ManagedUser> implements User<
     }
 
     @Override
-    protected boolean changeAttribute(String name, Object desired)
+    protected void changeAttributes(Map<String, Object> attributes)
     {
-        if (User.PASSWORD.equals(name))
+        if(attributes.containsKey(PASSWORD))
         {
-            String storedPassword = 
_authenticationManager.createStoredPassword((String)desired);
+            String desiredPassword = (String) attributes.get(PASSWORD);
+            String storedPassword = 
_authenticationManager.createStoredPassword(desiredPassword);
             if 
(!storedPassword.equals(getActualAttributes().get(User.PASSWORD)))
             {
-                desired = storedPassword;
+                attributes = new HashMap<>(attributes);
+                attributes.put(PASSWORD, storedPassword);
             }
         }
-        return super.changeAttribute(name, desired);
+        super.changeAttributes(attributes);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/54f8074c/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
----------------------------------------------------------------------
diff --git 
a/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
 
b/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
index f379b93..9716d33 100644
--- 
a/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
+++ 
b/broker-core/src/main/java/org/apache/qpid/server/security/auth/manager/PrincipalDatabaseAuthenticationManager.java
@@ -25,7 +25,6 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.security.AccessControlException;
 import java.security.Principal;
 import java.util.Collections;
 import java.util.HashMap;
@@ -423,27 +422,25 @@ public abstract class 
PrincipalDatabaseAuthenticationManager<T extends Principal
         }
 
         @Override
-        public boolean changeAttribute(String name, Object desired)
-                throws IllegalStateException, AccessControlException, 
IllegalArgumentException
+        protected void changeAttributes(final Map<String, Object> attributes)
         {
-            if(name.equals(PASSWORD))
+            if(attributes.containsKey(PASSWORD))
             {
                 try
                 {
-                    String desiredPassword = (String) desired;
+                    String desiredPassword = (String) attributes.get(PASSWORD);
                     boolean changed = 
getPrincipalDatabase().updatePassword(_user, desiredPassword.toCharArray());
-                    if (changed)
+                    if (!changed)
                     {
-                        return super.changeAttribute(name, desired);
+                        throw new IllegalStateException(String.format("Failed 
to user password for user : '%s'", getName()));
                     }
-                    return false;
                 }
                 catch(AccountNotFoundException e)
                 {
                     throw new IllegalStateException(e);
                 }
             }
-            return super.changeAttribute(name, desired);
+            super.changeAttributes(attributes);
         }
 
         @StateTransition(currentState = {State.UNINITIALIZED,State.ERRORED}, 
desiredState = State.ACTIVE)


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to