Skip to content

Commit

Permalink
Merge pull request #80 from smartSenseSolutions/fix/local-deployment-…
Browse files Browse the repository at this point in the history
…issue-fix

Fix: local deployment issues
  • Loading branch information
carslen authored Jun 3, 2024
2 parents f93cb82 + e3a0730 commit d7ed0e8
Show file tree
Hide file tree
Showing 14 changed files with 2,726 additions and 166 deletions.
256 changes: 133 additions & 123 deletions DEPENDENCIES_BACKEND

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# *******************************************************************************
# Copyright (c) 2024 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# This program and the accompanying materials are made available under the
# terms of the Apache License, Version 2.0 which is available at
# https://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.
#
# SPDX-License-Identifier: Apache-2.0
# ********************************************************************************

services:
database:
image: 'postgres:16.2'
ports:
- '5432:5432'
environment:
- 'POSTGRES_USER=dcm'
- 'POSTGRES_DB=dcm'
- 'POSTGRES_PASSWORD=dcm'
volumes:
- mydb:/var/lib/postgresql/data
- ./dev/create_keycloak_db.sh:/docker-entrypoint-initdb.d/create_second_db.sh

keycloak:
healthcheck:
test: ["CMD", "curl", "-f", "http://0.0.0.0:8888/auth/"]
interval: 5s
timeout: 2s
retries: 15
pid: "host"
depends_on:
- database
volumes:
- keycloak-data:/opt/keycloak/data/
- ./dev/dcm_realm.json:/opt/keycloak/data/import/dcm_realm_local.json
environment:
KEYCLOAK_ADMIN: admin
KEYCLOAK_ADMIN_PASSWORD: admin
DB_VENDOR: postgres
DB_ADDR: database
DB_DATABASE: auth
DB_USER: root
DB_PASSWORD: password
image: quay.io/keycloak/keycloak:24.0.2
entrypoint: ["/opt/keycloak/bin/kc.sh", "start-dev", "--import-realm"]
ports:
- "28080:8080"

volumes:
mydb:
keycloak-data:
46 changes: 38 additions & 8 deletions demand-capacity-mgmt-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<version>3.1.5</version>
<version>3.2.5</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -83,10 +83,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down Expand Up @@ -140,6 +136,35 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-docker-compose</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-common</artifactId>
<version>2.5.0</version>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
</dependency>

<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>2.2.21</version>
</dependency>
</dependencies>

<build>
Expand All @@ -165,9 +190,9 @@
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>0.13</version>
<version>0.22</version>
<configuration>
<prettierJavaVersion>1.0.2</prettierJavaVersion>
<prettierJavaVersion>2.6.0</prettierJavaVersion>
<printWidth>120</printWidth>
<tabWidth>4</tabWidth>
<ignoreConfigFile>true</ignoreConfigFile>
Expand Down Expand Up @@ -200,7 +225,7 @@
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>application.properties</include>
<include>application.yml</include>
</includes>
<targetPath>BOOT-INF/classes/</targetPath>
</resource>
Expand All @@ -216,6 +241,11 @@
</includes>
<targetPath>META-INF</targetPath>
</resource>
<!-- add content of resources folder -->
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
public class DemandCapacityMgmtBackendApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* ******************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
* *******************************************************************************
*/

package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.appinfo;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "app.openapi")
public record InfoConfiguration(String name, String description, String version) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* ******************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
* *******************************************************************************
*/

