use of org.osgi.service.useradmin.UserAdmin in project felix by apache.
the class MongoDBStoreTest method testUpdateRoleOk.
/**
* 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");
// Wait a little to ensure everything is written...
Thread.sleep(100);
readRoles = ua.getRoles("(key=value)");
assertNotNull("Role not updated?!", readRoles);
assertEquals(1, readRoles.length);
}
}
use of org.osgi.service.useradmin.UserAdmin in project felix by apache.
the class UserAdminIntegrationTest method testFelix3735_StopRunningStoreRetainsDataOk.
/**
* Tests that stopping a filled store and starting it again will cause it to
* properly restore its state.
*/
@Test
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]);
}
use of org.osgi.service.useradmin.UserAdmin in project felix by apache.
the class UserAdminIntegrationTest method testFelix3735_StartStoreAfterUserAdminInitializesOk.
/**
* Tests that starting the file store <em>after</em> the user admin service
* is started will cause it to be properly initialized.
*/
@Test
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]);
}
use of org.osgi.service.useradmin.UserAdmin in project felix by apache.
the class UserAdminEventToEventAdminBridge method roleChanged.
public void roleChanged(final UserAdminEvent event) {
final ServiceReference ref = m_context.getServiceReference(EventAdmin.class.getName());
if (null != ref) {
final EventAdmin eventAdmin = (EventAdmin) m_context.getService(ref);
if (null != eventAdmin) {
final String topic;
switch(event.getType()) {
case UserAdminEvent.ROLE_CHANGED:
topic = "org/osgi/service/useradmin/UserAdmin/ROLE_CHANGED";
break;
case UserAdminEvent.ROLE_CREATED:
topic = "org/osgi/service/useradmin/UserAdmin/ROLE_CREATED";
break;
case UserAdminEvent.ROLE_REMOVED:
topic = "org/osgi/service/useradmin/UserAdmin/ROLE_REMOVED";
break;
default:
m_context.ungetService(ref);
return;
}
final Hashtable properties = new Hashtable();
properties.put(EventConstants.EVENT, event);
properties.put("role", event.getRole());
properties.put("role.name", event.getRole().getName());
properties.put("role.type", new Integer(event.getRole().getType()));
final ServiceReference eventRef = event.getServiceReference();
if (null == eventRef) {
throw new IllegalArgumentException("UserAdminEvent.getServiceReference() may not be null");
}
properties.put(EventConstants.SERVICE, eventRef);
properties.put(EventConstants.SERVICE_ID, eventRef.getProperty(EventConstants.SERVICE_ID));
final Object objectClass = eventRef.getProperty(Constants.OBJECTCLASS);
if (!(objectClass instanceof String[]) || !Arrays.asList((String[]) objectClass).contains(UserAdmin.class.getName())) {
throw new IllegalArgumentException("Bad objectclass: " + objectClass);
}
properties.put(EventConstants.SERVICE_OBJECTCLASS, objectClass);
properties.put(EventConstants.SERVICE_PID, eventRef.getProperty(EventConstants.SERVICE_PID));
eventAdmin.postEvent(new Event(topic, properties));
m_context.ungetService(ref);
}
}
}
Aggregations