Search in sources :

Example 21 with Group

use of org.osgi.service.useradmin.Group in project aries by apache.

the class UserAdmin method addMember.

/**
 * @see org.osgi.jmx.service.useradmin.UserAdminMBean#addMember(java.lang.String, java.lang.String)
 */
public boolean addMember(String groupname, String rolename) throws IOException {
    if (groupname == null) {
        throw new IOException("Group name cannot be null");
    }
    if (rolename == null) {
        throw new IOException("Role name cannot be null");
    }
    Role group = userAdmin.getRole(groupname);
    Role member = userAdmin.getRole(rolename);
    if (group == null) {
        throw new IOException("Operation fails role with provided groupname = [" + groupname + "] doesn't exist");
    }
    validateRoleType(group, Role.GROUP);
    return ((Group) group).addMember(member);
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group) IOException(java.io.IOException)

Example 22 with Group

use of org.osgi.service.useradmin.Group in project aries by apache.

the class UserAdminTest method testRemoveMember.

/**
 * Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#removeMember(java.lang.String, java.lang.String)}
 * .
 *
 * @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);
}
Also used : Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User) Test(org.junit.Test)

Example 23 with Group

use of org.osgi.service.useradmin.Group in project aries by apache.

the class UserAdminTest method testAddMember.

/**
 * Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#addMember(java.lang.String, java.lang.String)}.
 *
 * @throws IOException
 */
@Test
public void testAddMember() 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.addMember(user1)).thenReturn(true);
    boolean isAdded = mbean.addMember("group1", "user1");
    Assert.assertTrue(isAdded);
    Mockito.verify(group1).addMember(user1);
}
Also used : Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User) Test(org.junit.Test)

Example 24 with Group

use of org.osgi.service.useradmin.Group in project felix by apache.

the class RoleRepositorySerializer method addGroups.

/**
 * Adds all groups, based on the given stub groups.
 *
 * @param repository the repository to add the groups to, cannot be <code>null</code>;
 * @param stubGroups the list with stub groups to replace, cannot be <code>null</code>.
 * @throws IOException in case a referenced role was not found in the repository.
 */
private void addGroups(Map repository, List stubGroups) throws IOException {
    // First create "empty" groups in the repository; we'll fill them in later on...
    Iterator sgIter = stubGroups.iterator();
    while (sgIter.hasNext()) {
        StubGroupImpl stubGroup = (StubGroupImpl) sgIter.next();
        Group group = (Group) RoleFactory.createRole(Role.GROUP, stubGroup.getName());
        copyDictionary(stubGroup.getProperties(), group.getProperties());
        copyDictionary(stubGroup.getCredentials(), group.getCredentials());
        repository.put(group.getName(), group);
    }
    int origSize = stubGroups.size();
    while (!stubGroups.isEmpty()) {
        List copy = new ArrayList(stubGroups);
        int size = copy.size();
        for (int i = 0; i < size; i++) {
            StubGroupImpl stubGroup = (StubGroupImpl) copy.get(i);
            Group group = (Group) repository.get(stubGroup.getName());
            if (group != null) {
                resolveGroupMembers(stubGroup, group, repository);
                stubGroups.remove(stubGroup);
            }
        }
        // In case we didn't resolve any groups; we should fail...
        if (origSize == stubGroups.size()) {
            throw new IOException("Failed to resolve groups: " + stubGroups);
        }
        origSize = stubGroups.size();
    }
}
Also used : Group(org.osgi.service.useradmin.Group) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException)

Example 25 with Group

use of org.osgi.service.useradmin.Group in project felix by apache.

the class RoleRepositoryFileStorePerformanceTest method createGroup.

private Group createGroup(int idx) {
    String name = "Group" + idx;
    Group result = RoleFactory.createGroup(name);
    setCredentials(result);
    setProperties(result);
    return result;
}
Also used : Group(org.osgi.service.useradmin.Group)

Aggregations

Group (org.osgi.service.useradmin.Group)63 User (org.osgi.service.useradmin.User)32 Role (org.osgi.service.useradmin.Role)29 Test (org.junit.Test)11 IOException (java.io.IOException)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 Authorization (org.osgi.service.useradmin.Authorization)5 Bundle (org.osgi.framework.Bundle)3 UserAdmin (org.osgi.service.useradmin.UserAdmin)3 BasicDBObject (com.mongodb.BasicDBObject)2 GroupData (org.apache.aries.jmx.codec.GroupData)2 PrintWriter (java.io.PrintWriter)1 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CompositeData (javax.management.openmbean.CompositeData)1 ServletException (javax.servlet.ServletException)1 BackendException (org.apache.felix.useradmin.BackendException)1