Search in sources :

Example 51 with RedirectView

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

the class AlarmSeverityChangeController method handleRequestInternal.

/**
 * {@inheritDoc}
 *
 * Adjust the severity of the alarms specified in the POST and then redirect the client
 * to an appropriate URL for display.
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    // required parameter
    String[] alarmIdStrings = request.getParameterValues("alarm");
    String action = request.getParameter("actionCode");
    if (alarmIdStrings == null) {
        throw new MissingParameterException("alarm", new String[] { "alarm", "actionCode" });
    }
    if (action == null) {
        throw new MissingParameterException("actionCode", new String[] { "alarm", "actionCode" });
    }
    // convert the alarm id strings to ints
    int[] alarmIds = new int[alarmIdStrings.length];
    for (int i = 0; i < alarmIds.length; i++) {
        alarmIds[i] = WebSecurityUtils.safeParseInt(alarmIdStrings[i]);
    }
    if (action.equals(ESCALATE_ACTION)) {
        m_webAlarmRepository.escalateAlarms(alarmIds, request.getRemoteUser(), new Date());
    } else if (action.equals(CLEAR_ACTION)) {
        m_webAlarmRepository.clearAlarms(alarmIds, request.getRemoteUser(), new Date());
    } else {
        throw new ServletException("Unknown alarm severity action: " + action);
    }
    String redirectParms = request.getParameter("redirectParms");
    String redirect = request.getParameter("redirect");
    String viewName;
    if (redirect != null) {
        viewName = redirect;
    } else {
        viewName = (redirectParms == null || redirectParms == "" || redirectParms == "null" ? m_redirectView : m_redirectView + "?" + redirectParms);
    }
    RedirectView view = new RedirectView(viewName, true);
    return new ModelAndView(view);
}
Also used : ServletException(javax.servlet.ServletException) RedirectView(org.springframework.web.servlet.view.RedirectView) ModelAndView(org.springframework.web.servlet.ModelAndView) MissingParameterException(org.opennms.web.servlet.MissingParameterException) Date(java.util.Date)

Example 52 with RedirectView

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

the class AcknowledgeNotificationController method handleRequestInternal.

/**
 * {@inheritDoc}
 *
 * Acknowledge the notifications specified in the POST and then redirect the client
 * to an appropriate URL for display.
 */
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String[] required = { "notices" };
    String[] noticeIdStrings = request.getParameterValues("notices");
    if (noticeIdStrings == null) {
        throw new MissingParameterException("notices", required);
    }
    String currentUser = request.getParameter("curUser");
    if (currentUser == null) {
        currentUser = request.getRemoteUser();
    }
    List<Integer> noticeIds = new ArrayList<>();
    for (String noticeIdString : noticeIdStrings) {
        noticeIds.add(WebSecurityUtils.safeParseInt(noticeIdString));
    }
    List<Filter> filters = new ArrayList<>();
    filters.add(new NotificationIdListFilter(noticeIds.toArray(new Integer[0])));
    NotificationCriteria criteria = new NotificationCriteria(filters.toArray(new Filter[0]));
    m_webNotificationRepository.acknowledgeMatchingNotification(currentUser, new Date(), criteria);
    Notification[] notices = m_webNotificationRepository.getMatchingNotifications(criteria);
    request.setAttribute("notices", notices);
    String redirectParms = request.getParameter("redirectParms");
    String redirect = request.getParameter("redirect");
    String viewName;
    if (redirect != null) {
        viewName = redirect;
    } else {
        viewName = (redirectParms == null || redirectParms == "" || redirectParms == "null" ? m_redirectView : m_redirectView + "?" + redirectParms);
    }
    RedirectView view = new RedirectView(viewName, true);
    return new ModelAndView(view);
}
Also used : ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) Date(java.util.Date) Notification(org.opennms.web.notification.Notification) NotificationIdListFilter(org.opennms.web.notification.filter.NotificationIdListFilter) Filter(org.opennms.web.filter.Filter) NotificationIdListFilter(org.opennms.web.notification.filter.NotificationIdListFilter) NotificationCriteria(org.opennms.web.notification.filter.NotificationCriteria) RedirectView(org.springframework.web.servlet.view.RedirectView) MissingParameterException(org.opennms.web.servlet.MissingParameterException)

Example 53 with RedirectView

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

the class FlowExecutionExceptionResolver method resolveException.

