Search in sources :

Example 31 with Preference

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

the class PreferencesTest method testDeleteByType.

@Test
public void testDeleteByType() 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()));
    String unaffectedType = "X-type-2";
    final Preference unaffectedPreference = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, unaffectedType, "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(_testSubject, deletePreference, unaffectedPreference);
    Subject.doAs(_testSubject, new PrivilegedAction<Void>() {

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

Example 32 with Preference

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

the class PreferencesTest method testProhibitDuplicateNamesOfSameType.

@Test
public void testProhibitDuplicateNamesOfSameType() {
    final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    updateOrAppendAs(_testSubject, p1);
    final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    try {
        updateOrAppendAs(_testSubject, p2);
        fail("Property with same name and same type should not be allowed");
    } catch (IllegalArgumentException e) {
    // pass
    }
}
Also used : Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Example 33 with Preference

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

the class PreferencesTest method testDeleteViaReplaceByTypeAndName.

@Test
public void testDeleteViaReplaceByTypeAndName() {
    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()));
    final Preference p2 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, preferenceType, "unaffectedPropName", 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().replaceByTypeAndName(preferenceType, "propName", null));
            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)

Example 34 with Preference

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

the class PreferencesTest method testLastUpdatedDateIsImmutable.

@Test
public void testLastUpdatedDateIsImmutable() throws Exception {
    final Preference p1 = PreferenceFactory.fromAttributes(_testObject, PreferenceTestHelper.createPreferenceAttributes(null, null, "X-testType", "propName1", null, TEST_PRINCIPAL_SERIALIZATION, null, Collections.<String, Object>emptyMap()));
    Date lastUpdatedDate = p1.getLastUpdatedDate();
    lastUpdatedDate.setTime(0);
    Date lastUpdatedDate2 = p1.getLastUpdatedDate();
    assertTrue("Creation date is not immutable.", lastUpdatedDate2.getTime() != 0);
}
Also used : Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Date(java.util.Date) Test(org.junit.Test)

Example 35 with Preference

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

the class RestUserPreferenceHandlerTest method testGetVisiblePreferencesByRoot.

@Test
public void testGetVisiblePreferencesByRoot() throws Exception {
    final String prefName = "testpref";
    final String prefType = "X-testtype";
    final RequestInfo rootRequestInfo = RequestInfo.createVisiblePreferencesRequestInfo(Collections.<String>emptyList(), Collections.<String>emptyList(), Collections.<String, List<String>>emptyMap());
    Subject.doAs(_subject, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            final Set<Preference> preferences = new HashSet<>();
            Map<String, Object> pref1Attributes = createPreferenceAttributes(null, null, prefType, prefName, null, MYUSER_SERIALIZATION, Collections.singleton(MYGROUP_SERIALIZATION), Collections.<String, Object>emptyMap());
            Preference p1 = PreferenceFactory.fromAttributes(_configuredObject, pref1Attributes);
            preferences.add(p1);
            Map<String, Object> pref2Attributes = createPreferenceAttributes(null, null, prefType, "testPref2", null, MYUSER_SERIALIZATION, Collections.<String>emptySet(), Collections.<String, Object>emptyMap());
            Preference p2 = PreferenceFactory.fromAttributes(_configuredObject, pref2Attributes);
            preferences.add(p2);
            awaitPreferenceFuture(_userPreferences.updateOrAppend(preferences));
            return null;
        }
    });
    Subject testSubject2 = TestPrincipalUtils.createTestSubject("testUser2", MYGROUP);
    Subject.doAs(testSubject2, new PrivilegedAction<Void>() {

        @Override
        public Void run() {
            Map<String, List<Map<String, Object>>> typeToPreferenceListMap = (Map<String, List<Map<String, Object>>>) _handler.handleGET(_userPreferences, rootRequestInfo);
            assertEquals("Unexpected preference map size", (long) 1, (long) typeToPreferenceListMap.size());
            assertEquals("Unexpected prefType in preference map", prefType, typeToPreferenceListMap.keySet().iterator().next());
            List<Map<String, Object>> preferences = typeToPreferenceListMap.get(prefType);
            assertEquals("Unexpected number of preferences", (long) 1, (long) preferences.size());
            assertEquals("Unexpected name of preferences", prefName, preferences.get(0).get(Preference.NAME_ATTRIBUTE));
            Set<Principal> visibilityList = (Set<Principal>) preferences.get(0).get(Preference.VISIBILITY_LIST_ATTRIBUTE);
            assertEquals("Unexpected number of principals in visibility list", (long) 1, (long) visibilityList.size());
            assertTrue("Unexpected principal in visibility list", GenericPrincipal.principalsEqual(_groupPrincipal, visibilityList.iterator().next()));
            assertTrue("Unexpected owner", GenericPrincipal.principalsEqual(_userPrincipal, (Principal) preferences.get(0).get(Preference.OWNER_ATTRIBUTE)));
            return null;
        }
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Subject(javax.security.auth.Subject) Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) GroupPrincipal(org.apache.qpid.server.security.group.GroupPrincipal) GenericPrincipal(org.apache.qpid.server.model.preferences.GenericPrincipal) Principal(java.security.Principal) 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