Skip to content

Commit

Permalink
Merge branch 'feature/ipf5prep'
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Ohr committed Dec 20, 2024
2 parents 36e069a + ab6e8d7 commit d364d4e
Show file tree
Hide file tree
Showing 2,907 changed files with 22,123 additions and 105,374 deletions.
12 changes: 5 additions & 7 deletions boot/ipf-atna-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,18 @@
<artifactId>spring-security-web</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<optional>true</optional>
</dependency>

<!-- dependencies for test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-test</artifactId>
<scope>test</scope>
</dependency>
<!--
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.openehealth.ipf.boot.atna;

import lombok.NonNull;
import org.openehealth.ipf.commons.audit.AuditContext;
import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
import org.openehealth.ipf.commons.audit.event.ApplicationActivityBuilder;
Expand All @@ -27,9 +28,6 @@

import static java.util.Objects.requireNonNull;

/**
*
*/
public class ApplicationStartEventListener implements ApplicationListener<ContextRefreshedEvent> {

private final AuditContext auditContext;
Expand All @@ -42,7 +40,7 @@ public ApplicationStartEventListener(AuditContext auditContext) {
}

@Override
public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
public void onApplicationEvent(@NonNull ContextRefreshedEvent contextRefreshedEvent) {
if (contextRefreshedEvent.getApplicationContext() == applicationContext) {
auditContext.audit(
new ApplicationActivityBuilder.ApplicationStart(EventOutcomeIndicator.Success)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.openehealth.ipf.boot.atna;

import lombok.NonNull;
import org.openehealth.ipf.commons.audit.AuditContext;
import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
import org.openehealth.ipf.commons.audit.event.ApplicationActivityBuilder;
Expand All @@ -27,9 +28,6 @@

import static java.util.Objects.requireNonNull;

/**
*
*/
public class ApplicationStopEventListener implements ApplicationListener<ContextClosedEvent> {

private final AuditContext auditContext;
Expand All @@ -42,7 +40,7 @@ public ApplicationStopEventListener(AuditContext auditContext) {
}

@Override
public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
public void onApplicationEvent(@NonNull ContextClosedEvent contextClosedEvent) {
if (contextClosedEvent.getApplicationContext() == applicationContext) {
auditContext.audit(
new ApplicationActivityBuilder.ApplicationStop(EventOutcomeIndicator.Success)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2018 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.boot.atna;

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

/**
* Customizer that can be used to manipulate auto-configured {@link AuditContext} beans
*
* @author Christian Ohr
*/
public interface AuditContextCustomizer {

void customizeAuditContext(AuditContext auditContext);

AuditContextCustomizer NOOP = auditContext -> {
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.openehealth.ipf.boot.atna;

import lombok.NonNull;
import org.openehealth.ipf.commons.audit.AuditContext;
import org.openehealth.ipf.commons.audit.codes.EventOutcomeIndicator;
import org.openehealth.ipf.commons.audit.event.UserAuthenticationBuilder;
Expand All @@ -42,19 +43,17 @@ public AuthenticationListener(AuditContext auditContext) {
}

@Override
public void onApplicationEvent(AbstractAuthenticationEvent authenticationEvent) {
public void onApplicationEvent(@NonNull AbstractAuthenticationEvent authenticationEvent) {
delegateListener.onApplicationEvent(authenticationEvent);

var outcome = authenticationEvent instanceof AbstractAuthenticationFailureEvent ?
EventOutcomeIndicator.MajorFailure :
EventOutcomeIndicator.Success;

var details = authenticationEvent.getAuthentication().getDetails();
if (details instanceof WebAuthenticationDetails) {
var webAuthenticationDetails = (WebAuthenticationDetails) details;
if (details instanceof WebAuthenticationDetails webAuthenticationDetails) {
var principal = authenticationEvent.getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
var userDetails = (UserDetails) principal;
if (principal instanceof UserDetails userDetails) {

var builder = new UserAuthenticationBuilder.Login(outcome)
.setAuditSource(auditContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@

import static org.apache.commons.lang3.StringUtils.isNotBlank;

/**
*
*/
@Configuration
@EnableConfigurationProperties(IpfAtnaConfigurationProperties.class)
public class IpfAtnaAutoConfiguration {

@Bean
@ConditionalOnMissingBean
public AuditContext auditContext(IpfAtnaConfigurationProperties config,
AuditContextCustomizer auditContextCustomizer,
AuditTransmissionProtocol auditTransmissionProtocol,
AuditMessageQueue auditMessageQueue,
TlsParameters tlsParameters,
Expand All @@ -54,29 +52,38 @@ public AuditContext auditContext(IpfAtnaConfigurationProperties config,
WsAuditDatasetEnricher wsAuditDatasetEnricher,
FhirAuditDatasetEnricher fhirAuditDatasetEnricher,
@Value("${spring.application.name}") String appName) {
DefaultAuditContext auditContext;
if (config.getBalp() != null) {
return balpConfiguration(defaultContextConfiguration(new DefaultBalpAuditContext(), config,
auditTransmissionProtocol, auditMessageQueue, tlsParameters, auditMetadataProvider,
auditExceptionHandler, auditMessagePostProcessor, wsAuditDatasetEnricher,
fhirAuditDatasetEnricher, appName), config);
auditContext = new DefaultBalpAuditContext();
configureBalpAuditContext((DefaultBalpAuditContext) auditContext, config);
} else {
return defaultContextConfiguration(new DefaultAuditContext(), config, auditTransmissionProtocol,
auditMessageQueue, tlsParameters, auditMetadataProvider, auditExceptionHandler,
auditMessagePostProcessor, wsAuditDatasetEnricher, fhirAuditDatasetEnricher, appName);
auditContext = new DefaultAuditContext();
}
configureDefaultAuditContext(auditContext, config, auditTransmissionProtocol,
auditMessageQueue, tlsParameters, auditMetadataProvider, auditExceptionHandler,
auditMessagePostProcessor, wsAuditDatasetEnricher, fhirAuditDatasetEnricher, appName);
auditContextCustomizer.customizeAuditContext(auditContext);
return auditContext;
}

private <T extends DefaultAuditContext> T defaultContextConfiguration(T auditContext,
IpfAtnaConfigurationProperties config,
AuditTransmissionProtocol auditTransmissionProtocol,
AuditMessageQueue auditMessageQueue,
TlsParameters tlsParameters,
AuditMetadataProvider auditMetadataProvider,
AuditExceptionHandler auditExceptionHandler,
AuditMessagePostProcessor auditMessagePostProcessor,
WsAuditDatasetEnricher wsAuditDatasetEnricher,
FhirAuditDatasetEnricher fhirAuditDatasetEnricher,
@Value("${spring.application.name}") String appName) {
@Bean
@ConditionalOnMissingBean(AuditContextCustomizer.class)
public AuditContextCustomizer auditContextCustomizer() {
return AuditContextCustomizer.NOOP;
}


private void configureDefaultAuditContext(DefaultAuditContext auditContext,
IpfAtnaConfigurationProperties config,
AuditTransmissionProtocol auditTransmissionProtocol,
AuditMessageQueue auditMessageQueue,
TlsParameters tlsParameters,
AuditMetadataProvider auditMetadataProvider,
AuditExceptionHandler auditExceptionHandler,
AuditMessagePostProcessor auditMessagePostProcessor,
WsAuditDatasetEnricher wsAuditDatasetEnricher,
FhirAuditDatasetEnricher fhirAuditDatasetEnricher,
@Value("${spring.application.name}") String appName) {

auditContext.setAuditEnabled(config.isAuditEnabled());

Expand All @@ -103,65 +110,63 @@ private <T extends DefaultAuditContext> T defaultContextConfiguration(T auditCon
if (fhirAuditDatasetEnricher != FhirAuditDatasetEnricher.NONE) {
auditContext.setFhirAuditDatasetEnricher(fhirAuditDatasetEnricher);
}

return auditContext;
}

private DefaultBalpAuditContext balpConfiguration(DefaultBalpAuditContext auditContext, IpfAtnaConfigurationProperties config) {
if (config.getBalp() != null) {
auditContext.setAuditRepositoryContextPath(config.getBalp().getAuditRepositoryContextPath());
private void configureBalpAuditContext(DefaultBalpAuditContext auditContext, IpfAtnaConfigurationProperties config) {
auditContext.setAuditRepositoryContextPath(config.getBalp().getAuditRepositoryContextPath());

if (isNotBlank(config.getBalp().getAuditEventSerializationType())) {
auditContext.setSerializationStrategy(
config.getBalp().getAuditEventSerializationType().equalsIgnoreCase("json") ?
new BalpJsonSerializationStrategy() : new BalpXmlSerializationStrategy());
if (isNotBlank(config.getBalp().getAuditEventSerializationType())) {
auditContext.setSerializationStrategy(
config.getBalp().getAuditEventSerializationType().equalsIgnoreCase("json") ?
new BalpJsonSerializationStrategy() : new BalpXmlSerializationStrategy());
}
var oAuth = config.getBalp().getOauth();
var props = auditContext.getBalpJwtExtractorProperties();

if (oAuth != null) {
if (oAuth.getIdPath() != null) {
props.setIdPath(oAuth.getIdPath());
}
if (oAuth.getClientIdPath() != null) {
props.setClientIdPath(oAuth.getClientIdPath());
}
if (config.getBalp().getOauth() != null) {
if (config.getBalp().getOauth().getIdPath() != null) {
auditContext.getBalpJwtExtractorProperties().setIdPath(config.getBalp().getOauth().getIdPath());
}
if (config.getBalp().getOauth().getClientIdPath() != null) {
auditContext.getBalpJwtExtractorProperties().setClientIdPath(config.getBalp().getOauth().getClientIdPath());
}
if (config.getBalp().getOauth().getIssuerPath() != null) {
auditContext.getBalpJwtExtractorProperties().setIssuerPath(config.getBalp().getOauth().getIssuerPath());
}
if (config.getBalp().getOauth().getSubjectPath() != null) {
auditContext.getBalpJwtExtractorProperties().setSubjectPath(config.getBalp().getOauth().getSubjectPath());
}
if (config.getBalp().getOauth().getSubjectNamePath() != null) {
auditContext.getBalpJwtExtractorProperties().setSubjectNamePath(config.getBalp().getOauth().getSubjectNamePath());
}
if (config.getBalp().getOauth().getSubjectRolePath() != null) {
auditContext.getBalpJwtExtractorProperties().setSubjectRolePath(config.getBalp().getOauth().getSubjectRolePath());
}
if (config.getBalp().getOauth().getSubjectOrganizationIdPath() != null) {
auditContext.getBalpJwtExtractorProperties().setSubjectOrganizationIdPath(config.getBalp().getOauth().getSubjectOrganizationIdPath());
}
if (config.getBalp().getOauth().getPurposeOfUsePath() != null) {
auditContext.getBalpJwtExtractorProperties().setPurposeOfUsePath(config.getBalp().getOauth().getPurposeOfUsePath());
}
if (config.getBalp().getOauth().getHomeCommunityIdPath() != null) {
auditContext.getBalpJwtExtractorProperties().setHomeCommunityIdPath(config.getBalp().getOauth().getHomeCommunityIdPath());
}
if (config.getBalp().getOauth().getNationalProviderIdPath() != null) {
auditContext.getBalpJwtExtractorProperties().setNationalProviderIdPath(config.getBalp().getOauth().getNationalProviderIdPath());
}
if (config.getBalp().getOauth().getDocIdPath() != null) {
auditContext.getBalpJwtExtractorProperties().setDocIdPath(config.getBalp().getOauth().getDocIdPath());
}
if (config.getBalp().getOauth().getPatientIdPath() != null) {
auditContext.getBalpJwtExtractorProperties().setPatientIdPath(config.getBalp().getOauth().getPatientIdPath());
}
if (config.getBalp().getOauth().getPersonIdPath() != null) {
auditContext.getBalpJwtExtractorProperties().setPersonIdPath(config.getBalp().getOauth().getPersonIdPath());
}
if (config.getBalp().getOauth().getAcpPath() != null) {
auditContext.getBalpJwtExtractorProperties().setAcpPath(config.getBalp().getOauth().getAcpPath());
}
if (oAuth.getIssuerPath() != null) {
props.setIssuerPath(oAuth.getIssuerPath());
}
if (oAuth.getSubjectPath() != null) {
props.setSubjectPath(oAuth.getSubjectPath());
}
if (oAuth.getSubjectNamePath() != null) {
props.setSubjectNamePath(oAuth.getSubjectNamePath());
}
if (oAuth.getSubjectRolePath() != null) {
props.setSubjectRolePath(oAuth.getSubjectRolePath());
}
if (oAuth.getSubjectOrganizationIdPath() != null) {
props.setSubjectOrganizationIdPath(oAuth.getSubjectOrganizationIdPath());
}
if (oAuth.getPurposeOfUsePath() != null) {
props.setPurposeOfUsePath(oAuth.getPurposeOfUsePath());
}
if (oAuth.getHomeCommunityIdPath() != null) {
props.setHomeCommunityIdPath(oAuth.getHomeCommunityIdPath());
}
if (oAuth.getNationalProviderIdPath() != null) {
props.setNationalProviderIdPath(oAuth.getNationalProviderIdPath());
}
if (oAuth.getDocIdPath() != null) {
props.setDocIdPath(oAuth.getDocIdPath());
}
if (oAuth.getPatientIdPath() != null) {
props.setPatientIdPath(oAuth.getPatientIdPath());
}
if (oAuth.getPersonIdPath() != null) {
props.setPersonIdPath(oAuth.getPersonIdPath());
}
if (oAuth.getAcpPath() != null) {
props.setAcpPath(oAuth.getAcpPath());
}
}
return auditContext;
}

// The following beans configure aud strategies (formats, queues, exception handlers) and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
import org.openehealth.ipf.commons.audit.types.AuditSource;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
*
*/
@ConfigurationProperties(prefix = "ipf.atna")
public class IpfAtnaConfigurationProperties {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.event.AbstractAuthenticationEvent;

/**
*
*/
@ConditionalOnClass({AbstractAuthenticationEvent.class})
@Configuration
@EnableConfigurationProperties(IpfAtnaConfigurationProperties.class)
Expand Down
Loading

0 comments on commit d364d4e

Please sign in to comment.