UserAdmin implements UserAdminMBean { public TabularData getCredentials(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); Dictionary<String, Object> credentials = ((User) role).getCredentials(); if (credentials == null) { return null; } TabularData data = new TabularDataSupport(JmxConstants.PROPERTIES_TYPE); for (Enumeration<String> keys = credentials.keys(); keys.hasMoreElements();) { String key = keys.nextElement(); data.put(PropertyData.newInstance(key, credentials.get(key)).toCompositeData()); } return data; } UserAdmin(org.osgi.service.useradmin.UserAdmin userAdmin); void addCredential(String key, byte[] value, String username); void addCredentialString(String key, String value, String username); boolean addMember(String groupname, String rolename); void addPropertyString(String key, String value, String rolename); void addProperty(String key, byte[] value, String rolename); boolean addRequiredMember(String groupname, String rolename); void createGroup(String name); void createRole(String name); void createUser(String name); CompositeData getAuthorization(String username); TabularData getCredentials(String username); CompositeData getGroup(String groupname); String[] getGroups(String filter); String[] getImpliedRoles(String username); String[] getMembers(String groupname); TabularData getProperties(String rolename); String[] getRequiredMembers(String groupname); CompositeData getRole(String name); String[] getRoles(String filter); CompositeData getUser(String username); String getUserWithProperty(String key, String value); String[] getUsers(String filter); String[] listGroups(); String[] listRoles(); String[] listUsers(); void removeCredential(String key, String username); boolean removeGroup(String name); boolean removeMember(String groupname, String rolename); void removeProperty(String key, String rolename); boolean removeRole(String name); boolean removeUser(String name);  }
@Test public void testGetCredentials() throws IOException { User user1 = Mockito.mock(User.class); Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put("key", "value"); Mockito.when(user1.getCredentials()).thenReturn(properties); Mockito.when(user1.getType()).thenReturn(Role.USER); Mockito.when(userAdmin.getRole(Mockito.anyString())).thenReturn(user1); TabularData data = mbean.getCredentials("user1"); Assert.assertNotNull(data); Assert.assertEquals(JmxConstants.PROPERTIES_TYPE, data.getTabularType()); CompositeData composite = data.get(new Object[] { "key" }); Assert.assertNotNull(composite); Assert.assertEquals("key", (String) composite.get(JmxConstants.KEY)); Assert.assertEquals("value", (String) composite.get(JmxConstants.VALUE)); }