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);
}
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);
}
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);
}
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));
}
}
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()));
}
}
Aggregations