@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AuditLogConfig other = (AuditLogConfig) o; return Objects.equals(httpMethod, other.getHttpMethod()) && logRequestBody == other.isLogRequestBody() && logResponseBody == other.isLogResponseBody() && Objects.equals(headerNames, other.getHeaderNames()); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // When a request is forwarded to the internal CDAP service if (msg instanceof HttpRequest) { HttpRequest request = (HttpRequest) msg; // Extra configurations for audit log AuditLogConfig logConfig = AUDIT_LOG_LOOKUP_METHOD.contains(request.method()) ? RouterAuditLookUp.getInstance().getAuditLogContent(request.uri(), request.method()) : null; if (logConfig == null) { logEntry = new AuditLogEntry(request, Networks.getIP(ctx.channel().remoteAddress())); } else { logEntry = new AuditLogEntry(request, Networks.getIP(ctx.channel().remoteAddress()), logConfig.getHeaderNames()); logRequestBody = logConfig.isLogRequestBody(); logResponseBody = logConfig.isLogResponseBody(); } } else if (msg instanceof HttpContent && logEntry != null) { ByteBuf content = ((HttpContent) msg).content(); if (logRequestBody && content.isReadable()) { logEntry.appendRequestBody(content.toString(StandardCharsets.UTF_8)); } } ctx.fireChannelRead(msg); }
@Nullable public AuditLogConfig getAuditLogContent(String path, HttpMethod httpMethod) throws Exception { List<PatternPathRouterWithGroups.RoutableDestination<AuditLogConfig>> destinations = patternMatcher.getDestinations(path); for (PatternPathRouterWithGroups.RoutableDestination<AuditLogConfig> entry : destinations) { AuditLogConfig destination = entry.getDestination(); if (destination.getHttpMethod().equals(httpMethod)) { return destination; } } return null; }
AuditLogConfig auditLogConfig = new AuditLogConfig(httpMethod, auditContents.contains(AuditDetail.REQUEST_BODY), auditContents.contains(AuditDetail.RESPONSE_BODY),
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } AuditLogConfig other = (AuditLogConfig) o; return Objects.equals(httpMethod, other.getHttpMethod()) && logRequestBody == other.isLogRequestBody() && logResponseBody == other.isLogResponseBody() && Objects.equals(headerNames, other.getHeaderNames()); }