qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1745424 - in /qpid/java/trunk/broker-core/src: main/java/org/apache/qpid/server/model/ main/java/org/apache/qpid/server/security/ test/java/org/apache/qpid/server/model/testmodels/singleton/
Date Wed, 25 May 2016 05:22:43 GMT
Author: kwall
Date: Wed May 25 05:22:42 2016
New Revision: 1745424

URL: http://svn.apache.org/viewvc?rev=1745424&view=rev
Log:
QPID-7203: [Java Broker] Ensure createdBy/createdDate/lastUpdateBy/lastUpdateDate are resolved

This special cases these attribites in the same way as the other derived storable attributes.

Modified:
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java
    qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java?rev=1745424&r1=1745423&r2=1745424&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
Wed May 25 05:22:42 2016
@@ -769,14 +769,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 Date currentTime = new Date();
                     _attributes.put(LAST_UPDATED_TIME, currentTime);
                     _attributes.put(CREATED_TIME, currentTime);
-                    _lastUpdatedTime = currentTime;
-                    _createdTime = currentTime;
 
                     CreateExceptionHandler createExceptionHandler = new CreateExceptionHandler();
                     try
@@ -1055,6 +1051,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.DATE_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.DATE_CONVERTER.convert(getActualAttributes().get(LAST_UPDATED_TIME),
this);
+        }
     }
 
     protected final void doCreation(final boolean skipCheck, final AbstractConfiguredObjectExceptionHandler
exceptionHandler)

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java?rev=1745424&r1=1745423&r2=1745424&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/SiteSpecificTrustStoreImpl.java
Wed May 25 05:22:42 2016
@@ -108,11 +108,11 @@ public class SiteSpecificTrustStoreImpl
     @Override
     protected void postResolve()
     {
+        super.postResolve();
         if(getActualAttributes().containsKey(CERTIFICATE))
         {
             decodeCertificate();
         }
-
     }
 
     @Override

Modified: qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java?rev=1745424&r1=1745423&r2=1745424&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
(original)
+++ qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
Wed May 25 05:22:42 2016
@@ -18,6 +18,9 @@
  */
 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;
@@ -32,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;
 
@@ -859,41 +863,110 @@ public class AbstractConfiguredObjectTes
         assertTrue("Expected statistic not found", stats.containsKey("longStatistic"));
     }
 
-    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 Date now = new Date();
 
-        @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 Date originalCreatedTime = object.getCreatedTime();
+        final Date originalLastUpdatedTime = object.getLastUpdatedTime();
+        assertTrue("Unexpected created time", originalCreatedTime.after(now));
+        assertEquals("Unexpected created and updated time", object.getCreatedTime(), 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.before(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