Search in sources :

Example 1 with AuthorizationData

use of org.apache.aries.jmx.codec.AuthorizationData in project aries by apache.

the class UserAdmin method getAuthorization.

/**
 * @see org.osgi.jmx.service.useradmin.UserAdminMBean#getAuthorization(java.lang.String)
 */
public CompositeData getAuthorization(String username) throws IOException {
    if (username == null) {
        throw new IOException("User name cannot be null");
    }
    Role role = userAdmin.getRole(username);
    if (role == null) {
        return null;
    }
    validateRoleType(role, Role.USER);
    Authorization auth = userAdmin.getAuthorization((User) role);
    if (auth == null) {
        return null;
    }
    return new AuthorizationData(auth).toCompositeData();
}
Also used : Role(org.osgi.service.useradmin.Role) Authorization(org.osgi.service.useradmin.Authorization) AuthorizationData(org.apache.aries.jmx.codec.AuthorizationData) IOException(java.io.IOException)

Example 2 with AuthorizationData

use of org.apache.aries.jmx.codec.AuthorizationData 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)

Aggregations

AuthorizationData (org.apache.aries.jmx.codec.AuthorizationData)2 Authorization (org.osgi.service.useradmin.Authorization)2 IOException (java.io.IOException)1 CompositeData (javax.management.openmbean.CompositeData)1 Test (org.junit.Test)1 Role (org.osgi.service.useradmin.Role)1 User (org.osgi.service.useradmin.User)1