qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lqu...@apache.org
Subject svn commit: r1746479 - in /qpid/java/branches/6.0.x: ./ broker-core/src/main/java/org/apache/qpid/server/model/ broker-core/src/main/java/org/apache/qpid/server/security/ broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/
Date Wed, 01 Jun 2016 15:27:37 GMT
Author: lquack
Date: Wed Jun  1 15:27:37 2016
New Revision: 1746479

URL: http://svn.apache.org/viewvc?rev=1746479&view=rev
Log:
QPID-7203: [Java Broker] Preserve model audit information

merged from trunk:
$ svn merge -c 1745424,1745450 ^/qpid/java/trunk

Modified:
    qpid/java/branches/6.0.x/   (props changed)
    qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
    qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java
    qpid/java/branches/6.0.x/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java

Propchange: qpid/java/branches/6.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jun  1 15:27:37 2016
@@ -9,5 +9,5 @@
 /qpid/branches/java-broker-vhost-refactor/java:1493674-1494547
 /qpid/branches/java-network-refactor/qpid/java:805429-821809
 /qpid/branches/qpid-2935/qpid/java:1061302-1072333
-/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728651,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729
 657,1729783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732184,1732452,1732461,1732525,1732812,1733467,1734452,1736478,1736751,1736838,1737804,1737835,1737853,1737984,1737992,1738119,1738135,1738231,1738271,1738607,1738610,1738731,1738914,1741702,1742257,1742284,1742544,1742900,1742926,1743161,1743228,1743383,1743982,1744012-1744013,1744046,1744123,1744157,1744276,1744403
+/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728651,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729
 657,1729783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732184,1732452,1732461,1732525,1732812,1733467,1734452,1736478,1736751,1736838,1737804,1737835,1737853,1737984,1737992,1738119,1738135,1738231,1738271,1738607,1738610,1738731,1738914,1741702,1742257,1742284,1742544,1742900,1742926,1743161,1743228,1743383,1743982,1744012-1744013,1744046,1744123,1744157,1744276,1744403,1745424,1745450
 /qpid/trunk/qpid:796646-796653

Modified: qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java?rev=1746479&r1=1746478&r2=1746479&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
(original)
+++ qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
Wed Jun  1 15:27:37 2016
@@ -728,14 +728,10 @@ public abstract class AbstractConfigured
                         String currentUserName = currentUser.getName();
                         _attributes.put(LAST_UPDATED_BY, currentUserName);
                         _attributes.put(CREATED_BY, currentUserName);
-                        _lastUpdatedBy = currentUserName;
-                        _createdBy = currentUserName;
                     }
                     final long currentTime = System.currentTimeMillis();
                     _attributes.put(LAST_UPDATED_TIME, currentTime);
                     _attributes.put(CREATED_TIME, currentTime);
-                    _lastUpdatedTime = currentTime;
-                    _createdTime = currentTime;
 
                     CreateExceptionHandler createExceptionHandler = new CreateExceptionHandler();
                     try
@@ -1014,6 +1010,22 @@ public abstract class AbstractConfigured
 
     protected void postResolve()
     {
+        if (getActualAttributes().get(CREATED_BY) != null)
+        {
+            _createdBy = (String) getActualAttributes().get(CREATED_BY);
+        }
+        if (getActualAttributes().get(CREATED_TIME) != null)
+        {
+            _createdTime = AttributeValueConverter.LONG_CONVERTER.convert(getActualAttributes().get(CREATED_TIME),
this);
+        }
+        if (getActualAttributes().get(LAST_UPDATED_BY) != null)
+        {
+            _lastUpdatedBy = (String) getActualAttributes().get(LAST_UPDATED_BY);
+        }
+        if (getActualAttributes().get(LAST_UPDATED_TIME) != null)
+        {
+            _lastUpdatedTime = AttributeValueConverter.LONG_CONVERTER.convert(getActualAttributes().get(LAST_UPDATED_TIME),
this);
+        }
     }
 
     protected final void doCreation(final boolean skipCheck, final AbstractConfiguredObjectExceptionHandler
exceptionHandler)

Modified: qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java?rev=1746479&r1=1746478&r2=1746479&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java
(original)
+++ qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java
Wed Jun  1 15:27:37 2016
@@ -109,11 +109,11 @@ public class SiteSpecificTrustStoreImpl
     @Override
     protected void postResolve()
     {
+        super.postResolve();
         if(getActualAttributes().containsKey(CERTIFICATE))
         {
             decodeCertificate();
         }
-
     }
 
     @Override

