use of javax.servlet.RequestDispatcher 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);
}
use of javax.servlet.RequestDispatcher 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);
}
}
use of javax.servlet.RequestDispatcher in project opennms by OpenNMS.
the class DiscoveryScanServlet method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
LOG.info("Loading Discovery configuration.");
HttpSession sess = request.getSession(true);
DiscoveryConfiguration config = (DiscoveryConfiguration) sess.getAttribute(ATTRIBUTE_DISCOVERY_CONFIGURATION);
if (config == null) {
config = new DiscoveryConfiguration();
}
// load current general settings
config = GeneralSettingsLoader.load(request, config);
String action = request.getParameter("action");
LOG.debug("action: {}", action);
// add a Specific
if (action.equals(addSpecificAction)) {
LOG.debug("Adding Specific");
String ipAddr = request.getParameter("specificipaddress");
String timeout = request.getParameter("specifictimeout");
String retries = request.getParameter("specificretries");
String foreignSource = request.getParameter("specificforeignsource");
String location = request.getParameter("specificlocation");
Specific newSpecific = new Specific();
newSpecific.setAddress(ipAddr);
if (timeout != null && !"".equals(timeout.trim()) && !timeout.equals(String.valueOf(config.getTimeout().orElse(null)))) {
newSpecific.setTimeout(WebSecurityUtils.safeParseLong(timeout));
}
if (retries != null && !"".equals(retries.trim()) && !retries.equals(String.valueOf(config.getRetries().orElse(null)))) {
newSpecific.setRetries(WebSecurityUtils.safeParseInt(retries));
}
if (foreignSource != null && !"".equals(foreignSource.trim()) && !foreignSource.equals(config.getForeignSource().orElse(null))) {
newSpecific.setForeignSource(foreignSource);
}
if (location != null && !"".equals(location.trim()) && !location.equals(config.getLocation().orElse(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID))) {
newSpecific.setLocation(location);
}
config.addSpecific(newSpecific);
}
// remove 'Specific' from configuration
if (action.equals(removeSpecificAction)) {
LOG.debug("Removing Specific");
String specificIndex = request.getParameter("index");
int index = WebSecurityUtils.safeParseInt(specificIndex);
final int index1 = index;
Specific spec = config.getSpecifics().get(index1);
boolean result = config.removeSpecific(spec);
LOG.debug("Removing Specific result = {}", result);
}
// add an 'Include Range'
if (action.equals(addIncludeRangeAction)) {
LOG.debug("Adding Include Range");
String ipAddrBase = request.getParameter("irbase");
String ipAddrEnd = request.getParameter("irend");
String timeout = request.getParameter("irtimeout");
String retries = request.getParameter("irretries");
String foreignSource = request.getParameter("irforeignsource");
String location = request.getParameter("irlocation");
IncludeRange newIR = new IncludeRange();
newIR.setBegin(ipAddrBase);
newIR.setEnd(ipAddrEnd);
if (timeout != null && !"".equals(timeout.trim()) && !timeout.equals(String.valueOf(config.getTimeout().orElse(null)))) {
newIR.setTimeout(WebSecurityUtils.safeParseLong(timeout));
}
if (retries != null && !"".equals(retries.trim()) && !retries.equals(String.valueOf(config.getRetries().orElse(null)))) {
newIR.setRetries(WebSecurityUtils.safeParseInt(retries));
}
if (foreignSource != null && !"".equals(foreignSource.trim()) && !foreignSource.equals(config.getForeignSource().orElse(null))) {
newIR.setForeignSource(foreignSource);
}
if (location != null && !"".equals(location.trim()) && !location.equals(config.getLocation().orElse(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID))) {
newIR.setLocation(location);
}
config.addIncludeRange(newIR);
}
// remove 'Include Range' from configuration
if (action.equals(removeIncludeRangeAction)) {
LOG.debug("Removing Include Range");
String specificIndex = request.getParameter("index");
int index = WebSecurityUtils.safeParseInt(specificIndex);
final int index1 = index;
IncludeRange ir = config.getIncludeRanges().get(index1);
boolean result = config.removeIncludeRange(ir);
LOG.debug("Removing Include Range result = {}", result);
}
// add an 'Include URL'
if (action.equals(addIncludeUrlAction)) {
LOG.debug("Adding Include URL");
String url = request.getParameter("iuurl");
String timeout = request.getParameter("iutimeout");
String retries = request.getParameter("iuretries");
String foreignSource = request.getParameter("iuforeignsource");
String location = request.getParameter("iulocation");
IncludeUrl iu = new IncludeUrl();
iu.setUrl(url);
if (timeout != null && !"".equals(timeout.trim()) && !timeout.equals(String.valueOf(config.getTimeout().orElse(null)))) {
iu.setTimeout(WebSecurityUtils.safeParseLong(timeout));
}
if (retries != null && !"".equals(retries.trim()) && !retries.equals(String.valueOf(config.getRetries().orElse(null)))) {
iu.setRetries(WebSecurityUtils.safeParseInt(retries));
}
if (foreignSource != null && !"".equals(foreignSource.trim()) && !foreignSource.equals(config.getForeignSource().orElse(null))) {
iu.setForeignSource(foreignSource);
}
if (location != null && !"".equals(location.trim()) && !location.equals(config.getLocation().orElse(MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID))) {
iu.setLocation(location);
}
config.addIncludeUrl(iu);
}
// remove 'Include URL' from configuration
if (action.equals(removeIncludeUrlAction)) {
LOG.debug("Removing Include URL");
String specificIndex = request.getParameter("index");
int index = WebSecurityUtils.safeParseInt(specificIndex);
final int index1 = index;
IncludeUrl iu = config.getIncludeUrls().get(index1);
boolean result = config.removeIncludeUrl(iu);
LOG.debug("Removing Include URL result = {}", result);
}
// add an 'Exclude Range'
if (action.equals(addExcludeRangeAction)) {
LOG.debug("Adding Exclude Range");
String ipAddrBegin = request.getParameter("erbegin");
String ipAddrEnd = request.getParameter("erend");
ExcludeRange newER = new ExcludeRange();
newER.setBegin(ipAddrBegin);
newER.setEnd(ipAddrEnd);
config.addExcludeRange(newER);
}
// remove 'Exclude Range' from configuration
if (action.equals(removeExcludeRangeAction)) {
LOG.debug("Removing Exclude Range");
String specificIndex = request.getParameter("index");
int index = WebSecurityUtils.safeParseInt(specificIndex);
final int index1 = index;
ExcludeRange er = config.getExcludeRanges().get(index1);
boolean result = config.removeExcludeRange(er);
LOG.debug("Removing Exclude Range result = {}", result);
}
// Submit the discovery job
if (action.equals(saveAndRestartAction)) {
try {
WebApplicationContext beanFactory = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
// Fetch the ServiceRegistry
ServiceRegistry registry = beanFactory.getBean(ServiceRegistry.class);
// Use it to look up a DiscoveryTaskExecutor service
DiscoveryTaskExecutor executor = registry.findProvider(DiscoveryTaskExecutor.class);
// If the service exists...
if (executor != null) {
// Submit the job to the discovery queue
executor.handleDiscoveryTask(config);
} else {
LOG.warn("No DiscoveryTaskExecutor service is available");
}
} catch (Throwable ex) {
LOG.error("Error while submitting task", ex);
throw new ServletException(ex);
}
// TODO: Send an event here when the scan is started? Or do it on the Camel side?
/*
EventProxy proxy = null;
try {
proxy = Util.createEventProxy();
} catch (Throwable me) {
LOG.error(me.getMessage());
}
EventBuilder bldr = new EventBuilder(EventConstants.DISCOVERYCONFIG_CHANGED_EVENT_UEI, "ActionDiscoveryServlet");
bldr.setHost("host");
try {
proxy.send(bldr.getEvent());
} catch (Throwable me) {
LOG.error(me.getMessage());
}
LOG.info("Restart Discovery requested!");
*/
sess.removeAttribute(ATTRIBUTE_DISCOVERY_CONFIGURATION);
response.sendRedirect(Util.calculateUrlBase(request, "admin/discovery/scan-done.jsp"));
return;
}
sess.setAttribute(ATTRIBUTE_DISCOVERY_CONFIGURATION, config);
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/discovery/edit-scan.jsp");
dispatcher.forward(request, response);
}
use of javax.servlet.RequestDispatcher in project opennms by OpenNMS.
the class AddGroupDutySchedulesServlet method doPost.
/**
* {@inheritDoc}
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession userSession = request.getSession(true);
Group group = (Group) userSession.getAttribute("group.modifyGroup.jsp");
Vector<Object> newSchedule = new Vector<>();
int dutyAddCount = WebSecurityUtils.safeParseInt(request.getParameter("numSchedules"));
for (int j = 0; j < dutyAddCount; j++) {
// add 7 false boolean values for each day of the week
for (int i = 0; i < 7; i++) {
newSchedule.addElement(Boolean.FALSE);
}
// add two strings for the begin and end time
newSchedule.addElement("0");
newSchedule.addElement("0");
group.addDutySchedule((new DutySchedule(newSchedule)).toString());
}
// forward the request for proper display
RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/admin/userGroupView/groups/modifyGroup.jsp");
dispatcher.forward(request, response);
}
use of javax.servlet.RequestDispatcher in project processdash by dtuma.
the class WorkflowMappingEditor method showView.
private void showView(HttpServletRequest req, HttpServletResponse resp, String viewName) throws ServletException, IOException {
req.setAttribute("resources", resources.asJSTLMap());
RequestDispatcher disp = getServletContext().getRequestDispatcher("/WEB-INF/jsp/" + viewName);
disp.forward(req, resp);
}
Aggregations