Search in sources :

Example 21 with Preference

use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.

the class PreferencesTest method testReplaceByType.

@Test
public void testReplaceByType() {
    final String replaceType = "X-replaceType";
    final String unaffectedType = "X-unaffectedType";
    Subject testSubject2 = TestPrincipalUtils.createTestSubject(TEST_USERNAME2);
    final Preference unaffectedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, replaceType, "propName", null, TEST_PRINCIPAL2_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(testSubject2, unaffectedPreference);
    final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, replaceType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, unaffectedType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    final Preference p3 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, replaceType, "newPropName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(_testSubject, p1, p2);
    Subject.doAs(_testSubject, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            awaitPreferenceFuture(_testObject.getUserPreferences().replaceByType(replaceType, Collections.singleton(p3)));
            return null;
        }
    });
    assertPreferences(_testSubject, p2, p3);
    assertPreferences(testSubject2, unaffectedPreference);
}
Also used : Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 22 with Preference

use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.

the class PreferencesTest method testDeleteByTypeAndId.

@Test
public void testDeleteByTypeAndId() throws Exception {
    final String deleteType = "X-type-1";
    final Preference deletePreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, deleteType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    final Preference unaffectedPreference1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, deleteType, "propName2", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    String unaffectedType = "X-type-2";
    final Preference unaffectedPreference2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, unaffectedType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(_testSubject, deletePreference, unaffectedPreference1, unaffectedPreference2);
    Subject.doAs(_testSubject, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            awaitPreferenceFuture(_testObject.getUserPreferences().delete(deleteType, null, deletePreference.getId()));
            return null;
        }
    });
    assertPreferences(_testSubject, unaffectedPreference1, unaffectedPreference2);
}
Also used : Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 23 with Preference

use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.

the class PreferencesTest method testProhibitPreferenceStealing.

@Test
public void testProhibitPreferenceStealing() throws Exception {
    final String testGroupName = "testGroup";
    Subject user1Subject = TestPrincipalUtils.createTestSubject(TEST_USERNAME, testGroupName);
    Map<String, Object> preferenceAttributes = PreferenceTestHelper.createPreferenceAttributes(_testObject.getId(), null, "X-PREF", "prefname", null, TEST_PRINCIPAL_SERIALIZATION, Collections.singleton(TestPrincipalUtils.getTestPrincipalSerialization(testGroupName)), Collections.<String, Object>emptyMap());
    final Preference originalPreference = PreferenceFactory.fromAttributes(_testObject, preferenceAttributes);
    updateOrAppendAs(user1Subject, originalPreference);
    Subject user2Subject = TestPrincipalUtils.createTestSubject(TEST_USERNAME2, testGroupName);
    Subject.doAs(user2Subject, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            final ListenableFuture<Set<Preference>> visiblePreferencesFuture = _testObject.getUserPreferences().getVisiblePreferences();
            final Set<Preference> visiblePreferences = PreferenceTestHelper.awaitPreferenceFuture(visiblePreferencesFuture);
            assertEquals("Unexpected number of visible preferences", (long) 1, (long) visiblePreferences.size());
            final Preference target = visiblePreferences.iterator().next();
            Map<String, Object> replacementAttributes = new HashMap(target.getAttributes());
            replacementAttributes.put(Preference.OWNER_ATTRIBUTE, TEST_PRINCIPAL2_SERIALIZATION);
            try {
                awaitPreferenceFuture(_testObject.getUserPreferences().updateOrAppend(Arrays.asList(PreferenceFactory.fromAttributes(_testObject, replacementAttributes))));
                fail("The stealing of a preference must be prohibited");
            } catch (IllegalArgumentException e) {
            // pass
            }
            return null;
        }
    });
    assertPreferences(user1Subject, originalPreference);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Subject(javax.security.auth.Subject) Preference(org.apache.qpid.server.model.preferences.Preference) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 24 with Preference

use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.

the class PreferencesTest method testGetVisiblePreferencesSharedByGroup.

@Test
public void testGetVisiblePreferencesSharedByGroup() {
    final String testGroupName = "testGroup";
    Subject testSubjectWithGroup = TestPrincipalUtils.createTestSubject(TEST_USERNAME, testGroupName);
    final Preference sharedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName1", null, TEST_PRINCIPAL2_SERIALIZATION, Collections.singleton(TestPrincipalUtils.getTestPrincipalSerialization(testGroupName)), Collections.<String, Object>emptyMap()));
    Subject peerSubject = TestPrincipalUtils.createTestSubject(TEST_USERNAME2, testGroupName);
    updateOrAppendAs(peerSubject, sharedPreference);
    final Preference testUserPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(testSubjectWithGroup, testUserPreference);
    Subject.doAs(testSubjectWithGroup, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            Set<Preference> retrievedPreferences = awaitPreferenceFuture(_testObject.getUserPreferences().getVisiblePreferences());
            assertEquals("Unexpected number of preferences", (long) 2, (long) retrievedPreferences.size());
            assertTrue("Preference of my peer did not exist in visible set", retrievedPreferences.contains(sharedPreference));
            assertTrue("My preference did not exist in visible set", retrievedPreferences.contains(testUserPreference));
            return null;
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 25 with Preference

use of org.apache.qpid.server.model.preferences.Preference in project qpid-broker-j by apache.

the class PreferencesTest method testDeleteAll.

@Test
public void testDeleteAll() throws Exception {
    final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-type-1", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-type-2", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(_testSubject, p1, p2);
    Subject.doAs(_testSubject, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            awaitPreferenceFuture(_testObject.getUserPreferences().delete(null, null, null));
            Set<Preference> result = awaitPreferenceFuture(_testObject.getUserPreferences().getPreferences());
            assertEquals("Unexpected number of preferences", (long) 0, (long) result.size());
            return null;
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Aggregations

Preference (org.apache.qpid.server.model.preferences.Preference)40 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)39 Test (org.junit.Test)31 Subject (javax.security.auth.Subject)16 HashMap (java.util.HashMap)11 Map (java.util.Map)9 Set (java.util.Set)9 HashSet (java.util.HashSet)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)5 Date (java.util.Date)4 GroupPrincipal (org.apache.qpid.server.security.group.GroupPrincipal)4 Principal (java.security.Principal)3 UUID (java.util.UUID)3 GenericPrincipal (org.apache.qpid.server.model.preferences.GenericPrincipal)3 UserPreferencesImpl (org.apache.qpid.server.model.preferences.UserPreferencesImpl)3 LinkedHashSet (java.util.LinkedHashSet)2 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)2 UserPreferences (org.apache.qpid.server.model.preferences.UserPreferences)2