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);
}
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);
}
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);
}
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;
}
});
}
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;
}
});
}
Aggregations