Search in sources :

Example 31 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class HomeController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    User user = securityService.getCurrentUser(request);
    if (user.isAdminRole() && settingsService.isGettingStartedEnabled()) {
        return new ModelAndView(new RedirectView("gettingStarted.view"));
    }
    int listOffset = getIntParameter(request, "listOffset", 0);
    AlbumListType listType = AlbumListType.fromId(getStringParameter(request, "listType"));
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    if (listType == null) {
        listType = userSettings.getDefaultAlbumList();
    }
    MusicFolder selectedMusicFolder = settingsService.getSelectedMusicFolder(user.getUsername());
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername(), selectedMusicFolder == null ? null : selectedMusicFolder.getId());
    Map<String, Object> map = new HashMap<>();
    List<Album> albums = Collections.emptyList();
    switch(listType) {
        case HIGHEST:
            albums = getHighestRated(listOffset, LIST_SIZE, musicFolders);
            break;
        case FREQUENT:
            albums = getMostFrequent(listOffset, LIST_SIZE, musicFolders);
            break;
        case RECENT:
            albums = getMostRecent(listOffset, LIST_SIZE, musicFolders);
            break;
        case NEWEST:
            albums = getNewest(listOffset, LIST_SIZE, musicFolders);
            break;
        case STARRED:
            albums = getStarred(listOffset, LIST_SIZE, user.getUsername(), musicFolders);
            break;
        case RANDOM:
            albums = getRandom(LIST_SIZE, musicFolders);
            break;
        case ALPHABETICAL:
            albums = getAlphabetical(listOffset, LIST_SIZE, true, musicFolders);
            break;
        case DECADE:
            List<Integer> decades = createDecades();
            map.put("decades", decades);
            int decade = getIntParameter(request, "decade", decades.get(0));
            map.put("decade", decade);
            albums = getByYear(listOffset, LIST_SIZE, decade, decade + 9, musicFolders);
            break;
        case GENRE:
            List<Genre> genres = mediaFileService.getGenres(true);
            map.put("genres", genres);
            if (!genres.isEmpty()) {
                String genre = getStringParameter(request, "genre", genres.get(0).getName());
                map.put("genre", genre);
                albums = getByGenre(listOffset, LIST_SIZE, genre, musicFolders);
            }
            break;
        default:
            break;
    }
    map.put("albums", albums);
    map.put("welcomeTitle", settingsService.getWelcomeTitle());
    map.put("welcomeSubtitle", settingsService.getWelcomeSubtitle());
    map.put("welcomeMessage", settingsService.getWelcomeMessage());
    map.put("isIndexBeingCreated", mediaScannerService.isScanning());
    map.put("musicFoldersExist", !settingsService.getAllMusicFolders().isEmpty());
    map.put("listType", listType.getId());
    map.put("listSize", LIST_SIZE);
    map.put("coverArtSize", CoverArtScheme.MEDIUM.getSize());
    map.put("listOffset", listOffset);
    map.put("musicFolder", selectedMusicFolder);
    map.put("listReloadDelay", userSettings.getListReloadDelay());
    return new ModelAndView("home", "model", map);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 32 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project libresonic by Libresonic.

the class GettingStartedController method gettingStarted.

@RequestMapping(method = RequestMethod.GET)
public ModelAndView gettingStarted(HttpServletRequest request) {
    if (request.getParameter("hide") != null) {
        settingsService.setGettingStartedEnabled(false);
        settingsService.save();
        return new ModelAndView(new RedirectView("home.view"));
    }
    Map<String, Object> map = new HashMap<>();
    ;
    map.put("runningAsRoot", "root".equals(System.getProperty("user.name")));
    return new ModelAndView("gettingStarted", "model", map);
}
Also used : HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project opennms by OpenNMS.

the class CategoryController method handleRequestInternal.

