Search in sources :

Example 1 with RedirectView

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

the class AlarmDetailController method saveStickyMemo.

public ModelAndView saveStickyMemo(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);
        String stickyMemoBody = httpServletRequest.getParameter("stickyMemoBody");
        m_webAlarmRepository.updateStickyMemo(alarmId, stickyMemoBody, httpServletRequest.getRemoteUser());
        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)

Example 2 with RedirectView

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

the class AlarmDetailController method removeStickyMemo.

public ModelAndView removeStickyMemo(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.removeStickyMemo(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)

Example 3 with RedirectView

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

the class ChooseUeisController method handleRequestInternal.

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // Pull the notice from the session
    HttpSession session = request.getSession(true);
    Notification newNotice = (Notification) session.getAttribute("newNotice");
    // If the notice is not present in the session, redirect to the first page of the wizard
    if (newNotice == null) {
        return new ModelAndView(new RedirectView(NotificationWizardServlet.SOURCE_PAGE_NOTICES));
    }
    return new ModelAndView("/admin/notification/noticeWizard/chooseUeis", "model", createModel(newNotice));
}
Also used : HttpSession(javax.servlet.http.HttpSession) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) Notification(org.opennms.netmgt.config.notifications.Notification)

Example 4 with RedirectView

use of org.springframework.web.servlet.view.RedirectView in project ORCID-Source by ORCID.

the class OauthAuthorizeController method authorize.

@RequestMapping(value = { "/oauth/custom/authorize.json" }, method = RequestMethod.POST)
@ResponseBody
public RequestInfoForm authorize(HttpServletRequest request, HttpServletResponse response, @RequestBody OauthAuthorizeForm form) {
    RequestInfoForm requestInfoForm = (RequestInfoForm) request.getSession().getAttribute(REQUEST_INFO_FORM);
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    AuthorizationRequest authorizationRequest = (AuthorizationRequest) request.getSession().getAttribute("authorizationRequest");
    Map<String, String> requestParams = new HashMap<String, String>(authorizationRequest.getRequestParameters());
    Map<String, String> approvalParams = new HashMap<String, String>();
    // Add the persistent token information
    if (form.getApproved()) {
        requestParams.put(OAuth2Utils.USER_OAUTH_APPROVAL, "true");
        approvalParams.put(OAuth2Utils.USER_OAUTH_APPROVAL, "true");
    } else {
        requestParams.put(OAuth2Utils.USER_OAUTH_APPROVAL, "false");
        approvalParams.put(OAuth2Utils.USER_OAUTH_APPROVAL, "false");
    }
    requestParams.put(OrcidOauth2Constants.TOKEN_VERSION, OrcidOauth2Constants.PERSISTENT_TOKEN);
    // Check if the client have persistent tokens enabled
    requestParams.put(OrcidOauth2Constants.GRANT_PERSISTENT_TOKEN, "false");
    if (hasPersistenTokensEnabled(requestInfoForm.getClientId()))
        // Then check if the client granted the persistent token
        if (form.getPersistentTokenEnabled())
            requestParams.put(OrcidOauth2Constants.GRANT_PERSISTENT_TOKEN, "true");
    // strip /email/read-private scope if user has not consented
    if (requestInfoForm.containsEmailReadPrivateScope() && !form.isEmailAccessAllowed()) {
        requestInfoForm.removeEmailReadPrivateScope();
        requestParams.put(OrcidOauth2Constants.SCOPE_PARAM, requestInfoForm.getScopesAsString());
    }
    // Session status
    SimpleSessionStatus status = new SimpleSessionStatus();
    authorizationRequest.setRequestParameters(requestParams);
    // Authorization request model
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("authorizationRequest", authorizationRequest);
    // Approve
    RedirectView view = (RedirectView) authorizationEndpoint.approveOrDeny(approvalParams, model, status, auth);
    requestInfoForm.setRedirectUrl(view.getUrl());
    if (new HttpSessionRequestCache().getRequest(request, response) != null)
        new HttpSessionRequestCache().removeRequest(request, response);
    LOGGER.info("OauthConfirmAccessController form.getRedirectUri being sent to client browser: " + requestInfoForm.getRedirectUrl());
    return requestInfoForm;
}
Also used : AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) HashMap(java.util.HashMap) Authentication(org.springframework.security.core.Authentication) HttpSessionRequestCache(org.springframework.security.web.savedrequest.HttpSessionRequestCache) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestInfoForm(org.orcid.pojo.ajaxForm.RequestInfoForm) SimpleSessionStatus(org.springframework.web.bind.support.SimpleSessionStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with RedirectView

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

the class SettingsController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request) throws Exception {
    User user = securityService.getCurrentUser(request);
    // Redirect to music folder settings if admin.
    String view = user.isAdminRole() ? "musicFolderSettings" : "personalSettings";
    return new ModelAndView(new RedirectView(view));
}
Also used : User(org.libresonic.player.domain.User) 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)115 ModelAndView (org.springframework.web.servlet.ModelAndView)90 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)32 Test (org.junit.Test)25 HashMap (java.util.HashMap)20 View (org.springframework.web.servlet.View)18 Authentication (org.springframework.security.core.Authentication)14 AuthorizationRequest (org.springframework.security.oauth2.provider.AuthorizationRequest)13 Test (org.junit.jupiter.api.Test)9 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