Java Code Examples for io.undertow.security.api.SecurityContext#authenticate()

The following examples show how to use io.undertow.security.api.SecurityContext#authenticate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpServletRequestImpl.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public boolean authenticate(final HttpServletResponse response) throws IOException, ServletException {
    if (response.isCommitted()) {
        throw UndertowServletMessages.MESSAGES.responseAlreadyCommited();
    }

    SecurityContext sc = exchange.getSecurityContext();
    sc.setAuthenticationRequired();
    // TODO: this will set the status code and headers without going through any potential
    // 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;
        }
    }
}
 
Example 2
Source File: ServletAuthenticationCallHandler.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
        }
    }
}
 
Example 3
Source File: AuthenticationCallHandler.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
/**
 * 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 {
        exchange.endExchange();
    }
}
 
Example 4
Source File: AuthenticationCallHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 {
        exchange.endExchange();
    }
}
 
Example 5
Source File: HttpServletRequestImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean authenticate(final HttpServletResponse response) throws IOException, ServletException {
    if (response.isCommitted()) {
        throw UndertowServletMessages.MESSAGES.responseAlreadyCommited();
    }

    SecurityContext sc = exchange.getSecurityContext();
    sc.setAuthenticationRequired();
    // TODO: this will set the status code and headers without going through any potential
    // 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;
        }
    }
}
 
Example 6
Source File: ServletAuthenticationCallHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
        }
    }
}