Search in sources :

Example 1 with UserPreferencesImpl

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

the class PreferencesRecoverer method setUserPreferences.

private void setUserPreferences(ConfiguredObject<?> associatedObject, Map<UUID, Collection<PreferenceRecord>> objectToRecordMap, PreferenceStore preferenceStore, final Set<UUID> corruptedRecords) {
    final Collection<PreferenceRecord> preferenceRecords = objectToRecordMap.remove(associatedObject.getId());
    Collection<Preference> recoveredPreferences = new ArrayList<>();
    if (preferenceRecords != null) {
        for (PreferenceRecord preferenceRecord : preferenceRecords) {
            Map<String, Object> attributes = preferenceRecord.getAttributes();
            try {
                Preference recoveredPreference = PreferenceFactory.fromAttributes(associatedObject, attributes);
                validateRecoveredPreference(recoveredPreference);
                recoveredPreferences.add(recoveredPreference);
            } catch (IllegalArgumentException e) {
                LOGGER.info(String.format("Cannot recover preference '%s/%s'", preferenceRecord.getId(), attributes.get(Preference.NAME_ATTRIBUTE)), e);
                corruptedRecords.add(preferenceRecord.getId());
            }
        }
    }
    associatedObject.setUserPreferences(new UserPreferencesImpl(_executor, associatedObject, preferenceStore, recoveredPreferences));
    if (!(associatedObject instanceof PreferencesRoot)) {
        Collection<Class<? extends ConfiguredObject>> childrenCategories = associatedObject.getModel().getChildTypes(associatedObject.getCategoryClass());
        for (Class<? extends ConfiguredObject> childCategory : childrenCategories) {
            Collection<? extends ConfiguredObject> children = associatedObject.getChildren(childCategory);
            for (ConfiguredObject<?> child : children) {
                setUserPreferences(child, objectToRecordMap, preferenceStore, corruptedRecords);
            }
        }
    }
}
Also used : UserPreferencesImpl(org.apache.qpid.server.model.preferences.UserPreferencesImpl) ArrayList(java.util.ArrayList) Preference(org.apache.qpid.server.model.preferences.Preference) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject)

Example 2 with UserPreferencesImpl

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

the class PreferencesTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    final String objectName = getTestName();
    _testObject = _model.getObjectFactory().create(TestSingleton.class, Collections.<String, Object>singletonMap(ConfiguredObject.NAME, objectName), null);
    _preferenceTaskExecutor = new CurrentThreadTaskExecutor();
    _preferenceTaskExecutor.start();
    PreferenceStore preferenceStore = mock(PreferenceStore.class);
    _testObject.setUserPreferences(new UserPreferencesImpl(_preferenceTaskExecutor, _testObject, preferenceStore, Collections.<Preference>emptySet()));
    _testSubject = TestPrincipalUtils.createTestSubject(TEST_USERNAME);
}
Also used : UserPreferencesImpl(org.apache.qpid.server.model.preferences.UserPreferencesImpl) Preference(org.apache.qpid.server.model.preferences.Preference) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore)

Example 3 with UserPreferencesImpl

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

the class RestUserPreferenceHandlerTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    _configuredObject = mock(ConfiguredObject.class);
    _preferenceStore = mock(PreferenceStore.class);
    _preferenceTaskExecutor = new CurrentThreadTaskExecutor();
    _preferenceTaskExecutor.start();
    _userPreferences = new UserPreferencesImpl(_preferenceTaskExecutor, _configuredObject, _preferenceStore, Collections.<Preference>emptyList());
    _subject = TestPrincipalUtils.createTestSubject(MYUSER, MYGROUP);
    _groupPrincipal = _subject.getPrincipals(GroupPrincipal.class).iterator().next();
    _userPrincipal = _subject.getPrincipals(AuthenticatedPrincipal.class).iterator().next();
    when(_configuredObject.getUserPreferences()).thenReturn(_userPreferences);
}
Also used : UserPreferencesImpl(org.apache.qpid.server.model.preferences.UserPreferencesImpl) Preference(org.apache.qpid.server.model.preferences.Preference) GroupPrincipal(org.apache.qpid.server.security.group.GroupPrincipal) CurrentThreadTaskExecutor(org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) PreferenceStore(org.apache.qpid.server.store.preferences.PreferenceStore) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal)

Aggregations

ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)3 Preference (org.apache.qpid.server.model.preferences.Preference)3 UserPreferencesImpl (org.apache.qpid.server.model.preferences.UserPreferencesImpl)3 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)2 PreferenceStore (org.apache.qpid.server.store.preferences.PreferenceStore)2 ArrayList (java.util.ArrayList)1 AuthenticatedPrincipal (org.apache.qpid.server.security.auth.AuthenticatedPrincipal)1 GroupPrincipal (org.apache.qpid.server.security.group.GroupPrincipal)1