All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.networknt.oauth.code.handler.CodeAuditHandler Maven / Gradle / Ivy

There is a newer version: 2.1.15
Show newest version
package com.networknt.oauth.code.handler;

import com.networknt.body.BodyHandler;
import com.networknt.config.Config;
import com.networknt.oauth.cache.AuditInfoHandler;
import com.networknt.oauth.cache.OAuthConfig;
import com.networknt.oauth.cache.model.AuditInfo;
import com.networknt.oauth.cache.model.OauthService;
import io.undertow.server.HttpServerExchange;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class CodeAuditHandler extends AuditInfoHandler {
    static final Logger logger = LoggerFactory.getLogger(CodeAuditHandler.class);
    private final static OAuthConfig config = (OAuthConfig) Config.getInstance().getJsonObjectConfig(OAuthConfig.CONFIG_NAME, OAuthConfig.class);


    protected void processAudit(HttpServerExchange exchange) throws Exception{
        if (config.isEnableAudit()) {
            AuditInfo auditInfo = new AuditInfo();
            auditInfo.setServiceId(OauthService.OAUTH_CODE);
            auditInfo.setEndpoint(exchange.getHostName() + exchange.getRelativePath());
            auditInfo.setRequestHeader(exchange.getRequestHeaders().toString());
            auditInfo.setRequestBody(Config.getInstance().getMapper().writeValueAsString(exchange.getAttachment(BodyHandler.REQUEST_BODY)));
            auditInfo.setResponseCode(exchange.getStatusCode());
            auditInfo.setResponseHeader(exchange.getResponseHeaders().toString());
            auditInfo.setResponseBody(Config.getInstance().getMapper().writeValueAsString(exchange.getResponseCookies()));
            saveAudit(auditInfo);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy