Search in sources :

Example 26 with Preference

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

the class PreferencesTest method testGetOnlyOwnedPreferences.

@Test
public void testGetOnlyOwnedPreferences() {
    final Preference testUserPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "prop1", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(_testSubject, testUserPreference);
    final Preference testUser2Preference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "prop2", null, TEST_PRINCIPAL2_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    Subject testSubject2 = TestPrincipalUtils.createTestSubject(TEST_USERNAME2);
    updateOrAppendAs(testSubject2, testUser2Preference);
    assertPreferences(testSubject2, testUser2Preference);
    assertPreferences(_testSubject, testUserPreference);
}
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 27 with Preference

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

the class PreferencesTest method testDeleteViaReplace.

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

        @Override
        public Void run() {
            awaitPreferenceFuture(_testObject.getUserPreferences().replace(Collections.<Preference>emptySet()));
            return null;
        }
    });
    assertPreferences(_testSubject);
    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 28 with Preference

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

the class PreferencesTest method testDeleteByTypeAndNameAndId.

@Test
public void testDeleteByTypeAndNameAndId() throws Exception {
    final String deleteType = "X-type-1";
    final String deletePropertyName = "propName";
    final Preference deletePreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, deleteType, deletePropertyName, 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, deletePropertyName, 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, deletePropertyName, 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 29 with Preference

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

the class PreferencesTest method testGetVisiblePreferences.

@Test
public void testGetVisiblePreferences() {
    final String testGroupName = "testGroup";
    Subject sharer = TestPrincipalUtils.createTestSubject(TEST_USERNAME2, testGroupName);
    Subject nonSharer = TestPrincipalUtils.createTestSubject(TEST_USERNAME, testGroupName);
    final Preference sharedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName1", "shared with group", TEST_PRINCIPAL2_SERIALIZATION, Collections.singleton(TestPrincipalUtils.getTestPrincipalSerialization(testGroupName)), Collections.<String, Object>emptyMap()));
    final Preference notSharedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName2", null, TEST_PRINCIPAL2_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(sharer, sharedPreference, notSharedPreference);
    final Preference nonSharersPrivatePref = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(nonSharer, nonSharersPrivatePref);
    Subject.doAs(nonSharer, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            Set<Preference> retrievedPreferences = awaitPreferenceFuture(_testObject.getUserPreferences().getVisiblePreferences());
            assertEquals("Unexpected number of preferences", (long) 2, (long) retrievedPreferences.size());
            Set<UUID> visibleIds = new HashSet<>(retrievedPreferences.size());
            for (Preference preference : retrievedPreferences) {
                visibleIds.add(preference.getId());
            }
            assertTrue("Owned preference not visible", visibleIds.contains(nonSharersPrivatePref.getId()));
            assertTrue("Shared preference not visible", visibleIds.contains(sharedPreference.getId()));
            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 30 with Preference

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

the class PreferencesTest method testDeleteViaReplaceByType.

@Test
public void testDeleteViaReplaceByType() {
    final String preferenceType = "X-testType";
    final String unaffectedPreferenceType = "X-unaffectedType";
    Subject testSubject2 = TestPrincipalUtils.createTestSubject(TEST_USERNAME2);
    final Preference unaffectedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, preferenceType, "propName", null, TEST_PRINCIPAL2_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(testSubject2, unaffectedPreference);
    final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, preferenceType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, unaffectedPreferenceType, "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().replaceByType(preferenceType, Collections.<Preference>emptySet()));
            return null;
        }
    });
    assertPreferences(_testSubject, p2);
    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)

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