Search in sources :

Example 21 with RedirectView

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

the class OidcCallbackAuthorizeViewResolver method resolve.

@Override
public ModelAndView resolve(final J2EContext ctx, final ProfileManager manager, final String url) {
    final Set<String> prompt = authorizationRequestSupport.getOidcPromptFromAuthorizationRequest(url);
    if (prompt.contains(OidcConstants.PROMPT_NONE)) {
        if (manager.get(true) != null) {
            return new ModelAndView(url);
        }
        final Map<String, String> model = new HashMap<>();
        model.put(OAuthConstants.ERROR, OidcConstants.LOGIN_REQUIRED);
        return new ModelAndView(new MappingJackson2JsonView(), model);
    }
    return new ModelAndView(new RedirectView(url));
}
Also used : HashMap(java.util.HashMap) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) MappingJackson2JsonView(org.springframework.web.servlet.view.json.MappingJackson2JsonView)

Example 22 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project mysql_perf_analyzer by yahoo.

the class LogoutController method handleRequestImpl.

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    HttpSession sess = req.getSession();
    //do we have session
    if (sess != null) {
        UserDBConnections conns = UserDBConnections.class.cast(sess.getAttribute("UserDBConnections"));
        sess.removeAttribute("UserDBConnections");
        sess.invalidate();
        //make it async. 
        new Thread(new LogoutCleaner(conns)).start();
    //TODO Add the thread handle for central process
    }
    ModelAndView mv = new ModelAndView(new RedirectView(this.getNosessView()));
    return mv;
}
Also used : HttpSession(javax.servlet.http.HttpSession) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) UserDBConnections(com.yahoo.dba.perf.myperf.db.UserDBConnections)

Example 23 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project mysql_perf_analyzer by yahoo.

the class UdmController method handleRequestImpl.

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    String message = "OK";
    String cmd = req.getParameter("cmd");
    boolean isValid = true;
    UserDefinedMetrics udm = null;
    logger.info("receive cmd " + cmd + ", url " + req.getQueryString());
    //it a form request
    if ((cmd == null || cmd.isEmpty()) && !WebAppUtil.hasValidSession(req)) {
        return new ModelAndView(new RedirectView(nosessView));
    }
    //first session check
    boolean isSessionValid = WebAppUtil.hasValidSession(req);
    if (!isSessionValid)
        return this.respondFailure("session timeout. Please logout and re-login.", req);
    AppUser appUser = AppUser.class.cast(req.getSession().getAttribute(AppUser.SESSION_ATTRIBUTE));
    ModelAndView mv = null;
    //By default, just display the page
    if (//or any invalid command
    cmd == null || cmd.isEmpty())
        message = null;
    if ("test".equals(cmd) || "publish".equals(cmd)) {
        if (appUser.isAdminUser())
            return this.processNewUDM(req, resp);
        else
            return this.respondFailure("Non admin user is not allowed to add UDM", req);
    } else if ("test_alert".equals(cmd) || "publish_alert".equals(cmd)) {
        if (appUser.isAdminUser())
            return this.processNewAlert(req, resp);
        else
            return this.respondFailure("Non admin user is not allowed to add UDM", req);
    } else if (//display
    "udm_detail".equalsIgnoreCase(cmd)) {
        String name = req.getParameter("name");
        udm = this.frameworkContext.getMetricsDef().getUdmManager().getUDMByName(name);
        if (udm != null) {
            mv = new ModelAndView(this.jsonView);
            String res = "{\"resp\":{\"status\": 0, \"message\":\"OK\", \"udm\": " + udm.toJSON(true) + "}}";
            //logger.info("UDM detail: "+res);
            mv.addObject("json_result", res);
            return mv;
        } else
            return this.respondFailure("UDM " + name + " not found", req);
    } else if (//display
    "alert_detail".equalsIgnoreCase(cmd)) {
        String name = req.getParameter("name");
        AlertDefinition alert = this.frameworkContext.getMetricsDef().getUdmManager().getAlertByName(name);
        if (alert != null) {
            mv = new ModelAndView(this.jsonView);
            String res = "{\"resp\":{\"status\": 0, \"message\":\"OK\", \"alert\": " + alert.toJSON(true) + "}}";
            //logger.info("UDM detail: "+res);
            mv.addObject("json_result", res);
            return mv;
        } else
            return this.respondFailure("ALERT " + name + " not found", req);
    } else if (//display
    "udmdb_detail".equalsIgnoreCase(cmd))
        return processUDMDBDetail(req, resp);
    else if (//display
    "udmdb_update".equalsIgnoreCase(cmd))
        return processUDMDBUpdate(req, resp, appUser);
    else if (//display
    "alertdb_update".equalsIgnoreCase(cmd))
        return this.processAlertDBUpdate(req, resp, appUser);
    mv = new ModelAndView(this.formView);
    //udm list
    List<String> udms = new ArrayList<String>();
    for (Map.Entry<String, UserDefinedMetrics> e : this.frameworkContext.getMetricsDef().getUdmManager().getUdms().entrySet()) {
        udms.add(e.getKey());
    }
    mv.addObject("udms", udms);
    //alerts
    List<String> alerts = new ArrayList<String>();
    for (Map.Entry<String, AlertDefinition> e : this.frameworkContext.getMetricsDef().getUdmManager().getAlerts().entrySet()) {
        alerts.add(e.getKey());
    }
    mv.addObject("alerts", alerts);
    //predefined
    Map<String, String> predefined = new TreeMap<String, String>();
    String[] predefinedGroups = this.frameworkContext.getMetricsDef().getGroupNames();
    for (String gname : predefinedGroups) {
        MetricsGroup g = this.frameworkContext.getMetricsDef().getGroupByName(gname);
        List<MetricsGroup> subGroups = g.getSubGroups();
        if (subGroups != null && subGroups.size() > 0) {
            for (MetricsGroup subG : subGroups) predefined.put(gname + "." + subG.getGroupName(), subG.isAuto() ? "y" : "n");
        } else
            predefined.put(gname, g.isAuto() ? "y" : "n");
    }
    mv.addObject("predefined", predefined);
    if (WebAppUtil.hasValidSession(req)) {
        mv.addObject("mydbs", this.frameworkContext.getDbInfoManager().listDbsByUserInfo(WebAppUtil.findUserFromRequest(req), retrieveAppUser(req).isRestrictedUser()));
        mv.addObject("mydbSize", this.frameworkContext.getDbInfoManager().getMyDatabases(WebAppUtil.findUserFromRequest(req), retrieveAppUser(req).isRestrictedUser()).size());
    } else {
        mv.addObject("mydbs", this.frameworkContext.getDbInfoManager().getClusters().keySet());
        mv.addObject("mydbSize", 0);
    }
    mv.addObject("dbMap", this.frameworkContext.getDbInfoManager().getClusters());
    mv.addObject("help_key", "udm");
    if (!isValid && message != null)
        mv.addObject("message", message);
    else if (message != null)
        mv.addObject("okmessage", message);
    if (cmd != null)
        mv.addObject("cmd", cmd);
    mv.addObject("u", appUser);
    return mv;
}
Also used : UserDefinedMetrics(com.yahoo.dba.perf.myperf.common.UserDefinedMetrics) ModelAndView(org.springframework.web.servlet.ModelAndView) ArrayList(java.util.ArrayList) AppUser(com.yahoo.dba.perf.myperf.common.AppUser) TreeMap(java.util.TreeMap) MetricsGroup(com.yahoo.dba.perf.myperf.common.MetricsGroup) RedirectView(org.springframework.web.servlet.view.RedirectView) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) AlertDefinition(com.yahoo.dba.perf.myperf.common.AlertDefinition)

