/** * Set an alternate redirect status code such as * {@link HttpStatus#TEMPORARY_REDIRECT} or * {@link HttpStatus#PERMANENT_REDIRECT}. */ public void setStatusCode(HttpStatus statusCode) { Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code"); this.statusCode = statusCode; }
/** * Set the default HTTP Status to use for redirects. * <p>By default this is {@link HttpStatus#SEE_OTHER}. * @param status the 3xx redirect status to use */ public void setRedirectStatus(HttpStatus status) { Assert.notNull(status, "Property 'redirectStatus' is required"); Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code"); this.redirectStatus = status; }
/** * Set the specific redirect 3xx status code to use. * <p>If not set, {@link org.springframework.web.servlet.view.RedirectView} * will select {@code HttpStatus.MOVED_TEMPORARILY (302)} by default. */ public RedirectViewControllerRegistration setStatusCode(HttpStatus statusCode) { Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code"); this.redirectView.setStatusCode(statusCode); return this; }
/** * Set the default HTTP Status to use for redirects. * <p>By default this is {@link HttpStatus#SEE_OTHER}. * @param status the 3xx redirect status to use */ public void setRedirectStatus(HttpStatus status) { Assert.notNull(status, "Property 'redirectStatus' is required"); Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code"); this.redirectStatus = status; }
/** * Return the name of the view to delegate to, or {@code null} if using a * View instance. */ @Nullable public String getViewName() { if (this.view instanceof String) { String viewName = (String) this.view; if (getStatusCode() != null && getStatusCode().is3xxRedirection()) { return viewName.startsWith("redirect:") ? viewName : "redirect:" + viewName; } else { return viewName; } } return null; }
/** * Set the specific redirect 3xx status code to use. * <p>If not set, {@link org.springframework.web.servlet.view.RedirectView} * will select {@code HttpStatus.MOVED_TEMPORARILY (302)} by default. */ public RedirectViewControllerRegistration setStatusCode(HttpStatus statusCode) { Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code"); this.redirectView.setStatusCode(statusCode); return this; }
/** * Return the name of the view to delegate to, or {@code null} if using a * View instance. */ @Nullable public String getViewName() { if (this.view instanceof String) { String viewName = (String) this.view; if (getStatusCode() != null && getStatusCode().is3xxRedirection()) { return viewName.startsWith("redirect:") ? viewName : "redirect:" + viewName; } else { return viewName; } } return null; }
if (getStatusCode().is3xxRedirection()) { request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, getStatusCode());
if (getStatusCode().is3xxRedirection()) { request.setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, getStatusCode());
HttpStatus status = extractStatus(response); if (status != null) { if (status.is3xxRedirection()) { return URI_REDIRECTION;
/** * Creates a {@code uri} tag based on the URI of the given {@code exchange}. Uses the * {@link HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE} best matching pattern if * available. Falling back to {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND} * for 404 responses, {@code root} for requests with no path info, and {@code UNKNOWN} * for all other requests. * @param exchange the exchange * @return the uri tag derived from the exchange */ public static Tag uri(ServerWebExchange exchange) { PathPattern pathPattern = exchange .getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); if (pathPattern != null) { return Tag.of("uri", pathPattern.getPatternString()); } HttpStatus status = exchange.getResponse().getStatusCode(); if (status != null) { if (status.is3xxRedirection()) { return URI_REDIRECTION; } if (status == HttpStatus.NOT_FOUND) { return URI_NOT_FOUND; } } String path = getPathInfo(exchange); if (path.isEmpty()) { return URI_ROOT; } return URI_UNKNOWN; }
/** * Creates an {@code outcome} tag based on the response status of the given * {@code exchange}. * @param exchange the exchange * @return the outcome tag derived from the response status * @since 2.1.0 */ public static Tag outcome(ServerWebExchange exchange) { HttpStatus status = exchange.getResponse().getStatusCode(); if (status != null) { if (status.is1xxInformational()) { return OUTCOME_INFORMATIONAL; } if (status.is2xxSuccessful()) { return OUTCOME_SUCCESS; } if (status.is3xxRedirection()) { return OUTCOME_REDIRECTION; } if (status.is4xxClientError()) { return OUTCOME_CLIENT_ERROR; } return OUTCOME_SERVER_ERROR; } return OUTCOME_UNKNOWN; }
/** * Set the default HTTP Status to use for redirects. * <p>By default this is {@link HttpStatus#SEE_OTHER}. * @param status the 3xx redirect status to use */ public void setRedirectStatus(HttpStatus status) { Assert.notNull(status, "Property 'redirectStatus' is required"); Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code"); this.redirectStatus = status; }
/** * Set an alternate redirect status code such as * {@link HttpStatus#TEMPORARY_REDIRECT} or * {@link HttpStatus#PERMANENT_REDIRECT}. */ public void setStatusCode(HttpStatus statusCode) { Assert.notNull(statusCode, "HttpStatus must not be null"); Assert.isTrue(statusCode.is3xxRedirection(), "Must be a redirection (3xx status code)"); this.statusCode = statusCode; }
/** * Set the default HTTP Status to use for redirects. * <p>By default this is {@link HttpStatus#SEE_OTHER}. * @param status the 3xx redirect status to use */ public void setRedirectStatus(HttpStatus status) { Assert.notNull(status, "Property 'redirectStatus' is required"); Assert.isTrue(status.is3xxRedirection(), "Not a redirect status code"); this.redirectStatus = status; }
/** * Set the specific redirect 3xx status code to use. * <p>If not set, {@link org.springframework.web.servlet.view.RedirectView} * will select {@code HttpStatus.MOVED_TEMPORARILY (302)} by default. */ public RedirectViewControllerRegistration setStatusCode(HttpStatus statusCode) { Assert.isTrue(statusCode.is3xxRedirection(), "Not a redirect status code"); this.redirectView.setStatusCode(statusCode); return this; }
private static boolean isWarn(Integer statusCode) { return HttpStatus.valueOf(statusCode).is3xxRedirection() || HttpStatus.valueOf(statusCode).is4xxClientError(); }
@Override public boolean shouldFilter() { RequestContext ctx = RequestContext.getCurrentContext(); int statusCode = ctx.getResponseStatusCode(); return HttpStatus.valueOf(statusCode).is3xxRedirection(); }
@Test public void testNoAuth() throws Exception { // set up the object under test GeoServerKeycloakFilter filter = new GeoServerKeycloakFilter(); filter.initializeFromConfig(config); // set up the test inputs when(response.getStatus()).thenReturn(HttpStatus.MOVED_PERMANENTLY.value()); // run the test filter.doFilter(request, response, chain); // simulate execution of the AEP ArgumentCaptor<AuthenticationEntryPoint> aep = ArgumentCaptor.forClass(AuthenticationEntryPoint.class); verify(request).setAttribute(eq(AEP_HEADER), aep.capture()); aep.getValue().commence(request, response, null); // check the results verify(chain).doFilter(request, response); ArgumentCaptor<Integer> status = ArgumentCaptor.forClass(Integer.class); verify(response).setStatus(status.capture()); assertTrue(HttpStatus.valueOf(status.getValue()).is3xxRedirection()); verify(response) .setHeader( eq(HttpHeaders.LOCATION), and(startsWith(OPENID_URL), contains(CLIENT_ID))); }
/** * @param status * @param translatableMessage */ public RestMessage(HttpStatus status, TranslatableMessage message) { super(); this.message = message.translate(Common.getTranslations()); if(status.is1xxInformational()||status.is2xxSuccessful()) this.level = RestMessageLevel.INFORMATION; else if(status.is3xxRedirection()) this.level = RestMessageLevel.WARNING; else if(status.is4xxClientError() || status.is5xxServerError()) this.level = RestMessageLevel.ERROR; this.status = status; }