Skip to content

Commit

Permalink
Add support for client port in audit record
Browse files Browse the repository at this point in the history
Closes #90
  • Loading branch information
eperott authored May 14, 2019
1 parent abf0c58 commit f4001c4
Show file tree
Hide file tree
Showing 33 changed files with 525 additions and 326 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changes

## Version 2.1.0
* Add support for client port in log messages - #90
* Add support for post-logging - #24
* Add support for host address in log message #28
* Add support for host address in log message - #28
* Add support for Chronicle-Queue backend - #62
* Add metrics for filtering and logging - #72
* Add support for system timestamp in log message - #27
Expand Down
6 changes: 6 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,11 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>com.ericsson.bss.cassandra.ecaudit</groupId>
<artifactId>test-utils_${artifact.flavor.version}</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.ericsson.bss.cassandra.ecaudit.common.chronicle;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.UUID;

Expand Down Expand Up @@ -48,8 +49,8 @@ public void readMarshallable(@NotNull WireIn wire) throws IORuntimeException
SimpleAuditRecord.Builder builder = SimpleAuditRecord
.builder()
.withTimestamp(wire.read(WireTags.KEY_TIMESTAMP).int64())
.withClientAddress(readAddress(wire, WireTags.KEY_CLIENT))
.withCoordinatorAddress(readAddress(wire, WireTags.KEY_COORDINATOR))
.withClientAddress(readInetSocketAddress(wire, WireTags.KEY_CLIENT_IP, WireTags.KEY_CLIENT_PORT))
.withCoordinatorAddress(readInetAddress(wire, WireTags.KEY_COORDINATOR_IP))
.withUser(wire.read(WireTags.KEY_USER).text());

if (WireTags.VALUE_TYPE_BATCH_ENTRY.equals(type))
Expand Down Expand Up @@ -83,15 +84,33 @@ private String readType(WireIn wire) throws IORuntimeException
return type;
}

private InetAddress readAddress(WireIn wire, String key) throws IORuntimeException
private InetSocketAddress readInetSocketAddress(WireIn wire, String ipKey, String portKey) throws IORuntimeException
{
try
{
InetAddress inetAddress = InetAddress.getByAddress(wire.read(ipKey).bytes());
int port = wire.read(portKey).int32();
return new InetSocketAddress(inetAddress, port);
}
catch (UnknownHostException e)
{
throw new IORuntimeException("Corrupt " + ipKey + " field", e);
}
catch (IllegalArgumentException e)
{
throw new IORuntimeException("Corrupt " + portKey + " field", e);
}
}

private InetAddress readInetAddress(WireIn wire, String key) throws IORuntimeException
{
try
{
return InetAddress.getByAddress(wire.read(key).bytes());
}
catch (UnknownHostException e)
{
throw new IORuntimeException("Corrupt " + key + " IP address field", e);
throw new IORuntimeException("Corrupt " + key + " field", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public void writeMarshallable(@NotNull WireOut wire)
wire.write(WireTags.KEY_VERSION).int16(WireTags.VALUE_VERSION_CURRENT);
wire.write(WireTags.KEY_TYPE).text(type);
wire.write(WireTags.KEY_TIMESTAMP).int64(auditRecord.getTimestamp());
wire.write(WireTags.KEY_CLIENT).bytes(auditRecord.getClientAddress().getAddress());
wire.write(WireTags.KEY_COORDINATOR).bytes(auditRecord.getCoordinatorAddress().getAddress());
wire.write(WireTags.KEY_CLIENT_IP).bytes(auditRecord.getClientAddress().getAddress().getAddress());
wire.write(WireTags.KEY_CLIENT_PORT).int32(auditRecord.getClientAddress().getPort());
wire.write(WireTags.KEY_COORDINATOR_IP).bytes(auditRecord.getCoordinatorAddress().getAddress());
wire.write(WireTags.KEY_USER).text(auditRecord.getUser());
auditRecord.getBatchId().ifPresent(batchId -> wire.write(WireTags.KEY_BATCH_ID).uuid(batchId));
wire.write(WireTags.KEY_STATUS).text(auditRecord.getStatus().name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class WireTags
static final String KEY_VERSION = "version";
static final String KEY_TYPE = "type";
static final String KEY_TIMESTAMP = "timestamp";
static final String KEY_CLIENT = "client";
static final String KEY_COORDINATOR = "coordinator";
static final String KEY_CLIENT_IP = "client_ip";
static final String KEY_CLIENT_PORT = "client_port";
static final String KEY_COORDINATOR_IP = "coordinator_ip";
static final String KEY_USER = "user";
static final String KEY_BATCH_ID = "batchId";
static final String KEY_STATUS = "status";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
package com.ericsson.bss.cassandra.ecaudit.common.record;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Optional;
import java.util.UUID;

public interface AuditRecord
{
Long getTimestamp();

InetAddress getClientAddress();
InetSocketAddress getClientAddress();

InetAddress getCoordinatorAddress();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
package com.ericsson.bss.cassandra.ecaudit.common.record;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.Optional;
import java.util.UUID;

public class SimpleAuditRecord implements AuditRecord
{
private final InetAddress clientAddress;
private final InetSocketAddress clientAddress;
private final InetAddress coordinatorAddress;
private final String user;
private final UUID batchId;
Expand All @@ -47,7 +48,7 @@ public Long getTimestamp()
}

@Override
public InetAddress getClientAddress()
public InetSocketAddress getClientAddress()
{
return clientAddress;
}
Expand Down Expand Up @@ -89,15 +90,15 @@ public static Builder builder()

public static class Builder
{
private InetAddress clientAddress;
private InetSocketAddress clientAddress;
private InetAddress coordinatorAddress;
private String user;
private UUID batchId;
private Status status;
private AuditOperation operation;
private long timestamp;

public Builder withClientAddress(InetAddress clientAddress)
public Builder withClientAddress(InetSocketAddress clientAddress)
{
this.clientAddress = clientAddress;
return this;
Expand Down
Loading

0 comments on commit f4001c4

Please sign in to comment.