use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class ServletRequestAttribute method writeAttribute.
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
ServletRequestContext context = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (context != null) {
context.getServletRequest().setAttribute(attributeName, newValue);
} else {
Map<String, String> attrs = exchange.getAttachment(HttpServerExchange.REQUEST_ATTRIBUTES);
if (attrs == null) {
exchange.putAttachment(HttpServerExchange.REQUEST_ATTRIBUTES, attrs = new HashMap<>());
}
attrs.put(attributeName, newValue);
}
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class ServletBlockingHttpExchange method close.
@Override
public void close() throws IOException {
ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
if (!exchange.isComplete()) {
try {
HttpServletRequestImpl request = servletRequestContext.getOriginalRequest();
request.closeAndDrainRequest();
} finally {
HttpServletResponseImpl response = servletRequestContext.getOriginalResponse();
response.closeStreamAndWriter();
}
} else {
try {
HttpServletRequestImpl request = servletRequestContext.getOriginalRequest();
request.freeResources();
} finally {
HttpServletResponseImpl response = servletRequestContext.getOriginalResponse();
response.freeResources();
}
}
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class ServletAuthenticationCallHandler method handleRequest.
/**
* Only allow the request through if successfully authenticated or if authentication is not required.
*
* @see io.undertow.server.HttpHandler#handleRequest(io.undertow.server.HttpServerExchange)
*/
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
if (exchange.isInIoThread()) {
exchange.dispatch(this);
return;
}
SecurityContext context = exchange.getSecurityContext();
if (context.authenticate()) {
if (!exchange.isComplete()) {
next.handleRequest(exchange);
}
} else {
if (exchange.getStatusCode() >= StatusCodes.BAD_REQUEST && !exchange.isComplete()) {
ServletRequestContext src = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
src.getOriginalResponse().sendError(exchange.getStatusCode());
} else {
exchange.endExchange();
}
}
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class ServletConfidentialityConstraintHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
final AuthorizationManager authorizationManager = servletRequestContext.getDeployment().getDeploymentInfo().getAuthorizationManager();
TransportGuaranteeType connectionGuarantee = servletRequestContext.getOriginalRequest().isSecure() ? TransportGuaranteeType.CONFIDENTIAL : TransportGuaranteeType.NONE;
TransportGuaranteeType transportGuarantee = authorizationManager.transportGuarantee(connectionGuarantee, servletRequestContext.getTransportGuarenteeType(), servletRequestContext.getOriginalRequest());
servletRequestContext.setTransportGuarenteeType(transportGuarantee);
if (TransportGuaranteeType.REJECTED == transportGuarantee) {
HttpServletResponse response = (HttpServletResponse) servletRequestContext.getServletResponse();
response.sendError(StatusCodes.FORBIDDEN);
return;
}
super.handleRequest(exchange);
}
use of io.undertow.servlet.handlers.ServletRequestContext in project undertow by undertow-io.
the class ServletFormAuthenticationMechanism method storeInitialLocation.
@Override
protected void storeInitialLocation(final HttpServerExchange exchange) {
if (!saveOriginalRequest) {
return;
}
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
HttpSessionImpl httpSession = servletRequestContext.getCurrentServletContext().getSession(exchange, true);
Session session;
if (System.getSecurityManager() == null) {
session = httpSession.getSession();
} else {
session = AccessController.doPrivileged(new HttpSessionImpl.UnwrapSessionAction(httpSession));
}
SessionManager manager = session.getSessionManager();
if (seenSessionManagers.add(manager)) {
manager.registerSessionListener(LISTENER);
}
session.setAttribute(SESSION_KEY, RedirectBuilder.redirect(exchange, exchange.getRelativePath()));
SavedRequest.trySaveRequest(exchange);
}
Aggregations