Skip to content

Commit

Permalink
#433: HAPI FHIR REST Audit Sender for BALP Audits
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris Stanojevic committed Jan 24, 2024
1 parent 4766c2a commit 3782e72
Show file tree
Hide file tree
Showing 44 changed files with 1,774 additions and 55 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ work
/commons/ihe/xds/generated-stubs
generated-stubs
/commons/audit/.vertx
/local_history.patch
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ default SerializationStrategy getSerializationStrategy() {
default void audit(AuditMessage... messages) {
if (isAuditEnabled() && messages != null) {
getAuditMessageQueue().audit(this, Stream.of(messages)
.map(getAuditMessagePostProcessor())
.toArray(AuditMessage[]::new));
.map(getAuditMessagePostProcessor())
.toArray(AuditMessage[]::new));
}
}

Expand Down Expand Up @@ -165,6 +165,10 @@ default String getAuditValueIfMissing() {
*/
boolean isIncludeParticipantsFromResponse();

String getAuditRepositoryContextPath();

String getFhirHttpClient();

static AuditContext noAudit() {
return DefaultAuditContext.NO_AUDIT;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ public class DefaultAuditContext implements AuditContext {
@Setter
private String auditValueIfMissing = "UNKNOWN";

@Getter
@Setter
private String auditRepositoryContextPath = "";

@Getter
@Setter
private String fhirHttpClient = "apache";

public String getAuditRepositoryTransport() {
return auditTransmissionProtocol.getTransportName();
}
Expand All @@ -111,7 +119,7 @@ public void setAuditRepositoryHost(String host) {

public void setAuditRepositoryTransport(String transport) {
setAuditTransmissionProtocol(
AuditTransmissionChannel.fromProtocolName(transport).makeInstance(tlsParameters)
AuditTransmissionChannel.fromProtocolName(transport).makeInstance(tlsParameters)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,56 @@

import org.openehealth.ipf.commons.audit.AuditException;
import org.openehealth.ipf.commons.audit.TlsParameters;
import org.openehealth.ipf.commons.audit.protocol.providers.NettyTLSSyslogSenderProvider;
import org.openehealth.ipf.commons.audit.protocol.providers.ReactorNettyTLSSyslogSenderProvider;
import org.openehealth.ipf.commons.audit.protocol.providers.RecordingAuditMessageTransmissionProvider;
import org.openehealth.ipf.commons.audit.protocol.providers.TLSSyslogSenderProvider;
import org.openehealth.ipf.commons.audit.protocol.providers.UDPSyslogSenderProvider;
import org.openehealth.ipf.commons.audit.protocol.providers.VertxTLSSyslogSenderProvider;

import java.util.Arrays;
import java.util.ServiceLoader;
import java.util.stream.Collectors;

/**
* Maps AuditTransmissionProtocol names to instances
* Maps AuditTransmissionProtocol names to service providers which should provide a concrete instance of an
* {@link AuditTransmissionProtocol} over a {@link ServiceLoader} mechanism.
*
* @author Christian Ohr
*/
public enum AuditTransmissionChannel {

UDP("UDP", UDPSyslogSenderImpl.class),
NIO_UDP("NIO-UDP", UDPSyslogSenderImpl.class),
VERTX_UDP("VERTX-UDP", UDPSyslogSenderImpl.class),
TLS("TLS", TLSSyslogSenderImpl.class),
NIO_TLS("NIO-TLS", NettyTLSSyslogSenderImpl.class),
VERTX_TLS("VERTX-TLS", VertxTLSSyslogSenderImpl.class),
NETTY_TLS("NETTY-TLS", NettyTLSSyslogSenderImpl.class),
REACTOR_NETTY_TLS("REACTOR-NETTY-TLS", ReactorNettyTLSSyslogSenderImpl.class),
RECORDING("RECORDING", RecordingAuditMessageTransmission.class);
UDP("UDP", UDPSyslogSenderProvider.class.getName()),
NIO_UDP("NIO-UDP", UDPSyslogSenderProvider.class.getName()),
VERTX_UDP("VERTX-UDP", UDPSyslogSenderProvider.class.getName()),
TLS("TLS", TLSSyslogSenderProvider.class.getName()),
NIO_TLS("NIO-TLS", NettyTLSSyslogSenderProvider.class.getName()),
VERTX_TLS("VERTX-TLS", VertxTLSSyslogSenderProvider.class.getName()),
NETTY_TLS("NETTY-TLS", NettyTLSSyslogSenderProvider.class.getName()),
REACTOR_NETTY_TLS("REACTOR-NETTY-TLS", ReactorNettyTLSSyslogSenderProvider.class.getName()),
FHIR_REST_TLS("FHIR-REST-TLS", "org.openehealth.ipf.commons.ihe.fhir.audit.protocol.FhirRestTLSAuditRecordSenderProvider"),
RECORDING("RECORDING", RecordingAuditMessageTransmissionProvider.class.getName());

private final String protocolName;
private final Class<? extends AuditTransmissionProtocol> protocol;
private final String protocolClass;

AuditTransmissionChannel(String protocolName, Class<? extends AuditTransmissionProtocol> protocol) {
AuditTransmissionChannel(String protocolName, String protocolClass) {
this.protocolName = protocolName;
this.protocol = protocol;
this.protocolClass = protocolClass;
}

public String getProtocolName() {
return protocolName;
}

public AuditTransmissionProtocol makeInstance(TlsParameters tlsParameters) {
try {
return protocol.getConstructor(TlsParameters.class).newInstance(tlsParameters);
} catch (Exception e) {
throw new AuditException(e);
ServiceLoader<AuditTransmissionProtocolProvider> loader = ServiceLoader.load(AuditTransmissionProtocolProvider.class);
for (AuditTransmissionProtocolProvider provider : loader) {
if (protocolClass.equals(provider.getClass().getName())) {
return provider.createAuditTransmissionProtocol(tlsParameters);
}
}
throw new AuditException("Could not instantiate AuditTransmissionProtocolProvider for name " + protocolName);
}

public static AuditTransmissionChannel fromProtocolName(String protocolName) {
Expand All @@ -66,9 +77,10 @@ public static AuditTransmissionChannel fromProtocolName(String protocolName) {
}
}
throw new IllegalArgumentException("Unknown audit protocol name: " + protocolName +
". Choose one of: " +
Arrays.stream(AuditTransmissionChannel.values())
.map(AuditTransmissionChannel::getProtocolName)
.collect(Collectors.joining(",")));
". Choose one of: " +
Arrays.stream(AuditTransmissionChannel.values())
.map(AuditTransmissionChannel::getProtocolName)
.collect(Collectors.joining(",")));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.audit.protocol;

import org.openehealth.ipf.commons.audit.TlsParameters;

/**
* A Service Provider interface located and loaded by {@link java.util.ServiceLoader}.
* Implementations should provide an instance of {@link AuditTransmissionProtocol}
*
* @see AuditTransmissionProtocol
* @see AuditTransmissionChannel
*
* @author Boris Stanojevic
*/
public interface AuditTransmissionProtocolProvider {
AuditTransmissionProtocol createAuditTransmissionProtocol(TlsParameters tlsParameters);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.audit.protocol.providers;

import org.openehealth.ipf.commons.audit.TlsParameters;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocolProvider;
import org.openehealth.ipf.commons.audit.protocol.NettyTLSSyslogSenderImpl;

public class NettyTLSSyslogSenderProvider implements AuditTransmissionProtocolProvider {

@Override
public AuditTransmissionProtocol createAuditTransmissionProtocol(TlsParameters tlsParameters) {
return new NettyTLSSyslogSenderImpl(tlsParameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.audit.protocol.providers;

import org.openehealth.ipf.commons.audit.TlsParameters;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocolProvider;
import org.openehealth.ipf.commons.audit.protocol.ReactorNettyTLSSyslogSenderImpl;

public class ReactorNettyTLSSyslogSenderProvider implements AuditTransmissionProtocolProvider {

@Override
public AuditTransmissionProtocol createAuditTransmissionProtocol(TlsParameters tlsParameters) {
return new ReactorNettyTLSSyslogSenderImpl(tlsParameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.audit.protocol.providers;

import org.openehealth.ipf.commons.audit.TlsParameters;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocolProvider;
import org.openehealth.ipf.commons.audit.protocol.RecordingAuditMessageTransmission;

public class RecordingAuditMessageTransmissionProvider implements AuditTransmissionProtocolProvider {

@Override
public AuditTransmissionProtocol createAuditTransmissionProtocol(TlsParameters tlsParameters) {
return new RecordingAuditMessageTransmission(tlsParameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.audit.protocol.providers;

import org.openehealth.ipf.commons.audit.TlsParameters;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocolProvider;
import org.openehealth.ipf.commons.audit.protocol.TLSSyslogSenderImpl;

public class TLSSyslogSenderProvider implements AuditTransmissionProtocolProvider {

@Override
public AuditTransmissionProtocol createAuditTransmissionProtocol(TlsParameters tlsParameters) {
return new TLSSyslogSenderImpl(tlsParameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.audit.protocol.providers;

import org.openehealth.ipf.commons.audit.TlsParameters;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocolProvider;
import org.openehealth.ipf.commons.audit.protocol.UDPSyslogSenderImpl;

public class UDPSyslogSenderProvider implements AuditTransmissionProtocolProvider {

@Override
public AuditTransmissionProtocol createAuditTransmissionProtocol(TlsParameters tlsParameters) {
return new UDPSyslogSenderImpl(tlsParameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.audit.protocol.providers;

import org.openehealth.ipf.commons.audit.TlsParameters;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocolProvider;
import org.openehealth.ipf.commons.audit.protocol.VertxTLSSyslogSenderImpl;

@Deprecated
public class VertxTLSSyslogSenderProvider implements AuditTransmissionProtocolProvider {

@Override
public AuditTransmissionProtocol createAuditTransmissionProtocol(TlsParameters tlsParameters) {
return new VertxTLSSyslogSenderImpl(tlsParameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.openehealth.ipf.commons.audit.protocol.providers;

import org.openehealth.ipf.commons.audit.TlsParameters;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocol;
import org.openehealth.ipf.commons.audit.protocol.AuditTransmissionProtocolProvider;
import org.openehealth.ipf.commons.audit.protocol.VertxUDPSyslogSenderImpl;

@Deprecated
public class VertxUDPSyslogSenderProvider implements AuditTransmissionProtocolProvider {

@Override
public AuditTransmissionProtocol createAuditTransmissionProtocol(TlsParameters tlsParameters) {
return new VertxUDPSyslogSenderImpl(tlsParameters);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
org.openehealth.ipf.commons.audit.protocol.providers.TLSSyslogSenderProvider
org.openehealth.ipf.commons.audit.protocol.providers.UDPSyslogSenderProvider
org.openehealth.ipf.commons.audit.protocol.providers.NettyTLSSyslogSenderProvider
org.openehealth.ipf.commons.audit.protocol.providers.ReactorNettyTLSSyslogSenderProvider
org.openehealth.ipf.commons.audit.protocol.providers.RecordingAuditMessageTransmissionProvider
org.openehealth.ipf.commons.audit.protocol.providers.VertxTLSSyslogSenderProvider
org.openehealth.ipf.commons.audit.protocol.providers.VertxUDPSyslogSenderProvider
Loading

0 comments on commit 3782e72

Please sign in to comment.