Search in sources :

Example 6 with Password

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

the class AddNewUserServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        UserFactory.init();
    } catch (Throwable e) {
        throw new ServletException("AddNewUserServlet: Error initialising user factory." + e);
    }
    UserManager userFactory = UserFactory.getInstance();
    String userID = request.getParameter("userID");
    String password = request.getParameter("pass1");
    boolean hasUser = false;
    try {
        hasUser = userFactory.hasUser(userID);
    } catch (Throwable e) {
        throw new ServletException("can't determine if user " + userID + " already exists in users.xml.", e);
    }
    if (hasUser) {
        RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/userGroupView/users/newUser.jsp?action=redo");
        dispatcher.forward(request, response);
    } else {
        final Password pass = new Password();
        pass.setEncryptedPassword(UserFactory.getInstance().encryptedPassword(password, true));
        pass.setSalt(true);
        final User newUser = new User();
        newUser.setUserId(userID);
        newUser.setPassword(pass);
        final HttpSession userSession = request.getSession(false);
        userSession.setAttribute("user.modifyUser.jsp", newUser);
        // forward the request for proper display
        RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/userGroupView/users/modifyUser.jsp");
        dispatcher.forward(request, response);
    }
}
Also used : ServletException(javax.servlet.ServletException) User(org.opennms.netmgt.config.users.User) UserManager(org.opennms.netmgt.config.UserManager) HttpSession(javax.servlet.http.HttpSession) RequestDispatcher(javax.servlet.RequestDispatcher) 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