Search in sources :

Example 21 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdminTest method testAddRequiredMember.

/**
     * Test method for
     * {@link org.apache.aries.jmx.useradmin.UserAdmin#addRequiredMember(java.lang.String, java.lang.String)}.
     * 
     * @throws IOException
     */
@Test
public void testAddRequiredMember() throws IOException {
    Group group1 = Mockito.mock(Group.class);
    User user1 = Mockito.mock(User.class);
    Mockito.when(userAdmin.getRole("group1")).thenReturn(group1);
    Mockito.when(userAdmin.getRole("user1")).thenReturn(user1);
    Mockito.when(group1.getType()).thenReturn(Role.GROUP);
    Mockito.when(group1.addRequiredMember(user1)).thenReturn(true);
    boolean isAdded = mbean.addRequiredMember("group1", "user1");
    Assert.assertTrue(isAdded);
    Mockito.verify(group1).addRequiredMember(user1);
}
Also used : Group(org.osgi.service.useradmin.Group) User(org.osgi.service.useradmin.User) Test(org.junit.Test)

Example 22 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdminTest method testAddCredentialString.

/**
     * Test method for
     * {@link org.apache.aries.jmx.useradmin.UserAdmin#addCredentialString(String, String, String)}
     * .
     * 
     * @throws IOException
     */
@Test
public void testAddCredentialString() throws IOException {
    User user1 = Mockito.mock(User.class);
    Dictionary<String, Object> credentials = new Hashtable<String, Object>();
    Mockito.when(userAdmin.getRole("user1")).thenReturn(user1);
    Mockito.when(user1.getType()).thenReturn(Role.USER);
    Mockito.when(user1.getCredentials()).thenReturn(credentials);
    mbean.addCredentialString("password", "1234", "user1");
    Assert.assertEquals("1234", (String) credentials.get("password"));
}
Also used : User(org.osgi.service.useradmin.User) Hashtable(java.util.Hashtable) Test(org.junit.Test)

Example 23 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdminTest method testGetAuthorization.

/**
     * Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#getAuthorization(java.lang.String)}.
     * 
     * @throws IOException
     */
@Test
public void testGetAuthorization() throws IOException {
    Authorization auth = Mockito.mock(Authorization.class);
    User user = Mockito.mock(User.class);
    Mockito.when(user.getType()).thenReturn(Role.USER);
    Mockito.when(userAdmin.getAuthorization(user)).thenReturn(auth);
    Mockito.when(userAdmin.getRole("role1")).thenReturn(user);
    Mockito.when(auth.getName()).thenReturn("auth1");
    Mockito.when(auth.getRoles()).thenReturn(new String[] { "role1" });
    CompositeData data = mbean.getAuthorization("role1");
    Assert.assertNotNull(data);
    AuthorizationData authData = AuthorizationData.from(data);
    Assert.assertNotNull(authData);
    Assert.assertEquals("auth1", authData.getName());
    Assert.assertArrayEquals(new String[] { "role1" }, authData.getRoles());
}
Also used : Authorization(org.osgi.service.useradmin.Authorization) User(org.osgi.service.useradmin.User) AuthorizationData(org.apache.aries.jmx.codec.AuthorizationData) CompositeData(javax.management.openmbean.CompositeData) Test(org.junit.Test)

Example 24 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdminTest method testGetRole.

/**
     * Test method for {@link org.apache.aries.jmx.useradmin.UserAdmin#getRole(java.lang.String)}.
     * 
     * @throws IOException
     */
@Test
public void testGetRole() throws IOException {
    User user1 = Mockito.mock(User.class);
    Mockito.when(user1.getType()).thenReturn(Role.USER);
    Mockito.when(user1.getName()).thenReturn("user1");
    Mockito.when(userAdmin.getRole(Mockito.anyString())).thenReturn(user1);
    CompositeData data = mbean.getRole("user1");
    Assert.assertNotNull(data);
    RoleData role = RoleData.from(data);
    Assert.assertNotNull(role);
    Assert.assertEquals("user1", role.getName());
    Assert.assertEquals(Role.USER, role.getType());
    Mockito.verify(userAdmin).getRole(Mockito.anyString());
}
Also used : User(org.osgi.service.useradmin.User) CompositeData(javax.management.openmbean.CompositeData) RoleData(org.apache.aries.jmx.codec.RoleData) Test(org.junit.Test)

Example 25 with User

use of org.osgi.service.useradmin.User in project aries by apache.

the class UserAdmin method addCredential.

private void addCredential(String key, Object value, String username) throws IOException {
    if (username == null) {
        throw new IOException("User name cannot be null");
    }
    if (key == null) {
        throw new IOException("Credential key cannot be null");
    }
    Role role = userAdmin.getRole(username);
    if (role == null) {
        throw new IOException("Operation fails user with provided username = [" + username + "] doesn't exist");
    }
    validateRoleType(role, Role.USER);
    Dictionary<String, Object> credentials = ((User) role).getCredentials();
    if (credentials != null) {
        credentials.put(key, value);
    }
}
Also used : Role(org.osgi.service.useradmin.Role) User(org.osgi.service.useradmin.User) IOException(java.io.IOException)

Aggregations

User (org.osgi.service.useradmin.User)25 Test (org.junit.Test)22 Hashtable (java.util.Hashtable)8 CompositeData (javax.management.openmbean.CompositeData)5 Group (org.osgi.service.useradmin.Group)5 IOException (java.io.IOException)3 TabularData (javax.management.openmbean.TabularData)3 Role (org.osgi.service.useradmin.Role)3 UserData (org.apache.aries.jmx.codec.UserData)2 Authorization (org.osgi.service.useradmin.Authorization)2 TabularDataSupport (javax.management.openmbean.TabularDataSupport)1 AuthorizationData (org.apache.aries.jmx.codec.AuthorizationData)1 RoleData (org.apache.aries.jmx.codec.RoleData)1