Search in sources :

Example 1 with UserAdmin

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

the class FileStoreInitializationTest method testStoreIsInitializedAndClosedProperlyOk.

/**
 * Tests that initialization and closing of the repository store is
 * performed correctly.
 */
@Test
public void testStoreIsInitializedAndClosedProperlyOk() throws Exception {
    UserAdmin ua = getUserAdmin();
    // Start the file store bundle...
    Bundle fileStoreBundle = getFileStoreBundle();
    fileStoreBundle.start();
    // Create two roles...
    User user = (User) ua.createRole("user1", Role.USER);
    assertNotNull(user);
    Group group = (Group) ua.createRole("group1", Role.GROUP);
    assertNotNull(group);
    group.addMember(user);
    group.addRequiredMember(ua.getRole(Role.USER_ANYONE));
    // Stop the file store; should persist the two roles...
    fileStoreBundle.stop();
    // Wait a little until the bundle is really stopped...
    Thread.sleep(100);
    // Retrieve the roles again; should both yield null due to the store not being available...
    user = (User) ua.getRole("user1");
    assertNull(user);
    group = (Group) ua.getRole("group1");
    assertNull(group);
    // This will not succeed: no backend to store the user in...
    assertNull(ua.createRole("user2", Role.USER));
    fileStoreBundle.start();
    awaitService(ORG_APACHE_FELIX_USERADMIN_FILESTORE);
    // Retrieve the roles again; should both yield valid values...
    user = (User) ua.getRole("user1");
    assertNotNull(user);
    group = (Group) ua.getRole("group1");
    assertNotNull(group);
    Role[] members = group.getMembers();
    assertNotNull(members);
    assertEquals(1, members.length);
    assertEquals("user1", members[0].getName());
    members = group.getRequiredMembers();
    assertNotNull(members);
    assertEquals(1, members.length);
    assertEquals(Role.USER_ANYONE, members[0].getName());
    user = (User) ua.getRole("user2");
    assertNull(user);
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User) UserAdmin(org.osgi.service.useradmin.UserAdmin) Bundle(org.osgi.framework.Bundle) Test(org.junit.Test)

Example 2 with UserAdmin

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

the class MongoDBStoreTest method testFelix4400_CreateRoleReturnsNonNullOk.

/**
 * Tests that creating a new role returns the actual created role.
 */
@Test
public void testFelix4400_CreateRoleReturnsNonNullOk() throws Exception {
    UserAdmin ua = getUserAdmin();
    String roleName = "newRole";
    if (canRunTest()) {
        Role newRole = ua.createRole(roleName, Role.USER);
        assertNotNull("Felix-4400 not resolved?!", newRole);
        assertEquals("Names not equal?!", roleName, newRole.getName());
        assertEquals("Types not equal?!", Role.USER, newRole.getType());
    }
}
Also used : Role(org.osgi.service.useradmin.Role) UserAdmin(org.osgi.service.useradmin.UserAdmin) Test(org.junit.Test)

Example 3 with UserAdmin

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

the class Activator method addingService.

/**
 * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
 */
public final Object addingService(ServiceReference reference) {
    SimpleWebConsolePlugin plugin = this.plugin;
    if (plugin == null) {
        final UserAdmin service = (UserAdmin) context.getService(reference);
        this.plugin = new WebConsolePlugin(service).register(context);
    // printerRegistration = context.registerService(ConfigurationPrinter.SERVICE,
    // new ComponentConfigurationPrinter(service), null);
    }
    return context.getService(reference);
}
Also used : UserAdmin(org.osgi.service.useradmin.UserAdmin) SimpleWebConsolePlugin(org.apache.felix.webconsole.SimpleWebConsolePlugin) SimpleWebConsolePlugin(org.apache.felix.webconsole.SimpleWebConsolePlugin)

Example 4 with UserAdmin

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

the class MongoDBStoreTest method testFelix4399_FetchEmptyRoleOk.

/**
 * Tests that fetching an empty role without properties or other roles does not cause a NPE.
 */
@Test
public void testFelix4399_FetchEmptyRoleOk() throws Exception {
    UserAdmin ua = getUserAdmin();
    String roleName = "emptyRole";
    if (canRunTest()) {
        Role emptyRole = ua.createRole(roleName, Role.USER);
        assertNotNull("Collection not empty?!", emptyRole);
        Role readRole = ua.getRole(roleName);
        assertNotNull("Unable to read back created empty role?!", readRole);
        assertEquals("Names not equal?!", emptyRole.getName(), readRole.getName());
        assertEquals("Types not equal?!", emptyRole.getType(), readRole.getType());
        Role[] readRoles = ua.getRoles(null);
        assertNotNull("Unable to read back created empty role?!", readRoles);
        assertEquals(1, readRoles.length);
    }
}
Also used : Role(org.osgi.service.useradmin.Role) UserAdmin(org.osgi.service.useradmin.UserAdmin) Test(org.junit.Test)

Example 5 with UserAdmin

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

the class MongoDBStoreTest method testRemoveRoleOk.

/**
 * Tests that removing a role works correctly.
 */
@Test
public void testRemoveRoleOk() throws Exception {
    UserAdmin ua = getUserAdmin();
    String roleName = "newRole";
    Role[] readRoles;
    if (canRunTest()) {
        Role role = ua.createRole(roleName, Role.USER);
        assertNotNull("Collection not empty?!", role);
        readRoles = ua.getRoles(null);
        assertNotNull("No roles stored?!", readRoles);
        assertEquals(1, readRoles.length);
        ua.removeRole(roleName);
        readRoles = ua.getRoles(null);
        assertNull("Still roles stored?!", readRoles);
    }
}
Also used : Role(org.osgi.service.useradmin.Role) UserAdmin(org.osgi.service.useradmin.UserAdmin) Test(org.junit.Test)

Aggregations

UserAdmin (org.osgi.service.useradmin.UserAdmin)9 Test (org.junit.Test)7 Role (org.osgi.service.useradmin.Role)5 User (org.osgi.service.useradmin.User)4 Bundle (org.osgi.framework.Bundle)3 Group (org.osgi.service.useradmin.Group)3 Hashtable (java.util.Hashtable)1 SimpleWebConsolePlugin (org.apache.felix.webconsole.SimpleWebConsolePlugin)1 ServiceReference (org.osgi.framework.ServiceReference)1 Event (org.osgi.service.event.Event)1 EventAdmin (org.osgi.service.event.EventAdmin)1 UserAdminEvent (org.osgi.service.useradmin.UserAdminEvent)1