Skip to content

Commit

Permalink
Add support for client port in audit record
Browse files Browse the repository at this point in the history
  • Loading branch information
eperott committed May 10, 2019
1 parent ff6b4da commit 0e28c1b
Show file tree
Hide file tree
Showing 29 changed files with 423 additions and 220 deletions.
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,29 @@ 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);
}
}

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 0e28c1b

Please sign in to comment.