From f9821d242fb8c953df1fe3af05101f67b79e0587 Mon Sep 17 00:00:00 2001 From: nishantmonu51 Date: Tue, 17 Mar 2015 23:15:15 +0530 Subject: [PATCH] also log author ip address in audit log --- .../src/main/java/io/druid/audit/AuditInfo.java | 15 ++++++++++++++- .../indexing/overlord/http/OverlordResource.java | 11 +++++++++-- .../http/CoordinatorDynamicConfigsResource.java | 11 +++++++++-- .../java/io/druid/server/http/RulesResource.java | 7 +++++-- .../metadata/SQLMetadataRuleManagerTest.java | 2 +- .../druid/server/audit/SQLAuditManagerTest.java | 9 ++++++--- 6 files changed, 44 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/io/druid/audit/AuditInfo.java b/common/src/main/java/io/druid/audit/AuditInfo.java index 6c3e1831441..c4ede95e9ab 100644 --- a/common/src/main/java/io/druid/audit/AuditInfo.java +++ b/common/src/main/java/io/druid/audit/AuditInfo.java @@ -24,15 +24,18 @@ public class AuditInfo { private final String author; private final String comment; + private final String ip; @JsonCreator public AuditInfo( @JsonProperty("author") String author, - @JsonProperty("comment") String comment + @JsonProperty("comment") String comment, + @JsonProperty("ip") String ip ) { this.author = author; this.comment = comment; + this.ip = ip; } @JsonProperty @@ -47,6 +50,12 @@ public class AuditInfo return comment; } + @JsonProperty + public String getIp() + { + return ip; + } + @Override public boolean equals(Object o) { @@ -65,6 +74,9 @@ public class AuditInfo if (!comment.equals(that.comment)) { return false; } + if (!ip.equals(that.ip)) { + return false; + } return true; } @@ -74,6 +86,7 @@ public class AuditInfo { int result = author.hashCode(); result = 31 * result + comment.hashCode(); + result = 31 * result + ip.hashCode(); return result; } } diff --git a/indexing-service/src/main/java/io/druid/indexing/overlord/http/OverlordResource.java b/indexing-service/src/main/java/io/druid/indexing/overlord/http/OverlordResource.java index 699c1d044f2..a3cb1e75232 100644 --- a/indexing-service/src/main/java/io/druid/indexing/overlord/http/OverlordResource.java +++ b/indexing-service/src/main/java/io/druid/indexing/overlord/http/OverlordResource.java @@ -49,6 +49,7 @@ import io.druid.timeline.DataSegment; import org.joda.time.DateTime; import org.joda.time.Interval; +import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -58,6 +59,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.IOException; @@ -196,10 +198,15 @@ public class OverlordResource public Response setWorkerConfig( final WorkerBehaviorConfig workerBehaviorConfig, @HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author, - @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment + @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment, + @Context HttpServletRequest req ) { - if (!configManager.set(WorkerBehaviorConfig.CONFIG_KEY, workerBehaviorConfig, new AuditInfo(author, comment))) { + if (!configManager.set( + WorkerBehaviorConfig.CONFIG_KEY, + workerBehaviorConfig, + new AuditInfo(author, comment, req.getRemoteAddr()) + )) { return Response.status(Response.Status.BAD_REQUEST).build(); } diff --git a/server/src/main/java/io/druid/server/http/CoordinatorDynamicConfigsResource.java b/server/src/main/java/io/druid/server/http/CoordinatorDynamicConfigsResource.java index 0728e246e2c..d873c359b58 100644 --- a/server/src/main/java/io/druid/server/http/CoordinatorDynamicConfigsResource.java +++ b/server/src/main/java/io/druid/server/http/CoordinatorDynamicConfigsResource.java @@ -24,6 +24,7 @@ import io.druid.server.coordinator.CoordinatorDynamicConfig; import org.joda.time.Interval; import javax.inject.Inject; +import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -32,6 +33,7 @@ import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -70,10 +72,15 @@ public class CoordinatorDynamicConfigsResource @Consumes(MediaType.APPLICATION_JSON) public Response setDynamicConfigs(final CoordinatorDynamicConfig dynamicConfig, @HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author, - @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment + @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment, + @Context HttpServletRequest req ) { - if (!manager.set(CoordinatorDynamicConfig.CONFIG_KEY, dynamicConfig, new AuditInfo(author, comment))) { + if (!manager.set( + CoordinatorDynamicConfig.CONFIG_KEY, + dynamicConfig, + new AuditInfo(author, comment, req.getRemoteAddr()) + )) { return Response.status(Response.Status.BAD_REQUEST).build(); } return Response.ok().build(); diff --git a/server/src/main/java/io/druid/server/http/RulesResource.java b/server/src/main/java/io/druid/server/http/RulesResource.java index 3024a93a08d..e3ea5c444bb 100644 --- a/server/src/main/java/io/druid/server/http/RulesResource.java +++ b/server/src/main/java/io/druid/server/http/RulesResource.java @@ -24,6 +24,7 @@ import io.druid.metadata.MetadataRuleManager; import io.druid.server.coordinator.rules.Rule; import org.joda.time.Interval; +import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; @@ -33,6 +34,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @@ -85,13 +87,14 @@ public class RulesResource @PathParam("dataSourceName") final String dataSourceName, final List rules, @HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author, - @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment + @HeaderParam(AuditManager.X_DRUID_COMMENT) @DefaultValue("") final String comment, + @Context HttpServletRequest req ) { if (databaseRuleManager.overrideRule( dataSourceName, rules, - new AuditInfo(author, comment) + new AuditInfo(author, comment, req.getRemoteAddr()) )) { return Response.ok().build(); } diff --git a/server/src/test/java/io/druid/metadata/SQLMetadataRuleManagerTest.java b/server/src/test/java/io/druid/metadata/SQLMetadataRuleManagerTest.java index c95247e3cdb..7061cfef9d3 100644 --- a/server/src/test/java/io/druid/metadata/SQLMetadataRuleManagerTest.java +++ b/server/src/test/java/io/druid/metadata/SQLMetadataRuleManagerTest.java @@ -94,7 +94,7 @@ public class SQLMetadataRuleManagerTest ) ) ); - AuditInfo auditInfo = new AuditInfo("test_author", "test_comment"); + AuditInfo auditInfo = new AuditInfo("test_author", "test_comment", "127.0.0.1"); ruleManager.overrideRule( "test_dataSource", rules, diff --git a/server/src/test/java/io/druid/server/audit/SQLAuditManagerTest.java b/server/src/test/java/io/druid/server/audit/SQLAuditManagerTest.java index 9923c535023..f1283ff8072 100644 --- a/server/src/test/java/io/druid/server/audit/SQLAuditManagerTest.java +++ b/server/src/test/java/io/druid/server/audit/SQLAuditManagerTest.java @@ -73,7 +73,8 @@ public class SQLAuditManagerTest "testType", new AuditInfo( "testAuthor", - "testComment" + "testComment", + "127.0.0.1" ), "testPayload", new DateTime("2013-01-01T00:00:00Z") @@ -91,7 +92,8 @@ public class SQLAuditManagerTest "testType", new AuditInfo( "testAuthor", - "testComment" + "testComment", + "127.0.0.1" ), "testPayload", new DateTime("2013-01-01T00:00:00Z") @@ -111,7 +113,8 @@ public class SQLAuditManagerTest "testType", new AuditInfo( "testAuthor", - "testComment" + "testComment", + "127.0.0.1" ), "testPayload", new DateTime("2013-01-01T00:00:00Z")