Modified: qpid/java/branches/6.0.x/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
URL: http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java?rev=1746479&r1=1746478&r2=1746479&view=diff
==============================================================================
--- qpid/java/branches/6.0.x/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
(original)
+++ qpid/java/branches/6.0.x/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
Wed Jun  1 15:27:37 2016
@@ -18,9 +18,13 @@
  */
 package org.apache.qpid.server.model.testmodels.singleton;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 import java.security.PrivilegedAction;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -31,10 +35,11 @@ import javax.security.auth.Subject;
 
 import org.apache.qpid.server.configuration.IllegalConfigurationException;
 import org.apache.qpid.server.model.AbstractConfiguredObject;
-import org.apache.qpid.server.model.ConfigurationChangeListener;
 import org.apache.qpid.server.model.ConfiguredObject;
 import org.apache.qpid.server.model.Model;
-import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.NoopConfigurationChangeListener;
+import org.apache.qpid.server.model.SystemConfig;
+import org.apache.qpid.server.security.auth.AuthenticatedPrincipal;
 import org.apache.qpid.server.store.ConfiguredObjectRecord;
 import org.apache.qpid.test.utils.QpidTestCase;
 
@@ -700,41 +705,172 @@ public class AbstractConfiguredObjectTes
         assertEquals("${foo3}", object.getActualAttributes().get(TestSingleton.STRING_VALUE));
     }
 
-    private static class NoopConfigurationChangeListener implements ConfigurationChangeListener
+    public void testAuditInformation() throws Exception
     {
-        @Override
-        public void stateChanged(final ConfiguredObject<?> object, final State oldState,
final State newState)
-        {
-        }
+        final String creatingUser = "creatingUser";
+        final String updatingUser = "updatingUser";
+        final Subject creatorSubject = createTestAuthenticatedSubject(creatingUser);
+        final Subject updaterSubject = createTestAuthenticatedSubject(updatingUser);
+        final long now = new Date().getTime();
 
-        @Override
-        public void childAdded(final ConfiguredObject<?> object, final ConfiguredObject<?>
child)
-        {
-        }
+        Thread.sleep(5);  // Let a small amount of time pass
 
-        @Override
-        public void childRemoved(final ConfiguredObject<?> object, final ConfiguredObject<?>
child)
-        {
-        }
+        final Map<String, Object> attributes = new HashMap<>();
+        attributes.put(TestSingleton.NAME, "myName");
 
-        @Override
-        public void attributeSet(final ConfiguredObject<?> object,
-                                 final String attributeName,
-                                 final Object oldAttributeValue,
-                                 final Object newAttributeValue)
-        {
-        }
+        final TestSingleton object = Subject.doAs(creatorSubject,
+                     new PrivilegedAction<TestSingleton>()
+                     {
+                         @Override
+                         public TestSingleton run()
+                         {
+                             return _model.getObjectFactory().create(TestSingleton.class,
attributes);
+                         }
+                     });
 
-        @Override
-        public void bulkChangeStart(final ConfiguredObject<?> object)
-        {
+        assertEquals("Unexpected creating user after object creation", creatingUser, object.getCreatedBy());
+        assertEquals("Unexpected last updating user after object creation", creatingUser,
object.getLastUpdatedBy());
 
-        }
+        final long originalCreatedTime = object.getCreatedTime();
+        final long originalLastUpdatedTime = object.getLastUpdatedTime();
+        assertTrue("Unexpected created time", originalCreatedTime > now);
+        assertEquals("Unexpected created and updated time", originalCreatedTime, originalLastUpdatedTime);
 
-        @Override
-        public void bulkChangeEnd(final ConfiguredObject<?> object)
-        {
+        Thread.sleep(5);  // Let a small amount of time pass
 
-        }
+        Subject.doAs(updaterSubject,
+                     new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             object.setAttributes(Collections.singletonMap(TestSingleton.INT_VALUE,
5));
+                             return null;
+                         }
+                     });
+
+        assertEquals("Creating user should not be changed by update", creatingUser, object.getCreatedBy());
+        assertEquals("Created time should not be changed by update", originalCreatedTime,
object.getCreatedTime());
+
+        assertEquals("Last updated by should be changed by update", updatingUser, object.getLastUpdatedBy());
+        assertTrue("Last updated time by should be changed by update", originalLastUpdatedTime
< object.getLastUpdatedTime());
     }
