use of org.opennms.netmgt.model.OnmsUserList in project opennms by OpenNMS.
the class UserRestServiceIT method testUser.
@Test
public void testUser() throws Exception {
String url = "/users";
// GET all users
String xml = sendRequest(GET, url, 200);
assertTrue(xml.contains("admin"));
OnmsUserList list = JaxbUtils.unmarshal(OnmsUserList.class, xml);
assertEquals(1, list.getUsers().size());
assertEquals(xml, "admin", list.getUsers().get(0).getUsername());
// GET admin user
xml = sendRequest(GET, url + "/admin", 200);
assertTrue(xml.contains(">admin<"));
// GET invalid URL
sendRequest(GET, url + "/idontexist", 404);
}
use of org.opennms.netmgt.model.OnmsUserList in project opennms by OpenNMS.
the class UserRestServiceIT method testGetUserWithoutAuth.
@Test
public void testGetUserWithoutAuth() throws Exception {
createUser("foo");
createUser("bar");
setUser("foo", new String[] { "ROLE_USER" });
String xml = sendRequest(GET, "/users", 200);
assertTrue(xml.contains("foo"));
assertTrue(xml.contains("bar"));
OnmsUserList users = JaxbUtils.unmarshal(OnmsUserList.class, xml);
assertEquals(3, users.size());
assertEquals("xxxxxxxx", users.get(0).getPassword());
assertEquals("xxxxxxxx", users.get(1).getPassword());
assertEquals(PASSWORD, users.get(2).getPassword());
setUser("bar", new String[] { "ROLE_USER" });
xml = sendRequest(GET, "/users", 200);
assertTrue(xml.contains("foo"));
assertTrue(xml.contains("bar"));
users = JaxbUtils.unmarshal(OnmsUserList.class, xml);
assertEquals(3, users.size());
assertEquals("xxxxxxxx", users.get(0).getPassword());
assertEquals(PASSWORD, users.get(1).getPassword());
assertEquals("xxxxxxxx", users.get(2).getPassword());
setUser("admin", new String[] { "ROLE_ADMIN" });
xml = sendRequest(GET, "/users", 200);
assertTrue(xml.contains("foo"));
assertTrue(xml.contains("bar"));
users = JaxbUtils.unmarshal(OnmsUserList.class, xml);
assertEquals(3, users.size());
assertEquals(PASSWORD, users.get(0).getPassword());
assertEquals(PASSWORD, users.get(1).getPassword());
assertEquals(PASSWORD, users.get(2).getPassword());
}
use of org.opennms.netmgt.model.OnmsUserList in project opennms by OpenNMS.
the class UserRestServiceIT method testWriteALotOfUsers.
@Test
public void testWriteALotOfUsers() throws Exception {
int userCount = 50;
// Limit the thread pool so that we don't exhaust all of the database connections
ExecutorService pool = Executors.newFixedThreadPool(25);
List<Future<?>> createFutures = new ArrayList<Future<?>>();
for (int i = 0; i < userCount; i++) {
final String userName = "test" + i;
createFutures.add(pool.submit(Executors.callable(new Runnable() {
@Override
public void run() {
try {
setUser("admin", new String[] { "ROLE_ADMIN" });
createUser(userName, userName + "@opennms.org", 201, "/users/" + userName);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
})));
}
// Wait for all of the REST operations to complete
for (Future<?> future : createFutures) {
future.get();
}
// validate list
OnmsUserList users = JaxbUtils.unmarshal(OnmsUserList.class, sendRequest(GET, "/users", 200));
assertNotNull(users);
// +1 because user "admin" is there before creating all the new users.
assertEquals(userCount + 1, users.size());
// are properly accessible in the UserManager
for (int i = 0; i < userCount; i++) {
// validate each created user
String xml = sendRequest(GET, "/users/test" + i, 200);
OnmsUser eachUser = JaxbUtils.unmarshal(OnmsUser.class, xml);
assertEquals("test" + i, eachUser.getUsername());
assertEquals("test" + i + " Full Name", eachUser.getFullName());
assertEquals("test" + i + "@opennms.org", eachUser.getEmail());
assertEquals("Autogenerated by a unit test...", eachUser.getComments());
// change
sendPut("/users/test" + i, "password=MONKEYS&email=TEST@OPENNMS.COM", 204);
// validate change of password
eachUser = JaxbUtils.unmarshal(OnmsUser.class, sendRequest(GET, "/users/test" + i, 200));
User xmlUser = m_userManager.getUser("test" + i);
assertEquals(xmlUser.getPassword().getEncryptedPassword(), "MONKEYS");
// validate change of email
assertEquals("TEST@OPENNMS.COM", eachUser.getEmail());
}
}
use of org.opennms.netmgt.model.OnmsUserList in project opennms by OpenNMS.
the class DefaultGroupService method getUsersOfGroup.
@Override
public OnmsUserList getUsersOfGroup(String groupName) {
Group group = getGroup(groupName);
OnmsUserList userCollection = new OnmsUserList();
if (group != null) {
for (String eachUser : group.getUsers()) {
OnmsUser onmsUser;
try {
onmsUser = m_userDao.getOnmsUser(eachUser);
if (onmsUser == null)
continue;
userCollection.add(onmsUser);
} catch (IOException e) {
// ignore
Log.error("could not load user", e);
}
}
}
return userCollection;
}
use of org.opennms.netmgt.model.OnmsUserList in project opennms by OpenNMS.
the class UserManager method getOnmsUserList.
public OnmsUserList getOnmsUserList() throws IOException {
update();
final OnmsUserList list = new OnmsUserList();
m_readLock.lock();
try {
for (final String username : _getUserNames()) {
list.add(_getOnmsUser(username));
}
list.setTotalCount(list.getCount());
return list;
} finally {
m_readLock.unlock();
}
}
Aggregations