Search in sources :

Example 11 with OnmsUser

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);
}
Also used : OnmsUser(org.opennms.netmgt.model.OnmsUser)

Example 12 with OnmsUser

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());
    }
}
Also used : OnmsUserList(org.opennms.netmgt.model.OnmsUserList) User(org.opennms.netmgt.config.users.User) OnmsUser(org.opennms.netmgt.model.OnmsUser) ArrayList(java.util.ArrayList) OnmsUser(org.opennms.netmgt.model.OnmsUser) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 13 with OnmsUser

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;
}
Also used : OnmsUserList(org.opennms.netmgt.model.OnmsUserList) Group(org.opennms.netmgt.config.groups.Group) OnmsGroup(org.opennms.netmgt.model.OnmsGroup) OnmsUser(org.opennms.netmgt.model.OnmsUser) IOException(java.io.IOException)

Example 14 with OnmsUser

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;
}
Also used : User(org.opennms.netmgt.config.users.User) OnmsUser(org.opennms.netmgt.model.OnmsUser) OnmsUser(org.opennms.netmgt.model.OnmsUser)

Example 15 with OnmsUser

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));
}
Also used : User(org.opennms.netmgt.config.users.User) OnmsUser(org.opennms.netmgt.model.OnmsUser) OnmsUser(org.opennms.netmgt.model.OnmsUser) Test(org.junit.Test)

Aggregations

OnmsUser (org.opennms.netmgt.model.OnmsUser)21 Test (org.junit.Test)8 Path (javax.ws.rs.Path)5 User (org.opennms.netmgt.config.users.User)5 ArrayList (java.util.ArrayList)2 DELETE (javax.ws.rs.DELETE)2 PUT (javax.ws.rs.PUT)2 OnmsUserList (org.opennms.netmgt.model.OnmsUserList)2 DirtiesContext (org.springframework.test.annotation.DirtiesContext)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Properties (java.util.Properties)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 Matcher (java.util.regex.Matcher)1