+
+    public void testAuditInformationIgnoresUserSuppliedAttributes() throws Exception
+    {
+        final String user = "user";
+        final Subject userSubject = createTestAuthenticatedSubject(user);
+
+        final Map<String, Object> attributes = new HashMap<>();
+        attributes.put(TestSingleton.NAME, "myName");
+        attributes.put(TestSingleton.CREATED_BY, "bogusCreator");
+        attributes.put(TestSingleton.CREATED_TIME, new Date(0));
+        attributes.put(TestSingleton.LAST_UPDATED_BY, "bogusUpdater");
+        attributes.put(TestSingleton.LAST_UPDATED_TIME, new Date(0));
+
+        final long now = new Date().getTime();
+        Thread.sleep(5);  // Let a small amount of time pass
+
+        final TestSingleton object = Subject.doAs(userSubject,
+                                                  new PrivilegedAction<TestSingleton>()
+                                                  {
+                                                      @Override
+                                                      public TestSingleton run()
+                                                      {
+                                                          return _model.getObjectFactory().create(TestSingleton.class,
attributes);
+                                                      }
+                                                  });
+
+        assertEquals("Unexpected creating user after object creation", user,  object.getCreatedBy());
+        assertEquals("Unexpected last updating user after object creation", user, object.getLastUpdatedBy());
+
+        final long originalCreatedTime = object.getCreatedTime();
+        assertTrue("Unexpected created time", originalCreatedTime > now);
+        final long originalLastUpdatedTime = object.getLastUpdatedTime();
+        assertEquals("Unexpected created and updated time", originalCreatedTime, originalLastUpdatedTime);
+
+
+        Subject.doAs(userSubject,
+                     new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             final Map<String, Object> updateMap = new HashMap<>();
+                             updateMap.put(TestSingleton.INT_VALUE, 5);
+                             updateMap.put(TestSingleton.CREATED_BY, "bogusCreator");
+                             updateMap.put(TestSingleton.CREATED_TIME, new Date(0));
+                             updateMap.put(TestSingleton.LAST_UPDATED_BY, "bogusUpdater");
+                             updateMap.put(TestSingleton.LAST_UPDATED_TIME, new Date(0));
+
+                             object.setAttributes(updateMap);
+                             return null;
+                         }
+                     });
+
+        Thread.sleep(5);  // Let a small amount of time pass
+
+        assertEquals("Creating user should not be changed by update", user, object.getCreatedBy());
+        assertEquals("Created time should not be changed by update", originalCreatedTime,
object.getCreatedTime());
+
+        assertEquals("Last updated by should be changed by update", user, object.getLastUpdatedBy());
+        assertTrue("Last updated time by should be changed by update", originalLastUpdatedTime
< object.getLastUpdatedTime());
+    }
+
+
+    public void testAuditInformationPersistenceAndRecovery() throws Exception
+    {
+        final String creatingUser = "creatingUser";
+        final Subject creatorSubject = createTestAuthenticatedSubject(creatingUser);
+        final String objectName = "myName";
+
+        final Map<String, Object> attributes = new HashMap<>();
+        attributes.put(TestSingleton.NAME, objectName);
+
+        final TestSingleton object = Subject.doAs(creatorSubject,
+                                                  new PrivilegedAction<TestSingleton>()
+                                                  {
+                                                      @Override
+                                                      public TestSingleton run()
+                                                      {
+                                                          return _model.getObjectFactory()
+                                                                  .create(TestSingleton.class,
attributes);
+                                                      }
+                                                  });
+
+        final ConfiguredObjectRecord cor = object.asObjectRecord();
+        final Map<String, Object> recordedAttributes = cor.getAttributes();
+
+        assertTrue(recordedAttributes.containsKey(ConfiguredObject.LAST_UPDATED_BY));
+        assertTrue(recordedAttributes.containsKey(ConfiguredObject.LAST_UPDATED_TIME));
+        assertTrue(recordedAttributes.containsKey(ConfiguredObject.CREATED_BY));
+        assertTrue(recordedAttributes.containsKey(ConfiguredObject.CREATED_TIME));
+
+        assertEquals(creatingUser, recordedAttributes.get(ConfiguredObject.CREATED_BY));
+        assertEquals(creatingUser, recordedAttributes.get(ConfiguredObject.LAST_UPDATED_BY));
+
+        // Now recover the object
+
+        final SystemConfig mockSystemConfig = mock(SystemConfig.class);
+        when(mockSystemConfig.getId()).thenReturn(UUID.randomUUID());
+        when(mockSystemConfig.getModel()).thenReturn(TestModel.getInstance());
+
+        final TestSingleton recovered = (TestSingleton) _model.getObjectFactory().recover(cor,
mockSystemConfig).resolve();
+        recovered.open();
+
+        assertEquals("Unexpected recovered object created by", object.getCreatedBy(), recovered.getCreatedBy());
+        assertEquals("Unexpected recovered object created time", object.getCreatedTime(),
recovered.getCreatedTime());
+
+        assertEquals("Unexpected recovered object updated by", object.getLastUpdatedBy(),
recovered.getLastUpdatedBy());
+        assertEquals("Unexpected recovered object updated time", object.getLastUpdatedTime(),
recovered.getLastUpdatedTime());
+    }
+
+    private Subject createTestAuthenticatedSubject(final String username)
+    {
+        return new Subject(true,
+                           Collections.singleton(new AuthenticatedPrincipal(username)),
+                           Collections.emptySet(),
+                           Collections.emptySet());
+    }
+
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message