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);
}
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"));
}
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());
}
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());
}
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);
}
}
Aggregations