Package org.osgi.service.useradmin

Examples of org.osgi.service.useradmin.UserAdmin


    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);
        }
View Full Code Here


    public void testFelix3735_StopRunningStoreRetainsDataOk() throws Exception
    {
        final String userName = "testUser";
        final String groupName = "testGroup";

        UserAdmin userAdmin = awaitService(UserAdmin.class.getName());
        Bundle fileStoreBundle = getFileStoreBundle();
        // Start a suitable storage service...
        fileStoreBundle.start();

        // Fill the user admin with some data...
        User testUser = (User) userAdmin.createRole(userName, Role.USER);
        testUser.getProperties().put("key", "value");

        Group testGroup = (Group) userAdmin.createRole(groupName, Role.GROUP);
        testGroup.addMember(testUser);

        // Stop the file store...
        fileStoreBundle.stop();

        // retrieve the useradmin again...
        userAdmin = awaitService(UserAdmin.class.getName());

        // Verify the user + group are gone (no store available)...
        assertNull(userAdmin.getRole(userName));
        assertNull(userAdmin.getRole(groupName));

        // Start the file store...
        fileStoreBundle.start();

        // Verify the user + group are gone (no store available)...
        User readUser = (User) userAdmin.getRole(userName);
        assertNotNull(readUser);
        assertEquals(userName, readUser.getName());
        assertEquals("value", readUser.getProperties().get("key"));

        Group readGroup = (Group) userAdmin.getRole(groupName);
        assertNotNull(readGroup);
        assertEquals(groupName, readGroup.getName());
        assertEquals(1, readGroup.getMembers().length);
        assertEquals(readUser, readGroup.getMembers()[0]);
    }
View Full Code Here

    public void testFelix3735_StartStoreAfterUserAdminInitializesOk() throws Exception
    {
        final String userName = "anotherTestUser";
        final String groupName = "anotherTestGroup";

        UserAdmin userAdmin = awaitService(UserAdmin.class.getName());
        Bundle fileStoreBundle = getFileStoreBundle();
        // Start a suitable storage service...
        fileStoreBundle.start();

        // Fill the user admin with some data...
        User testUser = (User) userAdmin.createRole(userName, Role.USER);
        testUser.getProperties().put("key", "value");

        Group testGroup = (Group) userAdmin.createRole(groupName, Role.GROUP);
        testGroup.addMember(testUser);

        // Stop the file store...
        fileStoreBundle.stop();

        Bundle userAdminBundle = findBundle(ORG_APACHE_FELIX_USERADMIN);
        assertNotNull(userAdminBundle);
        userAdminBundle.stop();

        // Obtain user admin service again; shouldn't be available...
        userAdmin = getService(UserAdmin.class.getName());
        assertNull(userAdmin);

        userAdminBundle.start();

        // Obtain user admin service again; should be available now...
        userAdmin = awaitService(UserAdmin.class.getName());
        assertNotNull(userAdmin);

        // Verify the user + group are gone (no store available)...
        assertNull(userAdmin.getRole(userName));
        assertNull(userAdmin.getRole(groupName));

        // Start the file store...
        fileStoreBundle.start();

        // Verify the user + group are gone (no store available)...
        User readUser = (User) userAdmin.getRole(userName);
        assertNotNull(readUser);
        assertEquals(userName, readUser.getName());
        assertEquals("value", readUser.getProperties().get("key"));

        Group readGroup = (Group) userAdmin.getRole(groupName);
        assertNotNull(readGroup);
        assertEquals(groupName, readGroup.getName());
        assertEquals(1, readGroup.getMembers().length);
        assertEquals(readUser, readGroup.getMembers()[0]);
    }
View Full Code Here

     * 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();

        Thread.sleep(100); // Wait a little until the bundle is really stopped...

        // 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);
    }
View Full Code Here

     * 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);
        }
    }
View Full Code Here

     * 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());
        }
View Full Code Here

     * 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);
        }
    }
View Full Code Here

     * Tests that removing a role works correctly.
     */
    @Test
    public void testUpdateRoleOk() throws Exception
    {
        UserAdmin ua = getUserAdmin();

        String roleName = "role1";
        Role[] readRoles;

        if (canRunTest())
        {
            User role = (User) ua.createRole(roleName, Role.USER);
            assertNotNull("Collection not empty?!", role);

            readRoles = ua.getRoles(null);

            assertNotNull("No roles stored?!", readRoles);
            assertEquals(1, readRoles.length);

            role.getProperties().put("key", "value");

            Thread.sleep(100); // Wait a little to ensure everything is written...

            readRoles = ua.getRoles("(key=value)");

            assertNotNull("Role not updated?!", readRoles);
            assertEquals(1, readRoles.length);
        }
    }
View Full Code Here

      Class.forName(USER_ADMIN);
      if (reference.isAssignableTo(ctx.getBundle(), USER_ADMIN)) {
        registerMBean(UserAdminMBean.class.getName(), new Factory<UserAdminMBean>() {
          public UserAdminMBean create()
          {
            UserAdmin service = (UserAdmin) ctx.getService(reference);

            if (service == null) return null;
            else return new org.apache.aries.jmx.useradmin.UserAdmin(service);
          }
        }, UserAdminMBean.OBJECTNAME, _userAdminMBeans, reference, USER_ADMIN);
View Full Code Here

     * @param name
     *            the name of the user to create, cannot be <code>null</code>;
     * @return a {@link User} with the given name, or <code>null</code> in case no such user could be created.
     */
    protected final User createUser(String name) {
        UserAdmin useradmin = getService(UserAdmin.class);
        User user = (User) useradmin.createRole(name, Role.USER);
        if (user == null) {
            user = useradmin.getUser("username", name);
        }
        else {
            user.getProperties().put("username", name);
        }
        return user;
View Full Code Here

TOP

Related Classes of org.osgi.service.useradmin.UserAdmin

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.