/**
 * {@inheritDoc}
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String removeCategoryIdString = request.getParameter("removeCategoryId");
    String newCategoryName = request.getParameter("newCategoryName");
    String categoryIdString = request.getParameter("categoryid");
    String editString = request.getParameter("edit");
    String nodeIdString = request.getParameter("node");
    RedirectView redirect = new RedirectView("/admin/categories.htm", true);
    // delete a category
    if (removeCategoryIdString != null) {
        m_adminCategoryService.removeCategory(removeCategoryIdString);
        return new ModelAndView(redirect);
    }
    // add a category
    if (newCategoryName != null) {
        OnmsCategory cat = m_adminCategoryService.getCategoryWithName(newCategoryName);
        if (cat == null) {
            m_adminCategoryService.addNewCategory(newCategoryName);
        }
        /*
             * We could be smart and take the user straight to the edit page
             * for this new category, which would be great, however it's
             * not so great if the site has a huge number of available
             * category and they need to edit category member nodes
             * from the node pages.  So, we don't do it.
             */
        return new ModelAndView(redirect);
    }
    // high-level category edit (add or remove nodes from a category)
    if (categoryIdString != null && editString != null) {
        String editAction = request.getParameter("action");
        if (editAction != null) {
            String[] toAdd = request.getParameterValues("toAdd");
            String[] toDelete = request.getParameterValues("toDelete");
            m_adminCategoryService.performEdit(categoryIdString, editAction, toAdd, toDelete);
            ModelAndView modelAndView = new ModelAndView(redirect);
            modelAndView.addObject("categoryid", categoryIdString);
            modelAndView.addObject("edit", "edit");
            return modelAndView;
        }
        EditModel model = m_adminCategoryService.findCategoryAndAllNodes(categoryIdString);
        return new ModelAndView("/admin/editCategory", "model", model);
    }
    // if we don't have an edit string, we just show the category
    if (categoryIdString != null) {
        return new ModelAndView("/admin/showCategory", "model", m_adminCategoryService.getCategory(categoryIdString));
    }
    // if we have a nodeId and we're in edit mode, edit the categories for a specific node
    if (nodeIdString != null && editString != null) {
        String editAction = request.getParameter("action");
        // if we've specified an action, perform that action
        if (editAction != null) {
            String[] toAdd = request.getParameterValues("toAdd");
            String[] toDelete = request.getParameterValues("toDelete");
            m_adminCategoryService.performNodeEdit(nodeIdString, editAction, toAdd, toDelete);
            ModelAndView modelAndView = new ModelAndView(redirect);
            modelAndView.addObject("node", nodeIdString);
            modelAndView.addObject("edit", "edit");
            return modelAndView;
        }
        // otherwise, display the edit page for adding and removing categories from a node
        NodeEditModel model = m_adminCategoryService.findNodeCategories(nodeIdString);
        return new ModelAndView("/admin/editNodeCategories", "model", model);
    }
    // otherwise, just show the category editor
    List<OnmsCategory> sortedCategories = m_adminCategoryService.findAllCategories();
    List<String> surveillanceCategories = getAllSurveillanceViewCategories();
    ModelAndView modelAndView = new ModelAndView("/admin/categories");
    modelAndView.addObject("categories", sortedCategories);
    modelAndView.addObject("surveillanceCategories", surveillanceCategories);
    // new ModelAndView("/admin/categories", "categories", sortedCategories);
    return modelAndView;
}
Also used : OnmsCategory(org.opennms.netmgt.model.OnmsCategory) NodeEditModel(org.opennms.web.svclayer.support.DefaultAdminCategoryService.NodeEditModel) NodeEditModel(org.opennms.web.svclayer.support.DefaultAdminCategoryService.NodeEditModel) EditModel(org.opennms.web.svclayer.support.DefaultAdminCategoryService.EditModel) RedirectView(org.springframework.web.servlet.view.RedirectView) ModelAndView(org.springframework.web.servlet.ModelAndView)

Example 34 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project cas by apereo.

the class CasSecurityInterceptor method postHandle.

@Override
public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final ModelAndView modelAndView) {
    if (modelAndView != null && StringUtils.isNotBlank(request.getQueryString()) && request.getQueryString().contains(CasProtocolConstants.PARAMETER_TICKET)) {
        final RedirectView v = new RedirectView(request.getRequestURL().toString());
        v.setExposeModelAttributes(false);
        v.setExposePathVariables(false);
        modelAndView.setView(v);
    }
}
Also used : RedirectView(org.springframework.web.servlet.view.RedirectView)

Example 35 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project cas by apereo.

the class OAuth20AuthorizationCodeAuthorizationResponseBuilder method build.

@Override
public View build(final J2EContext context, final String clientId, final AccessTokenRequestDataHolder holder) {
    final OAuthCode code = oAuthCodeFactory.create(holder.getService(), holder.getAuthentication(), holder.getTicketGrantingTicket(), holder.getScopes());
    LOGGER.debug("Generated OAuth code: [{}]", code);
    this.ticketRegistry.addTicket(code);
    final String state = holder.getAuthentication().getAttributes().get(OAuth20Constants.STATE).toString();
    final String nonce = holder.getAuthentication().getAttributes().get(OAuth20Constants.NONCE).toString();
    final String redirectUri = context.getRequestParameter(OAuth20Constants.REDIRECT_URI);
    LOGGER.debug("Authorize request verification successful for client [{}] with redirect uri [{}]", clientId, redirectUri);
    String callbackUrl = redirectUri;
    callbackUrl = CommonHelper.addParameter(callbackUrl, OAuth20Constants.CODE, code.getId());
    if (StringUtils.isNotBlank(state)) {
        callbackUrl = CommonHelper.addParameter(callbackUrl, OAuth20Constants.STATE, state);
    }
    if (StringUtils.isNotBlank(nonce)) {
        callbackUrl = CommonHelper.addParameter(callbackUrl, OAuth20Constants.NONCE, nonce);
    }
    LOGGER.debug("Redirecting to URL [{}]", callbackUrl);
    return new RedirectView(callbackUrl);
}
Also used : RedirectView(org.springframework.web.servlet.view.RedirectView) OAuthCode(org.apereo.cas.ticket.code.OAuthCode)

Aggregations

RedirectView (org.springframework.web.servlet.view.RedirectView)86 ModelAndView (org.springframework.web.servlet.ModelAndView)70 Test (org.junit.Test)34 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)19 HashMap (java.util.HashMap)18 View (org.springframework.web.servlet.View)17 Authentication (org.springframework.security.core.Authentication)14 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)13 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)9 OAuth2AccessToken (org.springframework.security.oauth2.common.OAuth2AccessToken)8 TokenRequest (org.springframework.security.oauth2.provider.TokenRequest)8 DefaultUserApprovalHandler (org.springframework.security.oauth2.provider.approval.DefaultUserApprovalHandler)8 ServletException (javax.servlet.ServletException)7 RequestInfoForm (org.orcid.pojo.ajaxForm.RequestInfoForm)7 DefaultOAuth2AccessToken (org.springframework.security.oauth2.common.DefaultOAuth2AccessToken)7 TokenGranter (org.springframework.security.oauth2.provider.TokenGranter)7 Principal (org.apereo.cas.authentication.principal.Principal)6 OAuthRegisteredService (org.apereo.cas.support.oauth.services.OAuthRegisteredService)6 CasProfile (org.pac4j.cas.profile.CasProfile)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6