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);
}
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());
}
}
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);
}
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);
}
}
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);
}
}
Aggregations