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

The following examples show how to use io.undertow.security.api.SecurityContext#isAuthenticated() . 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: 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 3
Source File: RemoteUserAttribute.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public String readAttribute(final HttpServerExchange exchange) {
    SecurityContext sc = exchange.getSecurityContext();
    if (sc == null || !sc.isAuthenticated()) {
        return null;
    }
    return sc.getAuthenticatedAccount().getPrincipal().getName();
}
 
Example 4
Source File: JDBCLogHandler.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public void logMessage(String pattern, HttpServerExchange exchange) {
    JDBCLogAttribute jdbcLogAttribute = new JDBCLogAttribute();

    if (pattern.equals("combined")) {
        jdbcLogAttribute.pattern = pattern;
    }
    jdbcLogAttribute.remoteHost = ((InetSocketAddress) exchange.getSourceAddress()).getAddress().getHostAddress();
    SecurityContext sc = exchange.getSecurityContext();
    if (sc == null || !sc.isAuthenticated()) {
        jdbcLogAttribute.user = null;
    } else {
        jdbcLogAttribute.user = sc.getAuthenticatedAccount().getPrincipal().getName();
    }
    jdbcLogAttribute.query = exchange.getQueryString();

    jdbcLogAttribute.bytes = exchange.getResponseContentLength();
    if (jdbcLogAttribute.bytes < 0) {
        jdbcLogAttribute.bytes = 0;
    }

    jdbcLogAttribute.status = exchange.getStatusCode();

    if (jdbcLogAttribute.pattern.equals("combined")) {
        jdbcLogAttribute.virtualHost = exchange.getRequestHeader(HttpHeaderNames.HOST);
        jdbcLogAttribute.method = exchange.getRequestMethod();
        jdbcLogAttribute.referer = exchange.getRequestHeader(HttpHeaderNames.REFERER);
        jdbcLogAttribute.userAgent = exchange.getRequestHeader(HttpHeaderNames.USER_AGENT);
    }

    this.pendingMessages.add(jdbcLogAttribute);
    int state = stateUpdater.get(this);
    if (state == 0) {
        if (stateUpdater.compareAndSet(this, 0, 1)) {
            this.executor = exchange.getWorker();
            this.executor.execute(this);
        }
    }
}
 
Example 5
Source File: RemoteUserAttribute.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String readAttribute(final HttpServerExchange exchange) {
    SecurityContext sc = exchange.getSecurityContext();
    if (sc == null || !sc.isAuthenticated()) {
        return null;
    }
    return sc.getAuthenticatedAccount().getPrincipal().getName();
}
 
Example 6
Source File: JDBCLogHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public void logMessage(String pattern, HttpServerExchange exchange) {
    JDBCLogAttribute jdbcLogAttribute = new JDBCLogAttribute();

    if (pattern.equals("combined")) {
        jdbcLogAttribute.pattern = pattern;
    }
    jdbcLogAttribute.remoteHost = ((InetSocketAddress) exchange.getConnection().getPeerAddress()).getAddress().getHostAddress();
    SecurityContext sc = exchange.getSecurityContext();
    if (sc == null || !sc.isAuthenticated()) {
        jdbcLogAttribute.user = null;
    } else {
        jdbcLogAttribute.user = sc.getAuthenticatedAccount().getPrincipal().getName();
    }
    jdbcLogAttribute.query = exchange.getQueryString();

    jdbcLogAttribute.bytes = exchange.getResponseContentLength();
    if (jdbcLogAttribute.bytes < 0) {
        jdbcLogAttribute.bytes = 0;
    }

    jdbcLogAttribute.status = exchange.getStatusCode();

    if (jdbcLogAttribute.pattern.equals("combined")) {
        jdbcLogAttribute.virtualHost = exchange.getRequestHeaders().getFirst(Headers.HOST);
        jdbcLogAttribute.method = exchange.getRequestMethod().toString();
        jdbcLogAttribute.referer = exchange.getRequestHeaders().getFirst(Headers.REFERER);
        jdbcLogAttribute.userAgent = exchange.getRequestHeaders().getFirst(Headers.USER_AGENT);
    }

    this.pendingMessages.add(jdbcLogAttribute);
    int state = stateUpdater.get(this);
    if (state == 0) {
        if (stateUpdater.compareAndSet(this, 0, 1)) {
            this.executor = exchange.getConnection().getWorker();
            this.executor.execute(this);
        }
    }
}