Search in sources :

Example 1 with Password

use of org.opennms.netmgt.config.users.Password in project opennms by OpenNMS.

the class UserManager method save.

public void save(final OnmsUser onmsUser) throws Exception {
    update();
    m_writeLock.lock();
    try {
        User xmlUser = _getUser(onmsUser.getUsername());
        if (xmlUser == null) {
            xmlUser = new User();
            xmlUser.setUserId(onmsUser.getUsername());
        }
        xmlUser.setFullName(onmsUser.getFullName());
        xmlUser.setUserComments(onmsUser.getComments());
        // Contact info
        _setContact(xmlUser, ContactType.email, onmsUser.getEmail());
        final Password pass = new Password();
        pass.setEncryptedPassword(onmsUser.getPassword());
        pass.setSalt(onmsUser.getPasswordSalted());
        xmlUser.setPassword(pass);
        if (onmsUser.getDutySchedule() != null) {
            xmlUser.setDutySchedules(new ArrayList<String>(onmsUser.getDutySchedule()));
        }
        if (onmsUser.getRoles() != null) {
            xmlUser.setRoles(new ArrayList<String>(onmsUser.getRoles()));
        }
        _writeUser(onmsUser.getUsername(), xmlUser);
    } finally {
        m_writeLock.unlock();
    }
}
Also used : User(org.opennms.netmgt.config.users.User) OnmsUser(org.opennms.netmgt.model.OnmsUser) Password(org.opennms.netmgt.config.users.Password)

Example 2 with Password

use of org.opennms.netmgt.config.users.Password in project opennms by OpenNMS.

the class UserManager method setEncryptedPassword.

/**
 * Sets the password for this user, assuming that the value passed in is
 * already encrypted properly
 *
 * @param userID
 *            the user ID to change the password for
 * @param aPassword
 *            the encrypted password
 * @throws java.lang.Exception if any.
 */
public void setEncryptedPassword(final String userID, final String aPassword, final boolean salted) throws Exception {
    update();
    m_writeLock.lock();
    try {
        final User user = m_users.get(userID);
        if (user != null) {
            final Password pass = new Password();
            pass.setEncryptedPassword(aPassword);
            pass.setSalt(salted);
            user.setPassword(pass);
        }
        _saveCurrent();
    } finally {
        m_writeLock.unlock();
    }
}
Also used : User(org.opennms.netmgt.config.users.User) OnmsUser(org.opennms.netmgt.model.OnmsUser) Password(org.opennms.netmgt.config.users.Password)

Example 3 with Password

use of org.opennms.netmgt.config.users.Password in project opennms by OpenNMS.

