-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4bc4a6e
commit ef46b00
Showing
16 changed files
with
652 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<!-- ~ Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch> ~ | ||
~ This Source Code Form is subject to the terms of the Mozilla Public ~ License, | ||
v. 2.0. If a copy of the MPL was not distributed with this ~ file, You can | ||
obtain one at https://mozilla.org/MPL/2.0/. ~ ~ SPDX-License-Identifier: | ||
MPL-2.0 --> | ||
|
||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.dpppt</groupId> | ||
<artifactId>dpppt-backend-sdk</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>dpppt-backend-sdk-interops</artifactId> | ||
<name>DP3T Backend SDK Interops Service</name> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<start-class>org.dpppt.backend.sdk.interops.Application</start-class> | ||
<sonar.projectKey>DP-3T_dp3t-sdk-backend</sonar.projectKey> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<!-- dp3t models --> | ||
<dependency> | ||
<groupId>org.dpppt</groupId> | ||
<artifactId>dpppt-backend-sdk-model</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.dpppt</groupId> | ||
<artifactId>dpppt-backend-sdk-data</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.micrometer</groupId> | ||
<artifactId>micrometer-registry-prometheus</artifactId> | ||
</dependency> | ||
<!-- Spring Security Core --> | ||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-core</artifactId> | ||
</dependency> | ||
|
||
<!-- Spring Security Config --> | ||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-config</artifactId> | ||
</dependency> | ||
|
||
<!-- Spring Security Web --> | ||
<dependency> | ||
<groupId>org.springframework.security</groupId> | ||
<artifactId>spring-security-web</artifactId> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-dependencies</artifactId> | ||
<type>pom</type> | ||
<version>${spring-boot-version}</version> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<build> | ||
<finalName> | ||
dpppt-backend-sdk-interops | ||
</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<mainClass>org.dpppt.backend.sdk.interops.Application</mainClass> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
.../dpppt-backend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package org.dpppt.backend.sdk.interops; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
|
||
@Configuration | ||
@ComponentScan(basePackages = {"org.dpppt.backend.sdk.interops.config"}) | ||
@EnableAutoConfiguration( | ||
exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class}) | ||
@EnableWebMvc | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class); | ||
} | ||
} |
118 changes: 118 additions & 0 deletions
118
...nd-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/config/ActuatorSecurity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package org.dpppt.backend.sdk.interops.config; | ||
|
||
import org.dpppt.backend.sdk.interops.config.configbeans.ActuatorSecurityConfig; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.actuate.health.HealthEndpoint; | ||
import org.springframework.boot.actuate.info.InfoEndpoint; | ||
import org.springframework.boot.actuate.logging.LoggersEndpoint; | ||
import org.springframework.boot.actuate.metrics.export.prometheus.PrometheusScrapeEndpoint; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.core.Ordered; | ||
import org.springframework.core.annotation.Order; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
|
||
@Configuration | ||
@Order(Ordered.HIGHEST_PRECEDENCE + 9) | ||
@Profile(value = "actuator-security") | ||
@EnableWebSecurity | ||
public class ActuatorSecurity extends WebSecurityConfigurerAdapter { | ||
|
||
private static final String PROMETHEUS_ROLE = "PROMETHEUS"; | ||
|
||
@Value("${ws.monitor.prometheus.user}") | ||
private String user; | ||
|
||
@Autowired Environment environment; | ||
// region Actuator Passwords | ||
// ---------------------------------------------------------------------------------------------------------------------------------- | ||
@Bean | ||
@Profile("cloud-dev") | ||
ActuatorSecurityConfig passwordCloudDev() { | ||
return new ActuatorSecurityConfig( | ||
user, environment.getProperty("vcap.services.ha_prometheus_dev.credentials.password")); | ||
} | ||
|
||
@Bean | ||
@Profile("cloud-test") | ||
ActuatorSecurityConfig passwordCloudTest() { | ||
return new ActuatorSecurityConfig( | ||
user, environment.getProperty("vcap.services.ha_prometheus_test.credentials.password")); | ||
} | ||
|
||
@Bean | ||
@Profile("cloud-abn") | ||
ActuatorSecurityConfig passwordCloudAbn() { | ||
return new ActuatorSecurityConfig( | ||
user, environment.getProperty("vcap.services.ha_prometheus_abn.credentials.password")); | ||
} | ||
|
||
@Bean | ||
@Profile("cloud-prod") | ||
ActuatorSecurityConfig passwordProdAbn() { | ||
return new ActuatorSecurityConfig( | ||
user, environment.getProperty("vcap.services.ha_prometheus_prod.credentials.password")); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
ActuatorSecurityConfig passwordDefault() { | ||
return new ActuatorSecurityConfig( | ||
user, environment.getProperty("ws.monitor.prometheus.password")); | ||
} | ||
// ---------------------------------------------------------------------------------------------------------------------------------- | ||
// endregion | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.requestMatcher( | ||
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest | ||
.toAnyEndpoint()) | ||
.authorizeRequests() | ||
.requestMatchers( | ||
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.to( | ||
HealthEndpoint.class)) | ||
.permitAll() | ||
.requestMatchers( | ||
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.to( | ||
InfoEndpoint.class)) | ||
.permitAll() | ||
.requestMatchers( | ||
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.to( | ||
LoggersEndpoint.class)) | ||
.hasRole(PROMETHEUS_ROLE) | ||
.requestMatchers( | ||
org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest.to( | ||
PrometheusScrapeEndpoint.class)) | ||
.hasRole(PROMETHEUS_ROLE) | ||
.anyRequest() | ||
.denyAll() | ||
.and() | ||
.httpBasic(); | ||
|
||
http.csrf().ignoringAntMatchers("/actuator/loggers/**"); | ||
} | ||
|
||
@Autowired | ||
protected void configureGlobal( | ||
AuthenticationManagerBuilder auth, ActuatorSecurityConfig securityConfig) throws Exception { | ||
auth.inMemoryAuthentication() | ||
.withUser(securityConfig.getUsername()) | ||
.password(passwordEncoder().encode(securityConfig.getPassword())) | ||
.roles(PROMETHEUS_ROLE); | ||
} | ||
|
||
@Bean | ||
public PasswordEncoder passwordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...ackend-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/config/WSBaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package org.dpppt.backend.sdk.interops.config; | ||
|
||
import javax.sql.DataSource; | ||
import org.flywaydb.core.Flyway; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
import org.springframework.scheduling.annotation.SchedulingConfigurer; | ||
import org.springframework.scheduling.config.ScheduledTaskRegistrar; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@EnableScheduling | ||
public abstract class WSBaseConfig implements SchedulingConfigurer, WebMvcConfigurer { | ||
|
||
protected final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
public abstract DataSource dataSource(); | ||
|
||
public abstract Flyway flyway(); | ||
|
||
public abstract String getDbType(); | ||
|
||
@Override | ||
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {} | ||
} |
18 changes: 18 additions & 0 deletions
18
...nd-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/config/WSCloudAbnConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package org.dpppt.backend.sdk.interops.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
@Configuration | ||
@Profile("cloud-abn") | ||
public class WSCloudAbnConfig extends WSCloudBaseConfig {} |
46 changes: 46 additions & 0 deletions
46
...d-sdk-interops/src/main/java/org/dpppt/backend/sdk/interops/config/WSCloudBaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2020 Ubique Innovation AG <https://www.ubique.ch> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package org.dpppt.backend.sdk.interops.config; | ||
|
||
import javax.sql.DataSource; | ||
import org.flywaydb.core.Flyway; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Lazy; | ||
|
||
@Configuration | ||
public abstract class WSCloudBaseConfig extends WSBaseConfig { | ||
|
||
@Autowired @Lazy private DataSource dataSource; | ||
|
||
@Override | ||
public DataSource dataSource() { | ||
return dataSource; | ||
} | ||
|
||
@Bean | ||
@Override | ||
public Flyway flyway() { | ||
Flyway flyWay = | ||
Flyway.configure() | ||
.dataSource(dataSource()) | ||
.locations("classpath:/db/migration/pgsql_cluster") | ||
.load(); | ||
flyWay.migrate(); | ||
return flyWay; | ||
} | ||
|
||
@Override | ||
public String getDbType() { | ||
return "pgsql"; | ||
} | ||
} |
Oops, something went wrong.