Example 24 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project mysql_perf_analyzer by yahoo.

the class UserController method handleRequestImpl.

@Override
protected ModelAndView handleRequestImpl(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    //user action src
    String actionSrc = req.getParameter("a");
    //only "reset" and "new" allowed no session
    if (!"reset".equalsIgnoreCase(actionSrc) && !"new".equals(actionSrc) && !WebAppUtil.hasValidSession(req)) {
        return new ModelAndView(new RedirectView(nosessView));
    }
    AppUser appUser = AppUser.class.cast(req.getSession().getAttribute(AppUser.SESSION_ATTRIBUTE));
    //self signup
    if (appUser == null && "new".equalsIgnoreCase(actionSrc)) {
        String name = req.getParameter("name");
        //form
        if (name == null || name.isEmpty())
            return this.showSelfSignupForm(req);
        //signup
        return this.handleSelfSignup(req);
    }
    //password reset, form and action
    if ("reset".equalsIgnoreCase(actionSrc))
        return handleReset(req);
    //retrieve a user list
    if (appUser != null && appUser.isAdminUser() && "userlist".equalsIgnoreCase(actionSrc))
        return this.retrieveUserList(req);
    //retrieve all users with detail
    if (appUser != null && appUser.isAdminUser() && "listalldetails".equalsIgnoreCase(actionSrc))
        return this.listAllUsers(req);
    //retrieve new user list
    if (appUser != null && appUser.isAdminUser() && "newuserlist".equalsIgnoreCase(actionSrc))
        return this.retrieveNewUserList(req);
    //retrieve a user info
    if (appUser != null && appUser.isAdminUser() && "show".equalsIgnoreCase(actionSrc))
        return this.retrieveUserInfo(req);
    //for admin to create a new user
    if (appUser != null && appUser.isAdminUser() && "new".equalsIgnoreCase(actionSrc)) {
        return handleCreateUser(req);
    }
    //confirm a new user
    if (appUser != null && appUser.isAdminUser() && "confirm".equalsIgnoreCase(actionSrc)) {
        return this.handleConfirmNewUser(req);
    }
    //delete a user
    if (appUser != null && appUser.isAdminUser() && "delete".equalsIgnoreCase(actionSrc)) {
        return this.handleDelete(req);
    }
    //change privilege
    if (appUser != null && appUser.isAdminUser() && "otherpriv".equalsIgnoreCase(actionSrc)) {
        return this.handleChangePrivilege(req);
    }
    if (appUser != null && ("selfpwd".equals(actionSrc) || (appUser.isAdminUser() && "otherpwd".equals(actionSrc)))) {
        return this.handleChangePwd(req);
    }
    if (appUser != null && ("selfemail".equals(actionSrc) || (appUser.isAdminUser() && "otheremail".equals(actionSrc)))) {
        return this.handleChangeEmail(req);
    }
    //anything else except display form is not valid
    if (appUser == null || (actionSrc != null && !actionSrc.isEmpty())) {
        return new ModelAndView(new RedirectView(nosessView));
    }
    int status = Constants.STATUS_OK;
    String message = "";
    ModelAndView mv = new ModelAndView(this.getFormView());
    mv.addObject("userInfo", appUser);
    mv.addObject("status", status);
    mv.addObject("message", message);
    mv.addObject("a", STATE_MANAGED_ACTION);
    appendUserListToModel(req, mv);
    mv.addObject("help_key", "account");
    return mv;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView)

Example 25 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)

Aggregations

RedirectView (org.springframework.web.servlet.view.RedirectView)79 ModelAndView (org.springframework.web.servlet.ModelAndView)68 Test (org.junit.Test)34 HashMap (java.util.HashMap)18 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)17 View (org.springframework.web.servlet.View)16 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