use of org.springframework.web.context.request.ServletWebRequest in project engine by craftercms.
the class StaticAssetsRequestHandler method handleRequest.
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
checkAndPrepare(request, response, true);
SiteContext siteContext = SiteContext.getCurrent();
String path = getPath(request, siteContext);
if (siteContext == null) {
throw new IllegalStateException("No current site context found");
}
if (logger.isDebugEnabled()) {
logger.debug("Trying to get content for static asset at [context=" + siteContext + ", path='" + path + "']");
}
Content content = getContent(siteContext, path);
if (content == null) {
if (logger.isDebugEnabled()) {
logger.debug("No static asset found at [context=" + siteContext + ", path='" + path + "'] - returning 404");
}
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
MediaType mediaType = getMediaType(path);
if (mediaType != null) {
if (logger.isDebugEnabled()) {
logger.debug("Determined media type '" + mediaType + "' for static asset at [context=" + siteContext + ", path='" + path + "']");
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("No media type found for static asset at [context=" + siteContext + ", path='" + path + "'] - not sending a content-type header");
}
}
if ((new ServletWebRequest(request, response)).checkNotModified(content.getLastModified())) {
if (logger.isDebugEnabled()) {
logger.debug("Static asset not modified - returning 304");
}
return;
}
setHeaders(response, content, mediaType);
if (disableCaching) {
if (logger.isDebugEnabled()) {
logger.debug("Caching disabled on client");
}
HttpUtils.disableCaching(response);
}
if (METHOD_HEAD.equals(request.getMethod())) {
logger.trace("HEAD request - skipping content");
return;
}
writeContent(response, content);
}
use of org.springframework.web.context.request.ServletWebRequest in project alf.io by alfio-event.
the class ReservationFlowIntegrationTest method reserveTicket.
private String reserveTicket(String eventName) {
ReservationForm reservationForm = new ReservationForm();
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("POST");
ServletWebRequest servletWebRequest = new ServletWebRequest(request);
BindingResult bindingResult = new BeanPropertyBindingResult(reservationForm, "reservation");
Model model = new BindingAwareModelMap();
RedirectAttributes redirectAttributes = new RedirectAttributesModelMap();
TicketReservationModification ticketReservation = new TicketReservationModification();
ticketReservation.setAmount(1);
ticketReservation.setTicketCategoryId(ticketCategoryRepository.findByEventId(event.getId()).stream().findFirst().map(TicketCategory::getId).orElseThrow(IllegalStateException::new));
reservationForm.setReservation(Collections.singletonList(ticketReservation));
return eventController.reserveTicket(eventName, reservationForm, bindingResult, model, servletWebRequest, redirectAttributes, Locale.ENGLISH);
}
use of org.springframework.web.context.request.ServletWebRequest in project dubion by valsamiq.
the class CustomSignInAdapter method signIn.
@Override
public String signIn(String userId, Connection<?> connection, NativeWebRequest request) {
try {
UserDetails user = userDetailsService.loadUserByUsername(userId);
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user, null, user.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
String jwt = tokenProvider.createToken(authenticationToken, false);
ServletWebRequest servletWebRequest = (ServletWebRequest) request;
servletWebRequest.getResponse().addCookie(getSocialAuthenticationCookie(jwt));
} catch (AuthenticationException ae) {
log.error("Social authentication error");
log.trace("Authentication exception trace: {}", ae);
}
return jHipsterProperties.getSocial().getRedirectAfterSignIn();
}
use of org.springframework.web.context.request.ServletWebRequest in project BroadleafCommerce by BroadleafCommerce.
the class SessionFixationProtectionFilter method abortUser.
protected void abortUser(HttpServletRequest request, HttpServletResponse response) throws IOException {
SecurityContextHolder.clearContext();
cookieUtils.invalidateCookie(response, SessionFixationProtectionCookie.COOKIE_NAME);
if (BLCRequestUtils.isOKtoUseSession(new ServletWebRequest(request))) {
request.getSession().invalidate();
}
response.sendRedirect("/");
}
use of org.springframework.web.context.request.ServletWebRequest in project BroadleafCommerce by BroadleafCommerce.
the class RepeatSubmitProtectionFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
boolean useSession = true;
if (BroadleafRequestContext.getBroadleafRequestContext() != null && BroadleafRequestContext.getBroadleafRequestContext().getWebRequest() != null) {
if (!BLCRequestUtils.isOKtoUseSession(BroadleafRequestContext.getBroadleafRequestContext().getWebRequest())) {
useSession = false;
}
} else if (!BLCRequestUtils.isOKtoUseSession(new ServletWebRequest((HttpServletRequest) request))) {
useSession = false;
}
if (useSession) {
String sessionId;
String requestURI;
synchronized (requests) {
sessionId = ((HttpServletRequest) request).getSession().getId();
requestURI = ((HttpServletRequest) request).getRequestURI();
if (requests.containsKey(sessionId) && requests.get(sessionId).contains(requestURI)) {
// we are currently already processing this request
((HttpServletResponse) response).setStatus(HttpServletResponse.SC_NO_CONTENT);
return;
}
List<String> myRequests = requests.get(sessionId);
if (myRequests == null) {
myRequests = new ArrayList<String>();
requests.put(sessionId, myRequests);
}
myRequests.add(requestURI);
}
try {
chain.doFilter(request, response);
} finally {
synchronized (requests) {
List<String> myRequests = requests.get(sessionId);
myRequests.remove(requestURI);
if (myRequests.isEmpty()) {
requests.remove(sessionId);
}
}
}
} else {
chain.doFilter(request, response);
}
}
Aggregations