use of org.apache.qpid.server.security.group.FileGroupDatabase in project qpid-broker-j by apache.
the class FileBasedGroupProviderImpl method validateOnCreate.
@Override
protected void validateOnCreate() {
super.validateOnCreate();
File groupsFile = new File(_path);
if (groupsFile.exists()) {
if (!groupsFile.canRead()) {
throw new IllegalConfigurationException(String.format("Cannot read groups file '%s'. Please check permissions.", _path));
}
FileGroupDatabase groupDatabase = new FileGroupDatabase();
try {
groupDatabase.setGroupFile(_path);
} catch (Exception e) {
throw new IllegalConfigurationException(String.format("Cannot load groups from '%s'", _path), e);
}
}
}
use of org.apache.qpid.server.security.group.FileGroupDatabase in project qpid-broker-j by apache.
the class FileGroupDatabaseTest method testCreateGroupPersistedToFile.
public void testCreateGroupPersistedToFile() throws Exception {
writeAndSetGroupFile();
Set<String> groups = _groupDatabase.getAllGroups();
assertEquals(0, groups.size());
_groupDatabase.createGroup(MY_GROUP);
groups = _groupDatabase.getAllGroups();
assertEquals(1, groups.size());
assertTrue(groups.contains(MY_GROUP));
FileGroupDatabase newGroupDatabase = new FileGroupDatabase();
newGroupDatabase.setGroupFile(_groupFile);
Set<String> newGroups = newGroupDatabase.getAllGroups();
assertEquals(1, newGroups.size());
assertTrue(newGroups.contains(MY_GROUP));
}
use of org.apache.qpid.server.security.group.FileGroupDatabase in project qpid-broker-j by apache.
the class FileGroupDatabaseTest method testRemoveUserPersistedToFile.
public void testRemoveUserPersistedToFile() throws Exception {
writeAndSetGroupFile("myGroup.users", "user1,user2");
Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
assertEquals(2, users.size());
_groupDatabase.removeUserFromGroup(USER2, MY_GROUP);
assertEquals(1, users.size());
FileGroupDatabase newGroupDatabase = new FileGroupDatabase();
newGroupDatabase.setGroupFile(_groupFile);
Set<String> newUsers = newGroupDatabase.getUsersInGroup(MY_GROUP);
assertEquals(users.size(), newUsers.size());
}
use of org.apache.qpid.server.security.group.FileGroupDatabase 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.security.group.FileGroupDatabase in project qpid-broker-j by apache.
the class FileGroupDatabaseTest method testAddUserPersistedToFile.
public void testAddUserPersistedToFile() throws Exception {
writeAndSetGroupFile("myGroup.users", "user1,user2");
Set<String> users = _groupDatabase.getUsersInGroup(MY_GROUP);
assertEquals(2, users.size());
_groupDatabase.addUserToGroup(USER3, MY_GROUP);
assertEquals(3, users.size());
FileGroupDatabase newGroupDatabase = new FileGroupDatabase();
newGroupDatabase.setGroupFile(_groupFile);
Set<String> newUsers = newGroupDatabase.getUsersInGroup(MY_GROUP);
assertEquals(users.size(), newUsers.size());
}
Aggregations