package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.config.openapi;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.OAuthFlow;
import io.swagger.v3.oas.models.security.OAuthFlows;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import java.util.Collections;
import lombok.AllArgsConstructor;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.appinfo.InfoConfiguration;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.security.AppSecurityConfigProperties;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@AllArgsConstructor
public class OpenApiConfig {

private final AppSecurityConfigProperties properties;
private final InfoConfiguration appInfoConfiguration;

@Bean
public OpenAPI customOpenAPI() {
Info info = new Info();
info.setTitle(appInfoConfiguration.name());
info.setDescription(appInfoConfiguration.description());
info.setVersion(appInfoConfiguration.version());
OpenAPI openAPI = new OpenAPI();
if (properties.enabled()) {
openAPI = enableSecurity(openAPI);
}
return openAPI.info(info);
}

@Bean
public GroupedOpenApi openApiDefinition() {
return GroupedOpenApi.builder().group("docs").pathsToMatch("/**").displayName("Docs").build();
}

private OpenAPI enableSecurity(OpenAPI openAPI) {
Components components = new Components();

//Auth using access_token
String accessTokenAuth = "Authenticate using access_token";
components.addSecuritySchemes(
accessTokenAuth,
new SecurityScheme()
.name(accessTokenAuth)
.description("Authenticate using token")
.type(SecurityScheme.Type.HTTP)
.scheme("Bearer")
);

//Auth using Resource Owner Password Flow
String passwordFlow = "Authenticate using Resource Owner Password Flow";
components.addSecuritySchemes(
passwordFlow,
new SecurityScheme()
.name(passwordFlow)
.description(
"Authenticate using Resource Owner Password Flow. provide username and password to authenticate"
)
.type(SecurityScheme.Type.OAUTH2)
.flows(
new OAuthFlows()
.password(
new OAuthFlow().tokenUrl(properties.tokenUrl()).refreshUrl(properties.refreshTokenUrl())
)
)
);

return openAPI
.components(components)
.addSecurityItem(
new SecurityRequirement()
.addList(accessTokenAuth, Collections.emptyList())
.addList(passwordFlow, Collections.emptyList())
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* ******************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://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.
*
* SPDX-License-Identifier: Apache-2.0
* *******************************************************************************
*/

package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.security;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("app.openapi.security")
public record AppSecurityConfigProperties(Boolean enabled, String authUrl, String tokenUrl, String refreshTokenUrl) {}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
"/token/introspect"
)
.permitAll()
.requestMatchers(HttpMethod.GET, "/docs/api-docs/**", "/ui/swagger-ui/**")
.permitAll()
.anyRequest()
.authenticated()
);
Expand Down
34 changes: 28 additions & 6 deletions demand-capacity-mgmt-backend/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,23 @@
# SPDX-License-Identifier: Apache-2.0
# ********************************************************************************

app:
openapi:
name: Demand and Capacity Management
description: Demand and Capacity Management project
version: 1
security:
enabled: ${SECURITY_ENABLE:true}
auth-url: ${keycloak.baseUrl}/realms/${keycloak.realm}/protocol/openid-connect/auth
token-url: ${keycloak.baseUrl}/realms/${keycloak.realm}/protocol/openid-connect/token
refresh-token-url: ${KEYCLOAK_TOKEN_URL}

spring:
security:
oauth2:
resource-server:
jwt:
issuer-uri: http://localhost:8888/realms/dcm
issuer-uri: ${keycloak.baseUrl}/realms/${keycloak.realm}

datasource:
url: jdbc:postgresql://${DCM_DATASOURCE_HOST:localhost:5432}/${DCM_DATASOURCE_NAME:dcm}
Expand All @@ -40,13 +51,24 @@ spring:
user: ${DCM_DATASOURCE_USER:dcm}
password: ${DCM_DATASOURCE_PASS:dcm}
schemas: migrations
locations: classpath:db/migration/postgresql
locations: classpath:db/migration

keycloak:
baseUrl: http://localhost:8888
realm: dcm
clientId: dcmauth
clientSecret: ${DCMSECR}
baseUrl: ${KEYCLOAK_BASE_URL:http://localhost:28080}
realm: ${KEYCLOAK_REALM_NAME:dcm}
clientId: ${KEYCLOAK_CLIENT_ID:dcmauth}
clientSecret: ${DCMSECR:test}
grant_type_token: password
grant_type_refresh_token : refresh_token

springdoc:
swagger-ui:
oauth:
clientId: ${keycloak.clientId}
disable-swagger-default-url: true
path: /ui/swagger-ui
show-common-extensions: true
csrf:
enabled: true
api-docs:
path: /docs/api-docs
Loading

0 comments on commit d7ed0e8

Please sign in to comment.