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);
}
}
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");
}
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);
}
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);
}
}
Aggregations