the class UpdateUserServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(false);
    if (userSession != null) {
        User newUser = (User) userSession.getAttribute("user.modifyUser.jsp");
        try {
            UserFactory.init();
        } catch (Throwable e) {
            throw new ServletException("UpdateUserServlet:init Error initialising UserFactory " + e);
        }
        // get the rest of the user information from the form
        newUser.setFullName(request.getParameter("fullName"));
        newUser.setUserComments(request.getParameter("userComments"));
        String password = request.getParameter("password");
        if (password != null && !password.trim().equals("")) {
            final Password pass = new Password();
            pass.setEncryptedPassword(UserFactory.getInstance().encryptedPassword(password, true));
            pass.setSalt(true);
            newUser.setPassword(pass);
        }
        String tuiPin = request.getParameter("tuiPin");
        if (tuiPin != null && !tuiPin.trim().equals("")) {
            newUser.setTuiPin(tuiPin);
        }
        String email = request.getParameter(ContactType.email.toString());
        String pagerEmail = request.getParameter("pemail");
        String xmppAddress = request.getParameter(ContactType.xmppAddress.toString());
        String microblog = request.getParameter(ContactType.microblog.toString());
        String numericPage = request.getParameter("numericalService");
        String numericPin = request.getParameter("numericalPin");
        String textPage = request.getParameter("textService");
        String textPin = request.getParameter("textPin");
        String workPhone = request.getParameter(ContactType.workPhone.toString());
        String mobilePhone = request.getParameter(ContactType.mobilePhone.toString());
        String homePhone = request.getParameter(ContactType.homePhone.toString());
        newUser.clearContacts();
        Contact tmpContact = new Contact();
        tmpContact.setInfo(email);
        tmpContact.setType(ContactType.email.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(pagerEmail);
        tmpContact.setType(ContactType.pagerEmail.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(xmppAddress);
        tmpContact.setType(ContactType.xmppAddress.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(microblog);
        tmpContact.setType(ContactType.microblog.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(numericPin);
        tmpContact.setServiceProvider(numericPage);
        tmpContact.setType(ContactType.numericPage.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(textPin);
        tmpContact.setServiceProvider(textPage);
        tmpContact.setType(ContactType.textPage.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(workPhone);
        tmpContact.setType(ContactType.workPhone.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(mobilePhone);
        tmpContact.setType(ContactType.mobilePhone.toString());
        newUser.addContact(tmpContact);
        tmpContact = new Contact();
        tmpContact.setInfo(homePhone);
        tmpContact.setType(ContactType.homePhone.toString());
        newUser.addContact(tmpContact);
        // build the duty schedule data structure
        List<Boolean> newSchedule = new ArrayList<Boolean>(7);
        ChoiceFormat days = new ChoiceFormat("0#Mo|1#Tu|2#We|3#Th|4#Fr|5#Sa|6#Su");
        Collection<String> dutySchedules = getDutySchedulesForUser(newUser);
        dutySchedules.clear();
        int dutyCount = WebSecurityUtils.safeParseInt(request.getParameter("dutySchedules"));
        for (int duties = 0; duties < dutyCount; duties++) {
            newSchedule.clear();
            String deleteFlag = request.getParameter("deleteDuty" + duties);
            // don't save any duties that were marked for deletion
            if (deleteFlag == null) {
                for (int i = 0; i < 7; i++) {
                    String curDayFlag = request.getParameter("duty" + duties + days.format(i));
                    newSchedule.add(Boolean.valueOf(curDayFlag != null));
                }
                int startTime = WebSecurityUtils.safeParseInt(request.getParameter("duty" + duties + "Begin"));
                int stopTime = WebSecurityUtils.safeParseInt(request.getParameter("duty" + duties + "End"));
                DutySchedule newDuty = new DutySchedule(newSchedule, startTime, stopTime);
                dutySchedules.add(newDuty.toString());
            }
        }
        // The new list of roles will override the existing one.
        // If the new list is empty or null, that means the user should not have roles, and the existing ones should be removed.
        newUser.getRoles().clear();
        String[] configuredRoles = request.getParameterValues("configuredRoles");
        if (configuredRoles != null && configuredRoles.length > 0) {
            newUser.getRoles().clear();
            for (String role : configuredRoles) {
                newUser.addRole(role);
            }
        }
        userSession.setAttribute("user.modifyUser.jsp", newUser);
    }
    // forward the request for proper display
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(request.getParameter("redirect"));
    dispatcher.forward(request, response);
}
Also used : User(org.opennms.netmgt.config.users.User) HttpSession(javax.servlet.http.HttpSession) ChoiceFormat(java.text.ChoiceFormat) ArrayList(java.util.ArrayList) RequestDispatcher(javax.servlet.RequestDispatcher) Contact(org.opennms.netmgt.config.users.Contact) ServletException(javax.servlet.ServletException) DutySchedule(org.opennms.netmgt.config.users.DutySchedule) Password(org.opennms.netmgt.config.users.Password)

Example 4 with Password

use of org.opennms.netmgt.config.users.Password in project opennms by OpenNMS.

the class NewPasswordActionServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        UserFactory.init();
    } catch (Throwable e) {
        throw new ServletException("NewPasswordActionServlet: Error initialising user factory." + e);
    }
    HttpSession userSession = request.getSession(false);
    UserManager userFactory = UserFactory.getInstance();
    User user = (User) userSession.getAttribute("user.newPassword.jsp");
    String currentPassword = request.getParameter("currentPassword");
    String newPassword = request.getParameter("newPassword");
    if (!request.isUserInRole(Authentication.ROLE_ADMIN) && user.getRoles().contains(Authentication.ROLE_READONLY)) {
        throw new ServletException("User " + user.getUserId() + " is read-only");
    }
    if (!userFactory.comparePasswords(user.getUserId(), currentPassword)) {
        RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/account/selfService/newPassword.jsp?action=redo");
        dispatcher.forward(request, response);
    } else {
        final Password pass = new Password();
        pass.setEncryptedPassword(userFactory.encryptedPassword(newPassword, true));
        pass.setSalt(true);
        user.setPassword(pass);
        userSession.setAttribute("user.newPassword.jsp", user);
        try {
            userFactory.saveUser(user.getUserId(), user);
        } catch (Throwable e) {
            throw new ServletException("Error saving user " + user.getUserId(), e);
        }
        // forward the request for proper display
        RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/account/selfService/passwordChanged.jsp");
        dispatcher.forward(request, response);
    }
}
Also used : ServletException(javax.servlet.ServletException) User(org.opennms.netmgt.config.users.User) HttpSession(javax.servlet.http.HttpSession) UserManager(org.opennms.netmgt.config.UserManager) RequestDispatcher(javax.servlet.RequestDispatcher) Password(org.opennms.netmgt.config.users.Password)

Example 5 with Password

use of org.opennms.netmgt.config.users.Password in project opennms by OpenNMS.

the class UserManager method setUnencryptedPassword.

/**
 * Sets the password for this user, first encrypting it
 *
 * @param userID
 *            the user ID to change the password for
 * @param aPassword
 *            the password
 * @throws java.lang.Exception if any.
 */
public void setUnencryptedPassword(final String userID, final String aPassword) throws Exception {
    update();
    m_writeLock.lock();
    try {
        final User user = m_users.get(userID);
        if (user != null) {
            final Password pass = new Password();
            pass.setEncryptedPassword(encryptedPassword(aPassword, true));
            pass.setSalt(true);
            user.setPassword(pass);
        }
        _saveCurrent();
    } finally {
        m_writeLock.unlock();
    }
}
Also used : User(org.opennms.netmgt.config.users.User) OnmsUser(org.opennms.netmgt.model.OnmsUser) Password(org.opennms.netmgt.config.users.Password)

Aggregations

Password (org.opennms.netmgt.config.users.Password)6 User (org.opennms.netmgt.config.users.User)6 RequestDispatcher (javax.servlet.RequestDispatcher)3 ServletException (javax.servlet.ServletException)3 HttpSession (javax.servlet.http.HttpSession)3 OnmsUser (org.opennms.netmgt.model.OnmsUser)3 UserManager (org.opennms.netmgt.config.UserManager)2 ChoiceFormat (java.text.ChoiceFormat)1 ArrayList (java.util.ArrayList)1 Contact (org.opennms.netmgt.config.users.Contact)1 DutySchedule (org.opennms.netmgt.config.users.DutySchedule)1