@Override
public ModelAndView resolveException(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final Exception exception) {
    /*
         * Since FlowExecutionRepositoryException is a common ancestor to these exceptions and other
         * error cases we would likely want to hide from the user, it seems reasonable to check for
         * FlowExecutionRepositoryException.
         *
         * BadlyFormattedFlowExecutionKeyException is specifically ignored by this handler
         * because redirecting to the requested URI with this exception may cause an infinite
         * redirect loop (i.e. when invalid "execution" parameter exists as part of the query string
         */
    if (!(exception instanceof FlowExecutionRepositoryException) || exception instanceof BadlyFormattedFlowExecutionKeyException) {
        LOGGER.debug("Ignoring the received exception due to a type mismatch", exception);
        return null;
    }
    final String urlToRedirectTo = request.getRequestURI() + (request.getQueryString() != null ? '?' + request.getQueryString() : StringUtils.EMPTY);
    LOGGER.debug("Error getting flow information for URL [{}]", urlToRedirectTo, exception);
    final Map<String, Object> model = new HashMap<>();
    model.put(this.modelKey, StringEscapeUtils.escapeHtml4(exception.getMessage()));
    return new ModelAndView(new RedirectView(urlToRedirectTo), model);
}
Also used : FlowExecutionRepositoryException(org.springframework.webflow.execution.repository.FlowExecutionRepositoryException) HashMap(java.util.HashMap) BadlyFormattedFlowExecutionKeyException(org.springframework.webflow.execution.repository.BadlyFormattedFlowExecutionKeyException) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView)

Example 54 with RedirectView

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

the class AuthorizationEndpoint method getImplicitGrantResponse.

// We can grant a token and return it with implicit approval.
private ModelAndView getImplicitGrantResponse(AuthorizationRequest authorizationRequest) {
    try {
        TokenRequest tokenRequest = getOAuth2RequestFactory().createTokenRequest(authorizationRequest, "implicit");
        OAuth2Request storedOAuth2Request = getOAuth2RequestFactory().createOAuth2Request(authorizationRequest);
        OAuth2AccessToken accessToken = getAccessTokenForImplicitGrant(tokenRequest, storedOAuth2Request);
        if (accessToken == null) {
            throw new UnsupportedResponseTypeException("Unsupported response type: token");
        }
        return new ModelAndView(new RedirectView(appendAccessToken(authorizationRequest, accessToken), false, true, false));
    } catch (OAuth2Exception e) {
        return new ModelAndView(new RedirectView(getUnsuccessfulRedirect(authorizationRequest, e, true), false, true, false));
    }
}
Also used : OAuth2Request(org.springframework.security.oauth2.provider.OAuth2Request) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) TokenRequest(org.springframework.security.oauth2.provider.TokenRequest) ImplicitTokenRequest(org.springframework.security.oauth2.provider.implicit.ImplicitTokenRequest) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) UnsupportedResponseTypeException(org.springframework.security.oauth2.common.exceptions.UnsupportedResponseTypeException) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception)

Example 55 with RedirectView

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

the class AuthorizationEndpoint method handleException.

private ModelAndView handleException(Exception e, ServletWebRequest webRequest) throws Exception {
    ResponseEntity<OAuth2Exception> translate = getExceptionTranslator().translate(e);
    webRequest.getResponse().setStatus(translate.getStatusCode().value());
    if (e instanceof ClientAuthenticationException || e instanceof RedirectMismatchException) {
        return new ModelAndView(errorPage, Collections.singletonMap("error", translate.getBody()));
    }
    AuthorizationRequest authorizationRequest = null;
    try {
        authorizationRequest = getAuthorizationRequestForError(webRequest);
        String requestedRedirectParam = authorizationRequest.getRequestParameters().get(OAuth2Utils.REDIRECT_URI);
        String requestedRedirect = redirectResolver.resolveRedirect(requestedRedirectParam, getClientDetailsService().loadClientByClientId(authorizationRequest.getClientId()));
        authorizationRequest.setRedirectUri(requestedRedirect);
        String redirect = getUnsuccessfulRedirect(authorizationRequest, translate.getBody(), authorizationRequest.getResponseTypes().contains("token"));
        return new ModelAndView(new RedirectView(redirect, false, true, false));
    } catch (OAuth2Exception ex) {
        // response.
        return new ModelAndView(errorPage, Collections.singletonMap("error", translate.getBody()));
    }
}
Also used : ClientAuthenticationException(org.springframework.security.oauth2.common.exceptions.ClientAuthenticationException) UnapprovedClientAuthenticationException(org.springframework.security.oauth2.common.exceptions.UnapprovedClientAuthenticationException) AuthorizationRequest(org.springframework.security.oauth2.provider.AuthorizationRequest) RedirectMismatchException(org.springframework.security.oauth2.common.exceptions.RedirectMismatchException) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) OAuth2Exception(org.springframework.security.oauth2.common.exceptions.OAuth2Exception)

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