Search in sources :

Example 26 with Group

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

the class RoleRepositorySerializerTest method createGroup.

private Group createGroup(int idx) {
    String name = "Group" + idx;
    Group result = RoleFactory.createGroup(name);
    setCredentials(result);
    setProperties(result);
    return result;
}
Also used : Group(org.osgi.service.useradmin.Group)

Example 27 with Group

use of org.osgi.service.useradmin.Group 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]);
}
Also used : 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 28 with Group

use of org.osgi.service.useradmin.Group 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]);
}
Also used : 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 29 with Group

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

the class MongoSerializerHelper method deserialize.

/**
 * Converts a given {@link DBObject} to a {@link Role} instance.
 *
 * @param object the {@link DBObject} to convert, cannot be <code>null</code>.
 * @return a {@link Role} instance, never <code>null</code>.
 */
public Role deserialize(DBObject object) {
    int type = ((Integer) object.get(TYPE)).intValue();
    String name = (String) object.get(NAME);
    Role result = RoleFactory.createRole(type, name);
    // Read the generic properties of the role...
    deserializeDictionary(result.getProperties(), (DBObject) object.get(PROPERTIES));
    if ((Role.GROUP == type) || (Role.USER == type)) {
        // This is safe, as Group extends from User...
        deserializeDictionary(((User) result).getCredentials(), (DBObject) object.get(CREDENTIALS));
        if (Role.GROUP == type) {
            for (Role member : getRoles((BasicDBList) object.get(MEMBERS))) {
                ((Group) result).addMember(member);
            }
            for (Role member : getRoles((BasicDBList) object.get(REQUIRED_MEMBERS))) {
                ((Group) result).addRequiredMember(member);
            }
        }
    }
    return result;
}
Also used : Role(org.osgi.service.useradmin.Role) Group(org.osgi.service.useradmin.Group)

Example 30 with Group

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

the class MongoSerializerHelper method serializeUpdate.

/**
 * Creates a serialized version of the given {@link Role} to be used in an update statement.
 *
 * @param role the {@link Role} to update, cannot be <code>null</code>.
 * @return a {@link DBObject} representing an update statement for the given {@link Role}.
 */
public DBObject serializeUpdate(Role role) {
    int type = role.getType();
    BasicDBObject changeSet = new BasicDBObject();
    changeSet.put(PROPERTIES, serializeDictionary(role.getProperties()));
    if ((Role.GROUP == type) || (Role.USER == type)) {
        changeSet.put(CREDENTIALS, serializeDictionary(((User) role).getCredentials()));
        if (Role.GROUP == type) {
            changeSet.put(MEMBERS, getRoleNames(((Group) role).getMembers()));
            changeSet.put(REQUIRED_MEMBERS, getRoleNames(((Group) role).getRequiredMembers()));
        }
    }
    return new BasicDBObject(SET, changeSet);
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User)

Aggregations

Group (org.osgi.service.useradmin.Group)63 User (org.osgi.service.useradmin.User)32 Role (org.osgi.service.useradmin.Role)29 Test (org.junit.Test)11 IOException (java.io.IOException)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 Authorization (org.osgi.service.useradmin.Authorization)5 Bundle (org.osgi.framework.Bundle)3 UserAdmin (org.osgi.service.useradmin.UserAdmin)3 BasicDBObject (com.mongodb.BasicDBObject)2 GroupData (org.apache.aries.jmx.codec.GroupData)2 PrintWriter (java.io.PrintWriter)1 MessageDigest (java.security.MessageDigest)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CompositeData (javax.management.openmbean.CompositeData)1 ServletException (javax.servlet.ServletException)1 BackendException (org.apache.felix.useradmin.BackendException)1