Search in sources :

Example 1 with GroupMember

use of org.apache.qpid.server.model.GroupMember 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)));
}
Also used : Group(org.apache.qpid.server.model.Group) GroupMember(org.apache.qpid.server.model.GroupMember) Set(java.util.Set) HashMap(java.util.HashMap)

Example 2 with GroupMember

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

the class MessagingACLTest method createGroupProvider.

private void createGroupProvider(final String groupName, final String... groupMembers) throws Exception {
    String groupProviderName = "groups";
    Connection connection = getConnectionBuilder().setVirtualHost("$management").build();
    try {
        connection.start();
        createEntity(groupProviderName, GroupProviderImpl.class.getName(), Collections.emptyMap(), connection);
        createEntity(groupName, Group.class.getName(), Collections.singletonMap("object-path", groupProviderName), connection);
        for (String groupMember : groupMembers) {
            createEntity(groupMember, GroupMember.class.getName(), Collections.singletonMap("object-path", groupProviderName + "/" + groupName), connection);
        }
    } finally {
        connection.close();
    }
}
Also used : GroupProviderImpl(org.apache.qpid.server.security.group.GroupProviderImpl) Group(org.apache.qpid.server.model.Group) GroupMember(org.apache.qpid.server.model.GroupMember) Connection(javax.jms.Connection)

Example 3 with GroupMember

use of org.apache.qpid.server.model.GroupMember 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")));
}
Also used : Group(org.apache.qpid.server.model.Group) GroupMember(org.apache.qpid.server.model.GroupMember) HashMap(java.util.HashMap)

Example 4 with GroupMember

use of org.apache.qpid.server.model.GroupMember 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")));
}
Also used : Group(org.apache.qpid.server.model.Group) GroupMember(org.apache.qpid.server.model.GroupMember) Set(java.util.Set) HashMap(java.util.HashMap) Principal(java.security.Principal)

Aggregations

Group (org.apache.qpid.server.model.Group)4 GroupMember (org.apache.qpid.server.model.GroupMember)4 HashMap (java.util.HashMap)3 Set (java.util.Set)2 Principal (java.security.Principal)1 Connection (javax.jms.Connection)1 GroupProviderImpl (org.apache.qpid.server.security.group.GroupProviderImpl)1