use of io.undertow.security.api.SecurityContext in project undertow by undertow-io.
the class HttpServletRequestImpl method authenticate.
@Override
public boolean authenticate(final HttpServletResponse response) throws IOException, ServletException {
if (response.isCommitted()) {
throw UndertowServletMessages.MESSAGES.responseAlreadyCommited();
}
SecurityContext sc = exchange.getSecurityContext();
sc.setAuthenticationRequired();
// wrappers, is this a problem?
if (sc.authenticate()) {
if (sc.isAuthenticated()) {
return true;
} else {
throw UndertowServletMessages.MESSAGES.authenticationFailed();
}
} else {
if (!exchange.isResponseStarted() && exchange.getStatusCode() == 200) {
throw UndertowServletMessages.MESSAGES.authenticationFailed();
} else {
return false;
}
}
}
use of io.undertow.security.api.SecurityContext in project undertow by undertow-io.
the class ServletSecurityRoleHandler method handleRequest.
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final ServletRequestContext servletRequestContext = exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY);
ServletRequest request = servletRequestContext.getServletRequest();
if (request.getDispatcherType() == DispatcherType.REQUEST) {
List<SingleConstraintMatch> constraints = servletRequestContext.getRequiredConstrains();
SecurityContext sc = exchange.getSecurityContext();
if (!authorizationManager.canAccessResource(constraints, sc.getAuthenticatedAccount(), servletRequestContext.getCurrentServlet().getManagedServlet().getServletInfo(), servletRequestContext.getOriginalRequest(), servletRequestContext.getDeployment())) {
HttpServletResponse response = (HttpServletResponse) servletRequestContext.getServletResponse();
response.sendError(StatusCodes.FORBIDDEN);
return;
}
}
next.handleRequest(exchange);
}
use of io.undertow.security.api.SecurityContext in project undertow by undertow-io.
the class AuthenticationMechanismsHandler method handleRequest.
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
final SecurityContext sc = exchange.getSecurityContext();
if (sc != null && sc instanceof AuthenticationMechanismContext) {
AuthenticationMechanismContext amc = (AuthenticationMechanismContext) sc;
for (int i = 0; i < authenticationMechanisms.length; ++i) {
amc.addAuthenticationMechanism(authenticationMechanisms[i]);
}
}
next.handleRequest(exchange);
}
use of io.undertow.security.api.SecurityContext in project undertow by undertow-io.
the class CachedAuthenticatedSessionHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
SecurityContext securityContext = exchange.getSecurityContext();
securityContext.registerNotificationReceiver(NOTIFICATION_RECEIVER);
SessionManager sessionManager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
SessionConfig sessionConfig = exchange.getAttachment(SessionConfig.ATTACHMENT_KEY);
if (sessionManager == null || sessionConfig == null) {
next.handleRequest(exchange);
return;
}
Session session = sessionManager.getSession(exchange, sessionConfig);
// the AuthenticatedSessionManager.
if (session != null) {
exchange.putAttachment(AuthenticatedSessionManager.ATTACHMENT_KEY, SESSION_MANAGER);
}
next.handleRequest(exchange);
}
use of io.undertow.security.api.SecurityContext in project undertow by undertow-io.
the class NotificationReceiverHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
SecurityContext sc = exchange.getSecurityContext();
for (int i = 0; i < receivers.length; ++i) {
sc.registerNotificationReceiver(receivers[i]);
}
next.handleRequest(exchange);
}
Aggregations