Search in sources :

Example 26 with User

use of org.osgi.service.useradmin.User in project felix-dev by apache.

the class CustomRoleImplTest method testChangeUserCredentialsYieldsEvent.

/**
 * Tests that changing the credentials of a user-role yields an event.
 */
public void testChangeUserCredentialsYieldsEvent() throws Exception {
    final User role = (User) m_repository.addRole("testUser", Role.USER);
    role.getCredentials().put("key", "value1");
    assertNotNull(role);
    m_latch = new CountDownLatch(1);
    new Thread(new Runnable() {

        public void run() {
            role.getCredentials().put("key", "value2");
        }
    }).start();
    assertTrue(m_latch.await(1, TimeUnit.SECONDS));
}
Also used : User(org.osgi.service.useradmin.User) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 27 with User

use of org.osgi.service.useradmin.User in project felix-dev by apache.

the class RoleCheckerTest method testRequiredRolesMultipleRequiredGroupsOk.

/**
 * Test that a membership can be implied for users belonging to multiple required groups.
 */
public void testRequiredRolesMultipleRequiredGroupsOk() {
    User elmer = RoleFactory.createUser("elmer");
    User pepe = RoleFactory.createUser("pepe");
    User bugs = RoleFactory.createUser("bugs");
    User daffy = RoleFactory.createUser("daffy");
    Group administrators = RoleFactory.createGroup("administrators");
    administrators.addRequiredMember(m_anyone);
    administrators.addMember(elmer);
    administrators.addMember(pepe);
    administrators.addMember(bugs);
    Group family = RoleFactory.createGroup("family");
    family.addRequiredMember(m_anyone);
    family.addMember(elmer);
    family.addMember(pepe);
    family.addMember(daffy);
    Group alarmSystemActivation = RoleFactory.createGroup("alarmSystemActivation");
    alarmSystemActivation.addMember(m_anyone);
    alarmSystemActivation.addRequiredMember(administrators);
    alarmSystemActivation.addRequiredMember(family);
    assertTrue(m_roleChecker.isImpliedBy(alarmSystemActivation, elmer));
    assertTrue(m_roleChecker.isImpliedBy(alarmSystemActivation, pepe));
    assertFalse(m_roleChecker.isImpliedBy(alarmSystemActivation, bugs));
    assertFalse(m_roleChecker.isImpliedBy(alarmSystemActivation, daffy));
}
Also used : Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User)

Example 28 with User

use of org.osgi.service.useradmin.User in project felix-dev by apache.

the class RoleCheckerTest method testUserImpliesImpliedGroup.

/**
 * Test that a user does never imply a group to which it is not a member.
 */
public void testUserImpliesImpliedGroup() {
    User user = RoleFactory.createUser("foo");
    Group group = RoleFactory.createGroup("bar");
    group.addRequiredMember(m_anyone);
    group.addMember(user);
    assertTrue(m_roleChecker.isImpliedBy(group, user));
}
Also used : Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User)

Example 29 with User

use of org.osgi.service.useradmin.User in project felix-dev by apache.

the class RoleCheckerTest method testUserDoesNotImplyNotImpliedGroup.

/**
 * Test that a user does never imply a group to which it is not a member.
 */
public void testUserDoesNotImplyNotImpliedGroup() {
    User user = RoleFactory.createUser("foo");
    Group group = RoleFactory.createGroup("bar");
    assertFalse(m_roleChecker.isImpliedBy(user, group));
}
Also used : Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User)

Example 30 with User

use of org.osgi.service.useradmin.User in project felix-dev by apache.

the class AuthorizationImplTest method testGetRolesOk.

/**
 * Test that the tests for membership work correctly.
 */
public void testGetRolesOk() {
    Group citizens = createGroup("citizen");
    citizens.addRequiredMember(m_anyone);
    Group adults = createGroup("adult");
    adults.addRequiredMember(m_anyone);
    Group voters = createGroup("voter");
    voters.addRequiredMember(citizens);
    voters.addRequiredMember(adults);
    voters.addMember(m_anyone);
    // Elmer belongs to the citizens and adults...
    User elmer = createUser("elmer");
    citizens.addMember(elmer);
    adults.addMember(elmer);
    // Pepe belongs to the citizens, but is not an adult...
    User pepe = createUser("pepe");
    citizens.addMember(pepe);
    // Bugs is an adult, but is not a citizen...
    User bugs = createUser("bugs");
    adults.addMember(bugs);
    // Daffy is not an adult, neither a citizen...
    User daffy = createUser("daffy");
    // Donald is not an adult, neither a citizen...
    User donald = RoleFactory.createUser("donald");
    AuthorizationImpl auth;
    auth = new AuthorizationImpl(elmer, m_roleRepository);
    assertSameRoles(new String[] { "elmer", "adult", "citizen", "voter" }, auth.getRoles());
    auth = new AuthorizationImpl(pepe, m_roleRepository);
    assertSameRoles(new String[] { "pepe", "citizen" }, auth.getRoles());
    auth = new AuthorizationImpl(bugs, m_roleRepository);
    assertSameRoles(new String[] { "bugs", "adult" }, auth.getRoles());
    auth = new AuthorizationImpl(daffy, m_roleRepository);
    assertSameRoles(new String[] { "daffy" }, auth.getRoles());
    auth = new AuthorizationImpl(donald, m_roleRepository);
    assertNull(auth.getRoles());
}
Also used : Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User)

Aggregations

User (org.osgi.service.useradmin.User)128 Group (org.osgi.service.useradmin.Group)60 Test (org.junit.Test)30 Role (org.osgi.service.useradmin.Role)17 Authorization (org.osgi.service.useradmin.Authorization)13 CountDownLatch (java.util.concurrent.CountDownLatch)12 Hashtable (java.util.Hashtable)10 UserAdmin (org.osgi.service.useradmin.UserAdmin)8 Bundle (org.osgi.framework.Bundle)6 CompositeData (javax.management.openmbean.CompositeData)5 BasicDBObject (com.mongodb.BasicDBObject)4 Dictionary (java.util.Dictionary)4 IOException (java.io.IOException)3 TabularData (javax.management.openmbean.TabularData)3 Collection (java.util.Collection)2 Enumeration (java.util.Enumeration)2 Iterator (java.util.Iterator)2 List (java.util.List)2 UserData (org.apache.aries.jmx.codec.UserData)2 HashSet (java.util.HashSet)1