Search in sources :

Example 6 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class FilterFavoriteServiceIT method createFavoriteObject.

private static OnmsFilterFavorite createFavoriteObject(String user, String filterName, String filterCriteria, Page page) {
    OnmsFilterFavorite favorite = new OnmsFilterFavorite();
    favorite.setName(filterName);
    favorite.setFilter(filterCriteria);
    favorite.setPage(page);
    favorite.setUsername(user);
    return favorite;
}
Also used : OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite)

Example 7 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class FilterFavoriteServiceIT method verifyXSSPreventionOnRead.

// Due to NMS-9670 there may already be malicious data in the table, verify that we convert that correctly as well
@Test
public void verifyXSSPreventionOnRead() throws FilterFavoriteService.FilterFavoriteException {
    for (Page page : Page.values()) {
        final OnmsFilterFavorite filterToCreate = createFavoriteObject("ulf", "XSS Read Test " + page.name(), "filter=severity%3D6<script>alert(123);</script>", page);
        int filterId = service.getFilterFavoriteDao().save(filterToCreate);
        final OnmsFilterFavorite filterRead = service.getFavorite(filterId, "ulf");
        Assert.assertEquals("filter=severity=6&lt;script&gt;alert(123);&lt;/script&gt;", filterRead.getFilter());
    }
}
Also used : Page(org.opennms.netmgt.model.OnmsFilterFavorite.Page) OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite) Test(org.junit.Test)

Example 8 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class AlarmFilterController method createFavorite.

public ModelAndView createFavorite(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String error = null;
    try {
        OnmsFilterFavorite favorite = favoriteService.createFavorite(request.getRemoteUser(), request.getParameter("favoriteName"), FilterUtil.toFilterURL(request.getParameterValues("filter")), OnmsFilterFavorite.Page.ALARM);
        if (favorite != null) {
            // success
            ModelAndView successView = list(request, favorite);
            // AlertTag.addAlertToRequest(successView, "Favorite was created successfully", AlertType.SUCCESS);
            return successView;
        }
        error = "An error occured while creating the favorite";
    } catch (FilterFavoriteService.FilterFavoriteException ex) {
        error = ex.getMessage();
    }
    ModelAndView errorView = list(request, (OnmsFilterFavorite) null);
    AlertTag.addAlertToRequest(errorView, error, AlertType.ERROR);
    return errorView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) FilterFavoriteService(org.opennms.web.services.FilterFavoriteService) OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite)

Example 9 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class EventController method createFavorite.

public ModelAndView createFavorite(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String error = null;
    try {
        OnmsFilterFavorite favorite = favoriteService.createFavorite(request.getRemoteUser(), request.getParameter("favoriteName"), FilterUtil.toFilterURL(request.getParameterValues("filter")), OnmsFilterFavorite.Page.EVENT);
        if (favorite != null) {
            // success
            ModelAndView successView = list(request, favorite);
            // AlertTag.addAlertToRequest(successView, "Favorite was created successfully", AlertType.SUCCESS);
            return successView;
        }
        error = "An error occured while creating the favorite";
    } catch (FilterFavoriteService.FilterFavoriteException ex) {
        error = ex.getMessage();
    }
    ModelAndView errorView = list(request, (OnmsFilterFavorite) null);
    AlertTag.addAlertToRequest(errorView, error, AlertType.ERROR);
    return errorView;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) FilterFavoriteService(org.opennms.web.services.FilterFavoriteService) OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite)

Example 10 with OnmsFilterFavorite

use of org.opennms.netmgt.model.OnmsFilterFavorite in project opennms by OpenNMS.

the class FilterFavoriteService method createFavorite.

public OnmsFilterFavorite createFavorite(String userName, String favoriteName, String filterString, OnmsFilterFavorite.Page page) throws FilterFavoriteException {
    // Validate input
    validate(userName, favoriteName, filterString, page);
    // Create filter
    OnmsFilterFavorite filter = new OnmsFilterFavorite();
    filter.setUsername(userName);
    filter.setFilter(filterString);
    filter.setName(favoriteName);
    filter.setPage(page);
    sanitizeFavorite(filter);
    favoriteDao.save(filter);
    return filter;
}
Also used : OnmsFilterFavorite(org.opennms.netmgt.model.OnmsFilterFavorite)

Aggregations

OnmsFilterFavorite (org.opennms.netmgt.model.OnmsFilterFavorite)12 ModelAndView (org.springframework.web.servlet.ModelAndView)4 Test (org.junit.Test)3 Page (org.opennms.netmgt.model.OnmsFilterFavorite.Page)3 FilterFavoriteService (org.opennms.web.services.FilterFavoriteService)2 Before (org.junit.Before)1 DatabasePopulator (org.opennms.netmgt.dao.DatabasePopulator)1 DaoSupport (org.opennms.netmgt.dao.DatabasePopulator.DaoSupport)1 FilterFavoriteDao (org.opennms.netmgt.dao.api.FilterFavoriteDao)1