Search in sources :

Example 71 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project spring-framework by spring-projects.

the class ViewMethodReturnValueHandlerTests method returnViewRedirect.

@Test
public void returnViewRedirect() throws Exception {
    RedirectView redirectView = new RedirectView("testView");
    ModelMap redirectModel = new RedirectAttributesModelMap();
    this.mavContainer.setRedirectModel(redirectModel);
    MethodParameter param = createReturnValueParam("view");
    this.handler.handleReturnValue(redirectView, param, this.mavContainer, this.webRequest);
    assertSame(redirectView, this.mavContainer.getView());
    assertSame("Should have switched to the RedirectModel", redirectModel, this.mavContainer.getModel());
}
Also used : ModelMap(org.springframework.ui.ModelMap) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) RedirectView(org.springframework.web.servlet.view.RedirectView) RedirectAttributesModelMap(org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap) MethodParameter(org.springframework.core.MethodParameter) Test(org.junit.Test)

Example 72 with RedirectView

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

the class SigninController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse resp) throws Exception {
    logger.info("receive url path: " + request.getContextPath() + "," + request.getRequestURI() + ", " + request.getServletPath() + ", parameters: " + request.getQueryString());
    boolean failed = false;
    String message = null;
    String username = request.getParameter("name");
    if (username != null) {
        username = username.trim().toLowerCase();
        //find the user from the system cache
        AppUser appUser = this.frameworkContext.getAuth().findUserByName(username);
        //sign in process
        boolean authed = this.frameworkContext.getAuth().login(appUser, request);
        if (//display
        authed) {
            String view = getLoginSuccessView();
            //if admin user, and setup not done yet, send to setup.
            if (appUser.isAdminUser() && !frameworkContext.getMyperfConfig().isConfigured())
                view = this.getSetupView();
            else if (!appUser.isAdminUser() && !appUser.isVerified()) {
                failed = true;
                message = "Your signup has not been confirmed by any administrator user yet.";
            }
            if (!failed) {
                logger.info(appUser.getName() + " login, redirect to " + view);
                return new ModelAndView(new RedirectView(view));
            }
        } else //if(appUser!=null && appUser.match(request.getParameter("pd"))
        {
            failed = true;
            message = DEFAULT_ERROR;
        }
    }
    //if(username!=null)
    //not authenticated? Try again
    //TODO add retry count
    long server_ts = System.currentTimeMillis();
    int seed = (int) (Math.random() * Integer.MAX_VALUE);
    ModelAndView mv = new ModelAndView(getLoginFormView());
    mv.addObject("name", username);
    if (failed)
        mv.addObject("message", message);
    mv.addObject("help_key", "start");
    mv.addObject("server_ts", server_ts);
    //ars: authentication random seed
    mv.addObject("ars", seed);
    mv.addObject("setup", this.frameworkContext.getMyperfConfig().isConfigured() ? 1 : 0);
    //add store them in session
    request.getSession(true).setAttribute(AppUser.SERVER_TS, new Long(server_ts));
    request.getSession().setAttribute(AppUser.RANDOM_SEED, new Integer(seed));
    return mv;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView)

Example 73 with RedirectView

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

the class MyPerfBaseController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) throws Exception {
    setupDebug(req);
    boolean debug = this.isDebug(req);
    if (debug)
        logger.info("receive url path: " + req.getContextPath() + "," + req.getRequestURI() + ", " + req.getServletPath() + ", parameters: " + req.getQueryString());
    AppUser user = retrieveAppUser(req);
    if (//check if user valid when require login
    this.requireLogin && user == null) {
        if (this.nosessView != null)
            return new ModelAndView(new RedirectView(nosessView));
        return respondFailure("Session expired. Please relogin and try again.", req);
    } else if (this.requireLogin && !user.isVerified()) {
        //TODO use a message view
        return this.respondFailure("New user request has not been verified by administrator yet. Please contact administrator by email " + this.frameworkContext.getMyperfConfig().getAdminEmail() + ".", req);
    }
    return handleRequestImpl(req, resp);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) AppUser(com.yahoo.dba.perf.myperf.common.AppUser)

Example 74 with RedirectView

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

the class PerfController method handleRequestImpl.

//private MyPerfContext frameworkContext;
@Override
protected ModelAndView handleRequestImpl(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String pg = request.getParameter("pg");
    String tgtPage = pg;
    if (tgtPage != null)
        tgtPage = tgtPage.trim().toLowerCase();
    if (tgtPage == null || tgtPage.isEmpty() || (!pageMap.containsKey(tgtPage) && !noSessionPageMap.containsKey(tgtPage)))
        tgtPage = this.defaultView;
    else if (pageMap.containsKey(tgtPage) && !WebAppUtil.hasValidSession(request)) {
        return new ModelAndView(new RedirectView(this.getNosessView()));
    } else if (pageMap.containsKey(tgtPage)) {
        tgtPage = pageMap.get(tgtPage);
    } else
        tgtPage = noSessionPageMap.get(tgtPage);
    ModelAndView mv = new ModelAndView(tgtPage);
    if (WebAppUtil.hasValidSession(request)) {
        mv.addObject("mydbs", this.frameworkContext.getDbInfoManager().listDbsByUserInfo(WebAppUtil.findUserFromRequest(request), retrieveAppUser(request).isRestrictedUser()));
        mv.addObject("mydbSize", this.frameworkContext.getDbInfoManager().getMyDatabases(WebAppUtil.findUserFromRequest(request), retrieveAppUser(request).isRestrictedUser()).size());
    } else {
        mv.addObject("mydbs", this.frameworkContext.getDbInfoManager().getClusters().keySet());
        mv.addObject("mydbSize", 0);
    }
    mv.addObject("hours", HOURS);
    mv.addObject("dbMap", this.frameworkContext.getDbInfoManager().getClusters());
    mv.addObject("help_key", pg);
    mv.addObject("config", this.frameworkContext.getMyperfConfig());
    mv.addObject("scanner_running", this.frameworkContext.getAutoScanner().isRunning());
    mv.addObject("setup", this.frameworkContext.getMyperfConfig().isConfigured() ? 1 : 0);
    if ("sp".equals(pg) || "scatterplot".equals(pg) || "m".equals(pg) || "metrics".equalsIgnoreCase(pg))
        mv.addObject("udms", this.frameworkContext.getMetricsList());
    return mv;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView)

Example 75 with RedirectView

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

the class AlarmDetailController method removeJournalMemo.

public ModelAndView removeJournalMemo(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
    int alarmId;
    String alarmIdString = "";
    // Try to parse alarm ID from string to integer
    try {
        alarmIdString = httpServletRequest.getParameter("alarmId");
        alarmId = Integer.parseInt(alarmIdString);
        m_webAlarmRepository.removeReductionKeyMemo(alarmId);
        return new ModelAndView(new RedirectView("detail.htm", true), "id", alarmId);
    } catch (NumberFormatException e) {
        logger.error("Could not parse alarm ID '{}' to integer.", httpServletRequest.getParameter("alarmId"));
        throw new ServletException("Could not parse alarm ID " + httpServletRequest.getParameter("alarmId") + " to integer.");
    }
}
Also used : ServletException(javax.servlet.ServletException) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView)

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