use of org.apache.qpid.server.model.Group in project qpid-broker-j by apache.
the class FileBasedGroupProviderImplTest method testRemoveGroupAndMember.
public void testRemoveGroupAndMember() throws Exception {
Map<String, Set<String>> input = new HashMap<>();
input.put("supers", Sets.newHashSet("root"));
input.put("operators", Sets.newHashSet("operator", "root"));
_groupFile = createTemporaryGroupFile(input);
Map<String, Object> providerAttrs = new HashMap<>();
String groupsFile = _groupFile.getAbsolutePath();
providerAttrs.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
providerAttrs.put(FileBasedGroupProvider.PATH, groupsFile);
providerAttrs.put(FileBasedGroupProvider.NAME, getTestName());
@SuppressWarnings("unchecked") GroupProvider<?> provider = _objectFactory.create(GroupProvider.class, providerAttrs, _broker);
assertThat(provider.getChildren(Group.class).size(), is(equalTo(2)));
Group operators = provider.getChildByName(Group.class, "operators");
GroupMember rootMember = (GroupMember) operators.getChildByName(GroupMember.class, "root");
rootMember.delete();
assertThat(operators.getChildren(GroupMember.class).size(), is(equalTo(1)));
Group supers = provider.getChildByName(Group.class, "supers");
assertThat(supers.getChildren(GroupMember.class).size(), is(equalTo(1)));
operators.delete();
assertThat(provider.getChildren(Group.class).size(), is(equalTo(1)));
}
use of org.apache.qpid.server.model.Group in project qpid-broker-j by apache.
the class FileBasedGroupProviderImpl method onOpen.
@Override
protected void onOpen() {
super.onOpen();
FileGroupDatabase groupDatabase = new FileGroupDatabase();
try {
groupDatabase.setGroupFile(getPath());
} catch (IOException | RuntimeException e) {
if (e instanceof IllegalConfigurationException) {
throw (IllegalConfigurationException) e;
}
throw new IllegalConfigurationException(String.format("Cannot load groups from '%s'", getPath()), e);
}
_groupDatabase = groupDatabase;
Set<Principal> groups = getGroupPrincipals();
Collection<Group> principals = new ArrayList<>(groups.size());
for (Principal group : groups) {
Map<String, Object> attrMap = new HashMap<String, Object>();
UUID id = UUID.randomUUID();
attrMap.put(ConfiguredObject.ID, id);
attrMap.put(ConfiguredObject.NAME, group.getName());
GroupAdapter groupAdapter = new GroupAdapter(attrMap);
principals.add(groupAdapter);
groupAdapter.registerWithParents();
// TODO - we know this is safe, but the sync method shouldn't really be called from the management thread
groupAdapter.openAsync();
}
}
use of org.apache.qpid.server.model.Group in project qpid-broker-j by apache.
the class FileBasedGroupProviderImplTest method testAddGroupAndMember.
public void testAddGroupAndMember() throws Exception {
_groupFile = createTemporaryGroupFile(Collections.emptyMap());
Map<String, Object> providerAttrs = new HashMap<>();
String groupsFile = _groupFile.getAbsolutePath();
providerAttrs.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
providerAttrs.put(FileBasedGroupProvider.PATH, groupsFile);
providerAttrs.put(FileBasedGroupProvider.NAME, getTestName());
@SuppressWarnings("unchecked") GroupProvider<?> provider = _objectFactory.create(GroupProvider.class, providerAttrs, _broker);
assertThat(provider.getChildren(Group.class).size(), is(equalTo(0)));
final Map<String, Object> groupAttrs = Collections.singletonMap(Group.NAME, "supers");
Group superGroup = provider.createChild(Group.class, groupAttrs);
assertThat(superGroup.getName(), is(equalTo("supers")));
final Map<String, Object> memberAttrs = Collections.singletonMap(GroupMember.NAME, "root");
GroupMember rootMember = (GroupMember) superGroup.createChild(GroupMember.class, memberAttrs);
assertThat(rootMember.getName(), is(equalTo("root")));
}
use of org.apache.qpid.server.model.Group in project qpid-broker-j by apache.
the class FileBasedGroupProviderImplTest method testExistingGroupFile.
public void testExistingGroupFile() throws Exception {
Map<String, Set<String>> input = new HashMap<>();
input.put("super", Sets.newHashSet("root"));
_groupFile = createTemporaryGroupFile(input);
Map<String, Object> providerAttrs = new HashMap<>();
String groupsFile = _groupFile.getAbsolutePath();
providerAttrs.put(FileBasedGroupProvider.TYPE, GROUP_FILE_PROVIDER_TYPE);
providerAttrs.put(FileBasedGroupProvider.PATH, groupsFile);
providerAttrs.put(FileBasedGroupProvider.NAME, getTestName());
@SuppressWarnings("unchecked") GroupProvider<?> provider = _objectFactory.create(GroupProvider.class, providerAttrs, _broker);
Set<Principal> adminGroups = provider.getGroupPrincipalsForUser(() -> "root");
assertThat("root has unexpected group membership", adminGroups.stream().map(Principal::getName).collect(Collectors.toSet()), containsInAnyOrder("super"));
Collection<Group> groups = provider.getChildren(Group.class);
assertThat(groups.size(), is(equalTo(1)));
Group<?> superGroup = groups.iterator().next();
assertThat(superGroup.getName(), is(equalTo("super")));
Collection<GroupMember> members = superGroup.getChildren(GroupMember.class);
assertThat(members.size(), is(equalTo(1)));
GroupMember rootMember = members.iterator().next();
assertThat(rootMember.getName(), is(equalTo("root")));
}
use of org.apache.qpid.server.model.Group in project qpid-broker-j by apache.
the class FileBasedGroupProviderImplTest method createTemporaryGroupFile.
private File createTemporaryGroupFile(Map<String, Set<String>> groups) throws Exception {
File groupFile = File.createTempFile("group", "grp");
groupFile.deleteOnExit();
Properties props = new Properties();
Map<String, String> m = groups.entrySet().stream().collect(Collectors.toMap(e -> e.getKey() + ".users", e -> e.getValue().stream().collect(Collectors.joining(","))));
props.putAll(m);
try (final FileOutputStream out = new FileOutputStream(groupFile)) {
props.store(out, "test group file");
}
return groupFile;
}
Aggregations