Search in sources :

Example 11 with Group

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

the class RoleRepositoryTest method testAddRequiredRoleYieldsEventOk.

/**
 * Tests whether adding a new role to a group causes an event to be emitted to the {@link RoleRepository}.
 */
public void testAddRequiredRoleYieldsEventOk() throws Exception {
    final Group role = (Group) m_roleRepository.addRole("foo", Role.GROUP);
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            Role anyone = m_roleRepository.getRoleByName(Role.USER_ANYONE);
            role.addRequiredMember(anyone);
        }
    }).start();
    assertTrue(m_latch.await(1, TimeUnit.SECONDS));
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 12 with Group

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

the class RoleRepositoryTest method testRemoveBasicRoleYieldsEventOk.

/**
 * Tests whether removing a role from a group causes an event to be emitted to the {@link RoleRepository}.
 */
public void testRemoveBasicRoleYieldsEventOk() throws Exception {
    final Role anyone = m_roleRepository.getRoleByName(Role.USER_ANYONE);
    final Group role = (Group) m_roleRepository.addRole("bar", Role.GROUP);
    role.addMember(anyone);
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            role.removeMember(anyone);
        }
    }).start();
    assertTrue(m_latch.await(1, TimeUnit.SECONDS));
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 13 with Group

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

the class RoleRepositoryTest method testRemoveRequiredRoleYieldsEventOk.

/**
 * Tests whether removing a role from a group causes an event to be emitted to the {@link RoleRepository}.
 */
public void testRemoveRequiredRoleYieldsEventOk() throws Exception {
    final Role anyone = m_roleRepository.getRoleByName(Role.USER_ANYONE);
    final Group role = (Group) m_roleRepository.addRole("bar", Role.GROUP);
    role.addRequiredMember(anyone);
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            role.removeMember(anyone);
        }
    }).start();
    assertTrue(m_latch.await(1, TimeUnit.SECONDS));
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 14 with Group

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

the class RoleRepositoryTest method testAddBasicRoleYieldsEventOk.

/**
 * Tests whether adding a new role to a group causes an event to be emitted to the {@link RoleRepository}.
 */
public void testAddBasicRoleYieldsEventOk() throws Exception {
    final Group role = (Group) m_roleRepository.addRole("foo", Role.GROUP);
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            Role anyone = m_roleRepository.getRoleByName(Role.USER_ANYONE);
            role.addMember(anyone);
        }
    }).start();
    assertTrue(m_latch.await(1, TimeUnit.SECONDS));
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 15 with Group

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

the class UserAdminImplTest method testRemovingGroupMemberOk.

/**
 * Tests that removing a basic member from a group works.
 */
public void testRemovingGroupMemberOk() {
    User user1 = (User) m_userAdmin.createRole("user1", Role.USER);
    Group group1 = (Group) m_userAdmin.createRole("group1", Role.GROUP);
    assertTrue(group1.addMember(user1));
    assertTrue(group1.removeMember(user1));
    assertFalse(group1.removeMember(user1));
}
Also used : Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User)

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