Search in sources :

Example 6 with UserManager

use of org.opennms.netmgt.config.UserManager 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)

Example 7 with UserManager

use of org.opennms.netmgt.config.UserManager in project opennms by OpenNMS.

the class RenameUserServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String userID = request.getParameter("userID");
    String newID = request.getParameter("newID");
    // now save to the xml file
    try {
        UserManager userFactory = UserFactory.getInstance();
        userFactory.renameUser(userID, newID);
    } catch (Throwable e) {
        throw new ServletException("Error renaming user " + userID + " to " + newID, e);
    }
    response.sendRedirect("list.jsp");
}
Also used : ServletException(javax.servlet.ServletException) UserManager(org.opennms.netmgt.config.UserManager)

Example 8 with UserManager

use of org.opennms.netmgt.config.UserManager in project opennms by OpenNMS.

the class SaveUserServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession user = request.getSession(false);
    if (user != null) {
        UserManager userFactory = UserFactory.getInstance();
        User newUser = (User) user.getAttribute("user.modifyUser.jsp");
        if (newUser.getRoles().contains(Authentication.ROLE_READONLY) && !request.isUserInRole(Authentication.ROLE_ADMIN)) {
            throw new ServletException("Error: user " + newUser.getUserId() + " is read-only!");
        }
        // now save to the XML file
        try {
            userFactory.saveUser(newUser.getUserId(), newUser);
        } catch (Throwable e) {
            throw new ServletException("Error saving user " + newUser.getUserId(), e);
        }
    }
    // forward the request for proper display
    RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/userGroupView/users/list.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)

Example 9 with UserManager

use of org.opennms.netmgt.config.UserManager in project opennms by OpenNMS.

the class NewPasswordEntryServlet method doPost.

/**
 * {@inheritDoc}
 */
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession userSession = request.getSession(false);
    try {
        UserFactory.init();
    } catch (Throwable e) {
        throw new ServletException("NewPasswordEntryServlet: Error initialising user factory." + e);
    }
    UserManager userFactory = UserFactory.getInstance();
    if (userSession != null) {
        String userid = request.getRemoteUser();
        try {
            User user = userFactory.getUser(userid);
            userSession.setAttribute("user.newPassword.jsp", user);
        } catch (Throwable e) {
            throw new ServletException("Couldn't initialize UserFactory", e);
        }
        RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/account/selfService/newPassword.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)

Aggregations

UserManager (org.opennms.netmgt.config.UserManager)9 ServletException (javax.servlet.ServletException)7 RequestDispatcher (javax.servlet.RequestDispatcher)5 HttpSession (javax.servlet.http.HttpSession)5 User (org.opennms.netmgt.config.users.User)5 Password (org.opennms.netmgt.config.users.Password)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Matcher (java.util.regex.Matcher)1 ReportException (org.opennms.api.reporting.ReportException)1 JavaMailerException (org.opennms.javamail.JavaMailerException)1 OnmsUser (org.opennms.netmgt.model.OnmsUser)1 DeliveryOptions (org.opennms.reporting.core.DeliveryOptions)1 OnmsUpgradeException (org.opennms.upgrade.api.OnmsUpgradeException)1