Search in sources :

Example 1 with FileGroupDatabase

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);
        }
    }
}
Also used : FileGroupDatabase(org.apache.qpid.server.security.group.FileGroupDatabase) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) File(java.io.File) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException)

Example 2 with FileGroupDatabase

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));
}
Also used : FileGroupDatabase(org.apache.qpid.server.security.group.FileGroupDatabase)

Example 3 with FileGroupDatabase

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());
}
Also used : FileGroupDatabase(org.apache.qpid.server.security.group.FileGroupDatabase)

Example 4 with FileGroupDatabase

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();
    }
}
Also used : Group(org.apache.qpid.server.model.Group) HashMap(java.util.HashMap) FileGroupDatabase(org.apache.qpid.server.security.group.FileGroupDatabase) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) UUID(java.util.UUID) GroupPrincipal(org.apache.qpid.server.security.group.GroupPrincipal) Principal(java.security.Principal)

Example 5 with FileGroupDatabase

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());
}
Also used : FileGroupDatabase(org.apache.qpid.server.security.group.FileGroupDatabase)

Aggregations

FileGroupDatabase (org.apache.qpid.server.security.group.FileGroupDatabase)6 IOException (java.io.IOException)2 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)2 File (java.io.File)1 Principal (java.security.Principal)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 Group (org.apache.qpid.server.model.Group)1 GroupPrincipal (org.apache.qpid.server.security.group.GroupPrincipal)1