mirror of https://github.com/apache/druid.git
also log author ip address in audit log
This commit is contained in:
parent
36b4c6a371
commit
f9821d242f
|
@ -24,15 +24,18 @@ public class AuditInfo
|
||||||
{
|
{
|
||||||
private final String author;
|
private final String author;
|
||||||
private final String comment;
|
private final String comment;
|
||||||
|
private final String ip;
|
||||||
|
|
||||||
@JsonCreator
|
@JsonCreator
|
||||||
public AuditInfo(
|
public AuditInfo(
|
||||||
@JsonProperty("author") String author,
|
@JsonProperty("author") String author,
|
||||||
@JsonProperty("comment") String comment
|
@JsonProperty("comment") String comment,
|
||||||
|
@JsonProperty("ip") String ip
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.author = author;
|
this.author = author;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
|
this.ip = ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
|
@ -47,6 +50,12 @@ public class AuditInfo
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
public String getIp()
|
||||||
|
{
|
||||||
|
return ip;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o)
|
public boolean equals(Object o)
|
||||||
{
|
{
|
||||||
|
@ -65,6 +74,9 @@ public class AuditInfo
|
||||||
if (!comment.equals(that.comment)) {
|
if (!comment.equals(that.comment)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!ip.equals(that.ip)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -74,6 +86,7 @@ public class AuditInfo
|
||||||
{
|
{
|
||||||
int result = author.hashCode();
|
int result = author.hashCode();
|
||||||
result = 31 * result + comment.hashCode();
|
result = 31 * result + comment.hashCode();
|
||||||
|
result = 31 * result + ip.hashCode();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ import io.druid.timeline.DataSegment;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DefaultValue;
|
import javax.ws.rs.DefaultValue;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
@ -58,6 +59,7 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -196,10 +198,15 @@ public class OverlordResource
|
||||||
public Response setWorkerConfig(
|
public Response setWorkerConfig(
|
||||||
final WorkerBehaviorConfig workerBehaviorConfig,
|
final WorkerBehaviorConfig workerBehaviorConfig,
|
||||||
@HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author,
|
@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();
|
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@ import io.druid.server.coordinator.CoordinatorDynamicConfig;
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DefaultValue;
|
import javax.ws.rs.DefaultValue;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
@ -32,6 +33,7 @@ import javax.ws.rs.POST;
|
||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
|
||||||
|
@ -70,10 +72,15 @@ public class CoordinatorDynamicConfigsResource
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
public Response setDynamicConfigs(final CoordinatorDynamicConfig dynamicConfig,
|
public Response setDynamicConfigs(final CoordinatorDynamicConfig dynamicConfig,
|
||||||
@HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author,
|
@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.status(Response.Status.BAD_REQUEST).build();
|
||||||
}
|
}
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
|
|
|
@ -24,6 +24,7 @@ import io.druid.metadata.MetadataRuleManager;
|
||||||
import io.druid.server.coordinator.rules.Rule;
|
import io.druid.server.coordinator.rules.Rule;
|
||||||
import org.joda.time.Interval;
|
import org.joda.time.Interval;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DefaultValue;
|
import javax.ws.rs.DefaultValue;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
|
@ -33,6 +34,7 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -85,13 +87,14 @@ public class RulesResource
|
||||||
@PathParam("dataSourceName") final String dataSourceName,
|
@PathParam("dataSourceName") final String dataSourceName,
|
||||||
final List<Rule> rules,
|
final List<Rule> rules,
|
||||||
@HeaderParam(AuditManager.X_DRUID_AUTHOR) @DefaultValue("") final String author,
|
@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(
|
if (databaseRuleManager.overrideRule(
|
||||||
dataSourceName,
|
dataSourceName,
|
||||||
rules,
|
rules,
|
||||||
new AuditInfo(author, comment)
|
new AuditInfo(author, comment, req.getRemoteAddr())
|
||||||
)) {
|
)) {
|
||||||
return Response.ok().build();
|
return Response.ok().build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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(
|
ruleManager.overrideRule(
|
||||||
"test_dataSource",
|
"test_dataSource",
|
||||||
rules,
|
rules,
|
||||||
|
|
|
@ -73,7 +73,8 @@ public class SQLAuditManagerTest
|
||||||
"testType",
|
"testType",
|
||||||
new AuditInfo(
|
new AuditInfo(
|
||||||
"testAuthor",
|
"testAuthor",
|
||||||
"testComment"
|
"testComment",
|
||||||
|
"127.0.0.1"
|
||||||
),
|
),
|
||||||
"testPayload",
|
"testPayload",
|
||||||
new DateTime("2013-01-01T00:00:00Z")
|
new DateTime("2013-01-01T00:00:00Z")
|
||||||
|
@ -91,7 +92,8 @@ public class SQLAuditManagerTest
|
||||||
"testType",
|
"testType",
|
||||||
new AuditInfo(
|
new AuditInfo(
|
||||||
"testAuthor",
|
"testAuthor",
|
||||||
"testComment"
|
"testComment",
|
||||||
|
"127.0.0.1"
|
||||||
),
|
),
|
||||||
"testPayload",
|
"testPayload",
|
||||||
new DateTime("2013-01-01T00:00:00Z")
|
new DateTime("2013-01-01T00:00:00Z")
|
||||||
|
@ -111,7 +113,8 @@ public class SQLAuditManagerTest
|
||||||
"testType",
|
"testType",
|
||||||
new AuditInfo(
|
new AuditInfo(
|
||||||
"testAuthor",
|
"testAuthor",
|
||||||
"testComment"
|
"testComment",
|
||||||
|
"127.0.0.1"
|
||||||
),
|
),
|
||||||
"testPayload",
|
"testPayload",
|
||||||
new DateTime("2013-01-01T00:00:00Z")
|
new DateTime("2013-01-01T00:00:00Z")
|
||||||
|
|
Loading…
Reference in New Issue