Package org.osgi.service.useradmin

Examples of org.osgi.service.useradmin.Group


     *
     * @throws IOException
     */
    @Test
    public void testGetMembers() throws IOException {
        Group group1 = Mockito.mock(Group.class);
        Mockito.when(group1.getType()).thenReturn(Role.GROUP);
        Mockito.when(group1.getName()).thenReturn("group1");
        User user1 = Mockito.mock(Group.class);
        Mockito.when(user1.getName()).thenReturn("user1");
        Mockito.when(group1.getMembers()).thenReturn(new Role[] { user1 });
        Mockito.when(userAdmin.getRole("group1")).thenReturn(group1);
        String[] members = mbean.getMembers("group1");
        Assert.assertArrayEquals(new String[] { "user1" }, members);
    }
View Full Code Here


     *
     * @throws IOException
     */
    @Test
    public void testGetRequiredMembers() throws IOException {
        Group group1 = Mockito.mock(Group.class);
        Mockito.when(group1.getType()).thenReturn(Role.GROUP);
        Mockito.when(group1.getName()).thenReturn("group1");
        User user1 = Mockito.mock(Group.class);
        Mockito.when(user1.getName()).thenReturn("user1");
        Mockito.when(group1.getRequiredMembers()).thenReturn(new Role[] { user1 });
        Mockito.when(userAdmin.getRole("group1")).thenReturn(group1);
        String[] members = mbean.getRequiredMembers("group1");
        Assert.assertArrayEquals(new String[] { "user1" }, members);
    }
View Full Code Here

     *
     * @throws Exception
     */
    @Test
    public void testListGroups() throws Exception {
        Group group1 = Mockito.mock(Group.class);
        Mockito.when(group1.getType()).thenReturn(Role.GROUP);
        Mockito.when(group1.getName()).thenReturn("group1");
        Group group2 = Mockito.mock(Group.class);
        Mockito.when(group2.getType()).thenReturn(Role.GROUP);
        Mockito.when(group2.getName()).thenReturn("group2");
        Mockito.when(userAdmin.getRoles(null)).thenReturn(new Role[] { group1, group2 });
        String[] groups = mbean.listGroups();
        Assert.assertArrayEquals(new String[] { "group1", "group2" }, groups);
    }
View Full Code Here

     *
     * @throws IOException
     */
    @Test
    public void testRemoveMember() throws IOException {
        Group group1 = Mockito.mock(Group.class);
        User user1 = Mockito.mock(User.class);
        Mockito.when(userAdmin.getRole("group1")).thenReturn(group1);
        Mockito.when(userAdmin.getRole("user1")).thenReturn(user1);
        Mockito.when(group1.getType()).thenReturn(Role.GROUP);
        Mockito.when(group1.removeMember(user1)).thenReturn(true);
        boolean isAdded = mbean.removeMember("group1", "user1");
        Assert.assertTrue(isAdded);
        Mockito.verify(group1).removeMember(user1);
    }
View Full Code Here

  private void removeRoleFromAllGroups(Role removedRole) {
        try {
            Role[] roles = m_store.getRoles(null);
            for (int i = 0; i < roles.length; i++) {
                if (roles[i].getType() == Role.GROUP) {
                  Group group = (Group) roles[i];
                  // Don't check whether the given role is actually a member
                  // of the group, but let the group itself figure this out...
                  group.removeMember(removedRole);
                }
            }
        }
        catch (Exception e) {
            throw new BackendException("Failed to get all roles!", e);
View Full Code Here

        }
        for (Group g : memberOf(r)) {
            g.removeMember(r);
        }
        for (String groupName : role.getMemberOf()) {
            Group g = (Group) m_userAdmin.getRole(groupName);
            if (g == null) {
                m_log.log(LogService.LOG_WARNING, "Cannot add user " + role.getName() + " to group " + groupName + ", because the group does not exist.");
                continue;
            }
            g.addMember(r);
        }
    }
View Full Code Here

        if (username == null || "".equals(username) || password == null || "".equals(password) || groupname == null || "".equals(groupname)) {
            throw new IllegalArgumentException("Username, password and groupname cannot be null or \"\"");
        }

        Group group = (Group) m_useradmin.getRole(groupname);
        if (group == null) {
            throw new GroupNotFoundException(groupname);
        }

        Role newRole = m_useradmin.createRole(username, Role.USER);
        if (newRole == null) {
            throw new UserAlreadyExistsException(username);
        }

        User newUser = (User) newRole;
        newUser.getProperties().put("username", username);
        newUser.getCredentials().put("password", password);
        group.addMember(newUser);
    }
View Full Code Here

        User user = getUser(username);
        if (user == null) {
            throw new UserNotFoundException(username);
        }

        Group oldGroup = (Group) m_useradmin.getRole(userDTO.getPreviousGroupname());
        if (oldGroup == null) {
            throw new GroupNotFoundException(group);
        }

        Group newGroup = (Group) m_useradmin.getRole(group);
        if (newGroup == null) {
            throw new GroupNotFoundException(group);
        }

        oldGroup.removeMember(user);
        newGroup.addMember(user);
    }
View Full Code Here

        }
        User user = getUser(oldUsername);
        if (user == null) {
            throw new UserNotFoundException(oldUsername);
        }
        Group group = getGroup(user);
        if (group == null) {
            throw new GroupNotFoundException(null);
        }

        group.removeMember(user);
        m_useradmin.removeRole(user.getName());

        User newUser = (User) m_useradmin.createRole(newUsername, Role.USER);
        newUser.getProperties().put("username", newUsername);
        newUser.getCredentials().put("password", userDTO.getPassword());

        group.addMember(newUser);
    }
View Full Code Here

        String[] roles = auth.getRoles();
        if (roles != null) {
            for (String role : roles) {
                Role result = m_useradmin.getRole(role);
                if (result.getType() == Role.GROUP) {
                    Group group = (Group) result;
                    Role[] members = group.getMembers();
                    if (members != null) {
                        for (Role r : members) {
                            if (r.getType() == Role.USER && r.getName().equals(user.getName())) {
                                return group;
                            }
View Full Code Here

TOP

Related Classes of org.osgi.service.useradmin.Group

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.