Search in sources :

Example 71 with Role

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

the class RoleRepositoryTest method testChangeRolePropertyYieldsEventOk.

/**
 * Tests whether changing an existing property to a role causes an event to be emitted to the {@link RoleRepository}.
 */
public void testChangeRolePropertyYieldsEventOk() throws Exception {
    final Role role = m_roleRepository.addRole("john.doe", Role.USER);
    role.getProperties().put("key", "value");
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

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

Example 72 with Role

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

the class RoleRepositoryTest method testAddRolePropertyYieldsEventOk.

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

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

Example 73 with Role

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

the class RoleRepositoryTest method testGetUserAnyoneRoleByName.

/**
 * Test method for {@link org.apache.felix.useradmin.impl.RoleRepository#getRoleByName(java.lang.String)}.
 */
public void testGetUserAnyoneRoleByName() {
    Role anyone = m_roleRepository.getRoleByName(Role.USER_ANYONE);
    assertEquals(Role.USER_ANYONE, anyone.getName());
    assertEquals(Role.ROLE, anyone.getType());
}
Also used : Role(org.osgi.service.useradmin.Role)

Example 74 with Role

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

the class UserAdminImplTest method testGetRolesWithFilterOk.

/**
 * Tests that getting multiple roles based on a OSGi-filter works and yields the correct result.
 */
public void testGetRolesWithFilterOk() throws Exception {
    Role user1 = m_userAdmin.createRole("user1", Role.USER);
    user1.getProperties().put("key", "value1");
    Role user2 = m_userAdmin.createRole("user2", Role.USER);
    user2.getProperties().put("key", "value2");
    Role group1 = m_userAdmin.createRole("group1", Role.GROUP);
    group1.getProperties().put("key", "value3");
    Role group2 = m_userAdmin.createRole("group2", Role.GROUP);
    group2.getProperties().put("key", "otherValue3");
    Role[] roles = m_userAdmin.getRoles("(key=value*)");
    assertNotNull(roles);
    assertEquals(3, roles.length);
    List roleList = Arrays.asList(roles);
    assertTrue(roleList.contains(user1));
    assertTrue(roleList.contains(user2));
    assertTrue(roleList.contains(group1));
}
Also used : Role(org.osgi.service.useradmin.Role) List(java.util.List)

Example 75 with Role

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

the class UserAdminImplTest method testAddRolePropertyOfInvalidTypeFail.

/**
 * Tests that adding a property of an invalid type to a role does not work and yields an exception.
 */
public void testAddRolePropertyOfInvalidTypeFail() {
    Role user1 = m_userAdmin.createRole("user1", Role.USER);
    try {
        user1.getProperties().put("key", Integer.valueOf(1));
        fail("Expected IllegalArgumentException!");
    } catch (IllegalArgumentException e) {
    // Ok; expected
    }
}
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