use of org.opennms.netmgt.model.OnmsUser in project opennms by OpenNMS.
the class GroupRestServiceIT method createUser.
private void createUser(final String userName) throws Exception {
OnmsUser user = new OnmsUser();
user.setUsername(userName);
user.setPassword("blah");
sendPost("/users", JaxbUtils.marshal(user), 201, "/users/" + userName);
}
use of org.opennms.netmgt.model.OnmsUser 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.OnmsUser 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.OnmsUser in project opennms by OpenNMS.
the class UserManager method _getOnmsUser.
private OnmsUser _getOnmsUser(final String username) throws IOException {
final User xmlUser = _getUser(username);
if (xmlUser == null)
return null;
final OnmsUser user = new OnmsUser(username);
user.setFullName(trim(xmlUser.getFullName()));
user.setComments(trim(xmlUser.getUserComments()));
user.setPassword(xmlUser.getPassword().getEncryptedPassword());
user.setPasswordSalted(Boolean.valueOf(xmlUser.getPassword().getSalt()));
user.setDutySchedule(xmlUser.getDutySchedules());
user.setRoles(xmlUser.getRoles());
user.setEmail(_getContactInfo(xmlUser, ContactType.email));
return user;
}
use of org.opennms.netmgt.model.OnmsUser in project opennms by OpenNMS.
the class UserGroupManagerTest method testContactInfo.
@Test
public void testContactInfo() throws Exception {
// verify that email address is loadable by default
User admin = m_userManager.getUser("admin");
String adminEmail = m_userManager.getContactInfo("admin", ContactType.email);
OnmsUser onmsAdmin = m_userManager.getOnmsUser("admin");
String onmsAdminEmail = onmsAdmin.getEmail();
assertEquals("admin@opennms.org", adminEmail);
assertEquals(adminEmail, onmsAdminEmail);
// verify that email is overwritten
onmsAdmin.setEmail("admin@opennms.com");
m_userManager.save(onmsAdmin);
assertEquals("admin@opennms.com", m_userManager.getContactInfo("admin", ContactType.email));
// reset
m_userManager.setContactInfo("admin", ContactType.email, "admin@opennms.org");
// reload
admin = m_userManager.getUser("admin");
// should be saved too
m_userManager.saveUser("admin", admin);
assertEquals("admin@opennms.org", m_userManager.getContactInfo("admin", ContactType.email));
}
Aggregations