Search in sources :

Example 61 with Role

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

the class CustomRoleImplTest method testRemoveRolePropertiesYieldsEvent.

/**
 * Tests that changing the properties of a user-role yields an event.
 */
public void testRemoveRolePropertiesYieldsEvent() throws Exception {
    final Role role = m_repository.addRole("testUser", Role.USER);
    role.getProperties().put("key", "value");
    assertNotNull(role);
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

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

Example 62 with Role

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

the class CustomRoleImplTest method testChangePropertiesYieldsEvent.

/**
 * Tests that changing the credentials of a user-role yields an event.
 */
public void testChangePropertiesYieldsEvent() throws Exception {
    final Role role = m_repository.addRole("testUser", Role.USER);
    role.getProperties().put("key", "value1");
    assertNotNull(role);
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            role.getProperties().put("key", "value2");
        }
    }).start();
    assertTrue(m_latch.await(1, TimeUnit.SECONDS));
}
Also used : Role(org.osgi.service.useradmin.Role) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 63 with Role

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

the class CustomRoleImplTest method testAddBasicGroupMemberYieldsEvent.

/**
 * Tests that adding a basic member to a group-role yields an event.
 */
public void testAddBasicGroupMemberYieldsEvent() throws Exception {
    final Group role = (Group) m_repository.addRole("testGroup", Role.GROUP);
    assertNotNull(role);
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            Role anyone = m_repository.getRoleByName(Role.USER_ANYONE);
            assertTrue(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 64 with Role

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

the class CustomRoleImplTest method testRemovingGroupMemberYieldsEvent.

/**
 * Tests that removing a member from a group-role yields an event.
 */
public void testRemovingGroupMemberYieldsEvent() throws Exception {
    final Role anyone = m_repository.getRoleByName(Role.USER_ANYONE);
    final Group role = (Group) m_repository.addRole("testGroup", Role.GROUP);
    assertNotNull(role);
    role.addRequiredMember(anyone);
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

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

Example 65 with Role

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

the class MemoryRoleRepositoryStore method addRole.

public Role addRole(String roleName, int type) throws Exception {
    if (roleName == null) {
        throw new IllegalArgumentException("Name cannot be null!");
    }
    Role role = RoleFactory.createRole(type, roleName);
    Object result = m_entries.putIfAbsent(roleName, role);
    return (result == null) ? role : null;
}
Also used : Role(org.osgi.service.useradmin.Role)

Aggregations

Role (org.osgi.service.useradmin.Role)98 Group (org.osgi.service.useradmin.Group)29 IOException (java.io.IOException)17 CountDownLatch (java.util.concurrent.CountDownLatch)13 List (java.util.List)9 User (org.osgi.service.useradmin.User)9 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)6 Collection (java.util.Collection)5 UserAdmin (org.osgi.service.useradmin.UserAdmin)5 DBCollection (com.mongodb.DBCollection)4 Iterator (java.util.Iterator)4 BackendException (org.apache.felix.useradmin.BackendException)4 ObservableRole (org.apache.felix.useradmin.impl.role.ObservableRole)4 Authorization (org.osgi.service.useradmin.Authorization)4 WriteResult (com.mongodb.WriteResult)3 Filter (org.osgi.framework.Filter)3 BasicDBObject (com.mongodb.BasicDBObject)2 DBObject (com.mongodb.DBObject)2 Dictionary (java.util.Dictionary)2